Deploy branch without default site settings

I have a GitHub repo that’s linked to Netlify and whenever I push to master branch Netlify runs 'npm run generate'. That’s great that’s exactly what I want on that branch

On a different branch however, I just have one index.html (for the whole branch just one file) and the build fails because it’s still doing npm run generate. How can I run a different command on a per branch basis?

I’ve tried adding below to the master branch of my repo but it still doesn’t work:
image
The name of my branch is maps

Hi, @simeon9696, this is the solution I would recommend so you are on the right track. β€œThe solution” being using netlify.toml to define different build commands and/or publish directories by branch.

I’m guessing the build command isn’t being detected for some reason. I though I found the correct account but none of those sites is building a branch names β€œmaps”. Would you please send us a link to the site or let us know the site’s API id (the id not the key)?

Hi @luke the site API ID is 846fe74b-fd3b-4753-8dc1-594b1935fda9

I don’t think you’ll see a branch maps β€˜built’ as yet because the builds for it keep failing.
image

My git repo is private but I don’t think that has anything to do with it?

Hi, @simeon9696, I don’t see the logs showing that the build command is being overridden by netlify.toml. When this happens there is a log line similar to this:

12:34:56 PM: Different build command detected, going to use the one specified in the Netlify configuration file: '<command here>' versus '<other command here>' in the Netlify UI

I don’t see that happening in these logs so the issue is definitely something to do with the netlify.toml file build command not being used.

I think maybe the empty string (meaning command = "") is being treated as the build command not being defined at all.

Would you please check the following two things:

  • Does netlify.toml exist in the base of the build directory for this repository? (If not, please make sure it is moved, copied, or created there.)
  • If netlify.toml is present, would you please change the build command to command = "true" instead of command = ""?

If this still doesn’t resolve the issue, please let us know.

Hi @luke yes netlify.toml exists at the base of the build directory. I have some header rules in there as well and it says β€˜all header rules deployed successfully’ so we know it’s reading the file.

Does the branch have to have a .toml file as well or just the master?

Hi @luke so setting command = "true" worked. But now it’s trying to deploy from /dist which is where the master deploys from. I’d like to deploy from the root of the branch. So I’ve changed netlify.toml on the branch and master to say:
image

But that still gives me the below log:

10:41:28 AM: Build ready to start

10:41:31 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6

10:41:31 AM: build-image tag: v3.4.1

10:41:31 AM: buildbot version: e1f4178b0d9779ebad1b11d5b54739f82fed3c22

10:41:31 AM: Building without cache

10:41:31 AM: Starting to prepare the repo for build

10:41:31 AM: No cached dependencies found. Cloning fresh repo

10:41:31 AM: git clone https://github.com/simeon9696/covid19-tt

10:41:32 AM: Preparing Git Reference refs/heads/maps

10:41:34 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'true' versus 'npm run generate' in the Netlify UI

10:41:34 AM: Starting build script

10:41:34 AM: Installing dependencies

10:41:34 AM: Python version set to 2.7

10:41:35 AM: Downloading and installing node v12.16.1...

10:41:35 AM: Downloading https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz...

10:41:36 AM: Computing checksum with sha256sum

10:41:36 AM: Checksums matched!

10:41:39 AM: Now using node v12.16.1 (npm v6.13.4)

10:41:39 AM: Started restoring cached build plugins

10:41:39 AM: Finished restoring cached build plugins

10:41:39 AM: Attempting ruby version 2.6.2, read from environment

10:41:41 AM: Using ruby version 2.6.2

10:41:41 AM: Using PHP version 5.6

10:41:41 AM: 5.2 is already installed.

10:41:41 AM: Using Swift version 5.2

10:41:41 AM: Started restoring cached go cache

10:41:41 AM: Finished restoring cached go cache

10:41:41 AM: Installing Go version 1.12

10:41:47 AM: unset GOOS;

10:41:47 AM: unset GOARCH;

10:41:47 AM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64';

10:41:47 AM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:${PATH}";

10:41:47 AM: go version >&2;

10:41:47 AM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env"

10:41:47 AM: go version go1.12 linux/amd64

10:41:47 AM: Installing missing commands

10:41:47 AM: Verify run directory

10:41:48 AM: ​

10:41:48 AM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

10:41:48 AM: β”‚ Netlify Build β”‚

10:41:48 AM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

