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?
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, @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:
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 @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
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)
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?
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).