10:41:48 AM: ​

10:41:48 AM: ❯ Version

10:41:48 AM: @netlify/build 3.3.5

10:41:48 AM: ​

10:41:48 AM: ❯ Flags

10:41:48 AM: deployId: 5f58e9637921e5355e689bcb

10:41:48 AM: mode: buildbot

10:41:48 AM: ​

10:41:48 AM: ❯ Current directory

10:41:48 AM: /opt/build/repo

10:41:48 AM: ​

10:41:48 AM: ❯ Config file

10:41:48 AM: /opt/build/repo/netlify.toml

10:41:48 AM: ​

10:41:48 AM: ❯ Context

10:41:48 AM: branch-deploy

10:41:48 AM: ​

10:41:48 AM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

10:41:48 AM: β”‚ 1. build.command from netlify.toml β”‚

10:41:48 AM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

10:41:48 AM: ​

10:41:48 AM: $ true

10:41:48 AM: ​

10:41:48 AM: (build.command completed in 17ms)

10:41:48 AM: ​

10:41:48 AM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

10:41:48 AM: β”‚ Netlify Build Complete β”‚

10:41:48 AM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

10:41:48 AM: ​

10:41:48 AM: (Netlify Build completed in 29ms)

10:41:48 AM: Caching artifacts

10:41:48 AM: Started saving build plugins

10:41:48 AM: Finished saving build plugins

10:41:48 AM: Started saving pip cache

10:41:49 AM: Finished saving pip cache

10:41:49 AM: Started saving emacs cask dependencies

10:41:49 AM: Finished saving emacs cask dependencies

10:41:49 AM: Started saving maven dependencies

10:41:49 AM: Finished saving maven dependencies

10:41:49 AM: Started saving boot dependencies

10:41:49 AM: Finished saving boot dependencies

10:41:49 AM: Started saving go dependencies

10:41:50 AM: Finished saving go dependencies

10:41:54 AM: Failed during stage 'building site': Deploy directory 'dist' does not exist

10:41:54 AM: Build script success

10:41:54 AM: Failing build: Failed to build site

10:41:55 AM: Finished processing build request in 24.729967412s

Hi, @simeon9696, please try making the publish directory β€œ.” instead of β€œ/” like so:

  publish = "."

The build system is Linux and it will treat β€œ/” as the root of the filesystem where as β€œ.” will be handled as the current directory.

If that doesn’t work, we’ll be here! :+1:

1 Like

Hi @luke unfortunately that didn’t work. It’s still reading the publish dir as dist/. In my experiments earlier i was trying the branch name and root and it failed but it said it couldn’t find the directory maps (i.e. the branch name) or root so at least I know it’s reading in the proper netlify.toml file. I also tried clearing the cache

image

Here’s the log:
8:44:08 PM: Build ready to start

8:44:10 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6

8:44:10 PM: build-image tag: v3.4.1

8:44:10 PM: buildbot version: 8c957a6d09a03023cea4239847cc73a9cb64eeb7

8:44:11 PM: Fetching cached dependencies

8:44:11 PM: Starting to download cache of 295.1MB

8:44:12 PM: Finished downloading cache in 1.875936975s

8:44:12 PM: Starting to extract cache

8:44:24 PM: Finished extracting cache in 11.991608491s

8:44:25 PM: Finished fetching cache in 13.968931083s

8:44:25 PM: Starting to prepare the repo for build

8:44:25 PM: Preparing Git Reference refs/heads/maps

8:44:27 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'true' versus 'npm run generate' in the Netlify UI

8:44:27 PM: Starting build script

8:44:27 PM: Installing dependencies

8:44:27 PM: Python version set to 2.7

8:44:28 PM: Started restoring cached node version

8:44:31 PM: Finished restoring cached node version

8:44:32 PM: v12.16.1 is already installed.

8:44:32 PM: Now using node v12.16.1 (npm v6.13.4)

8:44:32 PM: Started restoring cached build plugins

8:44:32 PM: Finished restoring cached build plugins

8:44:32 PM: Attempting ruby version 2.6.2, read from environment

8:44:34 PM: Using ruby version 2.6.2

8:44:34 PM: Using PHP version 5.6

8:44:34 PM: 5.2 is already installed.

8:44:34 PM: Using Swift version 5.2

8:44:34 PM: Started restoring cached go cache

8:44:36 PM: Finished restoring cached go cache

8:44:36 PM: Installing Go version 1.12

8:44:36 PM: unset GOOS;

8:44:36 PM: unset GOARCH;

8:44:36 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64';

8:44:36 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:${PATH}";

8:44:36 PM: go version >&2;

8:44:36 PM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env';

8:44:36 PM: go version go1.12 linux/amd64

8:44:36 PM: Installing missing commands

8:44:36 PM: Verify run directory

8:44:37 PM: ​

8:44:37 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

8:44:37 PM: β”‚ Netlify Build β”‚

8:44:37 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8:44:37 PM: ​

8:44:37 PM: ❯ Version

8:44:37 PM: @netlify/build 3.3.5

8:44:37 PM: ​

8:44:37 PM: ❯ Flags

8:44:37 PM: deployId: 5f5976d845c0fe0007cdaf89

8:44:37 PM: mode: buildbot

8:44:37 PM: ​

8:44:37 PM: ❯ Current directory

8:44:37 PM: /opt/build/repo

8:44:37 PM: ​

8:44:37 PM: ❯ Config file

8:44:37 PM: /opt/build/repo/netlify.toml

8:44:37 PM: ​

8:44:37 PM: ❯ Context

8:44:37 PM: branch-deploy

8:44:37 PM: ​

8:44:37 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

8:44:37 PM: β”‚ 1. build.command from netlify.toml β”‚

8:44:37 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8:44:37 PM: ​

8:44:37 PM: $ true

8:44:37 PM: ​

8:44:37 PM: (build.command completed in 17ms)

8:44:37 PM: ​

8:44:37 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

8:44:37 PM: β”‚ Netlify Build Complete β”‚

8:44:37 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8:44:37 PM: ​

8:44:37 PM: (Netlify Build completed in 31ms)

8:44:38 PM: Caching artifacts

8:44:38 PM: Started saving build plugins

8:44:38 PM: Finished saving build plugins

8:44:38 PM: Started saving pip cache

8:44:38 PM: Finished saving pip cache

8:44:38 PM: Started saving emacs cask dependencies

8:44:38 PM: Finished saving emacs cask dependencies

8:44:38 PM: Started saving maven dependencies

8:44:38 PM: Finished saving maven dependencies

8:44:38 PM: Started saving boot dependencies

8:44:38 PM: Finished saving boot dependencies

8:44:38 PM: Started saving go dependencies

8:44:39 PM: Finished saving go dependencies

8:44:40 PM: Build script success

8:44:40 PM: Failing build: Failed to build site

8:44:40 PM: Failed during stage 'building site': Deploy directory 'dist' does not exist

8:44:40 PM: Finished processing build request in 29.654218138s

Hiya @simeon9696 the detail you need is right there in your logs (these logs: Netlify App, but also in your paste) :slight_smile:

8:44:40 PM: Failed during stage 'building site': Deploy directory 'dist' does not exist

You seem to have not correctly overridden the publish directory as I don’t see any log line that would look like this one:

6:00:50 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'true' versus 'npm run generate' in the Netlify UI

…about that being changed from your default of dist in the UI here:

So - does your toml also specify the publish directory? I see you and Luke talking about it above, but I don’t see the evidence of us finding it - perhaps you can share the entire file as an attachment so we can directly advise?

Hi @fool in this reply I’ve screenshotted the netlify.toml in the branch.

I tried pasting in the contents as text but it just wouldn’t format properly. And below is the full content of the branch called maps

If I change it to potato that line does show up. So since it’s reading in the parameter and the file, I don’t know how to move forward.

8:41:57 PM: Build ready to start

8:41:59 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6

8:41:59 PM: build-image tag: v3.4.1

8:41:59 PM: buildbot version: 8c957a6d09a03023cea4239847cc73a9cb64eeb7

8:41:59 PM: Fetching cached dependencies

8:42:00 PM: Starting to download cache of 295.3MB

8:42:01 PM: Finished downloading cache in 1.551706935s

8:42:01 PM: Starting to extract cache

8:42:14 PM: Finished extracting cache in 12.86063515s

8:42:14 PM: Finished fetching cache in 14.50221903s

8:42:14 PM: Starting to prepare the repo for build

8:42:14 PM: Preparing Git Reference refs/heads/maps

8:42:16 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'potato' versus 'dist' in the Netlify UI

8:42:16 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'true' versus 'npm run generate' in the Netlify UI

8:42:16 PM: Starting build script

8:42:16 PM: Installing dependencies

8:42:16 PM: Python version set to 2.7

8:42:17 PM: Started restoring cached node version

8:42:21 PM: Finished restoring cached node version

8:42:22 PM: v12.16.1 is already installed.

8:42:22 PM: Now using node v12.16.1 (npm v6.13.4)

8:42:22 PM: Started restoring cached build plugins

8:42:22 PM: Finished restoring cached build plugins

8:42:22 PM: Attempting ruby version 2.6.2, read from environment

8:42:24 PM: Using ruby version 2.6.2

8:42:24 PM: Using PHP version 5.6

8:42:24 PM: 5.2 is already installed.

8:42:24 PM: Using Swift version 5.2

8:42:24 PM: Started restoring cached go cache

8:42:26 PM: Finished restoring cached go cache

8:42:26 PM: Installing Go version 1.12

8:42:26 PM: unset GOOS;

8:42:26 PM: unset GOARCH;

8:42:29 PM: Failed during stage 'building site': Deploy directory 'potato' does not exist

8:42:26 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64';

8:42:26 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:${PATH}";

8:42:26 PM: go version >&2;

8:42:26 PM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env';

8:42:26 PM: go version go1.12 linux/amd64

8:42:26 PM: Installing missing commands

8:42:26 PM: Verify run directory

8:42:27 PM: ​

8:42:27 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

8:42:27 PM: β”‚ Netlify Build β”‚

8:42:27 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8:42:27 PM: ​

8:42:27 PM: ❯ Version

8:42:27 PM: @netlify/build 3.3.5

8:42:27 PM: ​

8:42:27 PM: ❯ Flags

8:42:27 PM: deployId: 5f600dd5d2668b0008ac72d6

8:42:27 PM: mode: buildbot

8:42:27 PM: ​

8:42:27 PM: ❯ Current directory

8:42:27 PM: /opt/build/repo

8:42:27 PM: ​

8:42:27 PM: ❯ Config file

8:42:27 PM: /opt/build/repo/netlify.toml

8:42:27 PM: ​

8:42:27 PM: ❯ Context

8:42:27 PM: branch-deploy

8:42:27 PM: ​

8:42:27 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

8:42:27 PM: β”‚ 1. build.command from netlify.toml β”‚

8:42:27 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8:42:27 PM: ​

8:42:27 PM: $ true

8:42:27 PM: ​

8:42:27 PM: (build.command completed in 14ms)

8:42:27 PM: ​

8:42:27 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

8:42:27 PM: β”‚ Netlify Build Complete β”‚

8:42:27 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8:42:27 PM: ​

8:42:27 PM: (Netlify Build completed in 26ms)

8:42:27 PM: Caching artifacts

8:42:27 PM: Started saving build plugins

8:42:27 PM: Finished saving build plugins

8:42:27 PM: Started saving pip cache

8:42:27 PM: Finished saving pip cache

8:42:27 PM: Started saving emacs cask dependencies

8:42:27 PM: Finished saving emacs cask dependencies

8:42:27 PM: Started saving maven dependencies

8:42:27 PM: Finished saving maven dependencies

8:42:27 PM: Started saving boot dependencies

8:42:27 PM: Finished saving boot dependencies

8:42:28 PM: Started saving go dependencies

8:42:29 PM: Finished saving go dependencies

8:42:29 PM: Build script success

8:42:29 PM: Failing build: Failed to build site

8:42:29 PM: Finished processing build request in 30.057571817s

Hi, @simeon9696. This behavior is a bug.

I’ve gotten an issue filed for this. The issue is this:

  • If there is a publish directory defined in either the web UI or in the build stanza of netlify.toml then there is no way to make the publish directory the same as the base directory.

If/when this issue is known to be resolved, we post an update here to let you know about it.

In the meantime, the only workaround I have found is to remove any publish directory setting in the build stanza of netlify.toml and the site settings in the web UI (Site Name > Settings > Build & deploy > Continuous Deployment).

For example:

[build]
 command="npm run build"

[context.master]
  publish = "publish"

[context.maps]
  command = "true"

This would require creating a context stanza for all branches. This isn’t ideal but it is the only workaround I can find.

If there are other questions about this, please let us know.

1 Like