Bash: ./stackbit-build.sh: Permission denied

Hi guys,

I am using Stackbit to have in-page editing to my gatsby site deployed to Netlify.
Everything was working fine till yesterday and now I am getting this Permission denied error on build.
Stackbit and Sanity environment variables are configured properly on Netflify.

Anyone has seen this issue?

9:56:09 AM: Build ready to start
9:56:11 AM: build-image version: ca811f47d4c1cbd1812d1eb6ecb0c977e86d1a1d
9:56:11 AM: build-image tag: v3.3.20
9:56:11 AM: buildbot version: be8ecf2af866e16fa4301cc5c14de2ccbbb21cf4
9:56:11 AM: Fetching cached dependencies
9:56:11 AM: Starting to download cache of 152.3MB
9:56:12 AM: Finished downloading cache in 982.135565ms
9:56:12 AM: Starting to extract cache
9:56:19 AM: Finished extracting cache in 6.722927398s
9:56:19 AM: Finished fetching cache in 7.755744527s
9:56:19 AM: Starting to prepare the repo for build
9:56:19 AM: Preparing Git Reference refs/heads/master
9:56:21 AM: Starting build script
9:56:21 AM: Installing dependencies
9:56:21 AM: Python version set to 2.7
9:56:21 AM: Started restoring cached node version
9:56:24 AM: Finished restoring cached node version
9:56:24 AM: v12.18.0 is already installed.
9:56:25 AM: Now using node v12.18.0 (npm v6.14.4)
9:56:25 AM: Started restoring cached build plugins
9:56:25 AM: Finished restoring cached build plugins
9:56:25 AM: Attempting ruby version 2.7.1, read from environment
9:56:26 AM: Using ruby version 2.7.1
9:56:26 AM: Using PHP version 5.6
9:56:26 AM: 5.2 is already installed.
9:56:26 AM: Using Swift version 5.2
9:56:26 AM: Started restoring cached node modules
9:56:26 AM: Finished restoring cached node modules
9:56:26 AM: Started restoring cached yarn cache
9:56:26 AM: Finished restoring cached yarn cache
9:56:27 AM: Installing NPM modules using Yarn version 1.22.4
9:56:27 AM: yarn install v1.22.4
9:56:27 AM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
9:56:27 AM: [1/4] Resolving packages...
9:56:28 AM: success Already up-to-date.
9:56:28 AM: Done in 0.86s.
9:56:28 AM: NPM modules installed using Yarn
9:56:28 AM: Started restoring cached go cache
9:56:28 AM: Finished restoring cached go cache
9:56:28 AM: go version go1.14.4 linux/amd64
9:56:28 AM: go version go1.14.4 linux/amd64
9:56:28 AM: Installing missing commands
9:56:28 AM: Verify run directory
9:56:29 AM: ​
9:56:29 AM: ┌─────────────────────────────┐
9:56:29 AM: │        Netlify Build        │
9:56:29 AM: └─────────────────────────────┘
9:56:29 AM: ​
9:56:29 AM: ❯ Version
9:56:29 AM:   @netlify/build 3.0.1
9:56:29 AM: ​
9:56:29 AM: ❯ Flags
9:56:29 AM:   deployId: 5f21aa29d4912a7ebaf7abbc
9:56:29 AM:   mode: buildbot
9:56:29 AM: ​
9:56:29 AM: ❯ Current directory
9:56:29 AM:   /opt/build/repo
9:56:29 AM: ​
9:56:29 AM: ❯ Config file
9:56:29 AM:   /opt/build/repo/netlify.toml
9:56:29 AM: ​
9:56:29 AM: ❯ Context
9:56:29 AM:   production
9:56:29 AM: ​
9:56:29 AM: ┌────────────────────────────────────┐
9:56:29 AM: │ 1. build.command from netlify.toml │
9:56:29 AM: └────────────────────────────────────┘
9:56:29 AM: ​
9:56:29 AM: $ ./stackbit-build.sh
9:56:29 AM: bash: ./stackbit-build.sh: Permission denied
9:56:29 AM: ​
9:56:29 AM: ┌─────────────────────────────┐
9:56:29 AM: │   "build.command" failed    │
9:56:29 AM: └─────────────────────────────┘
9:56:29 AM: ​
9:56:29 AM:   Error message
9:56:29 AM:   Command failed with exit code 126: ./stackbit-build.sh
9:56:29 AM: ​
9:56:29 AM:   Error location
9:56:29 AM:   In build.command from netlify.toml:
9:56:29 AM:   ./stackbit-build.sh
9:56:29 AM: ​
9:56:30 AM: Failed during stage 'building site': Build script returned non-zero exit code: 1
9:56:29 AM:   Resolved config
9:56:29 AM:   build:
9:56:29 AM:     command: ./stackbit-build.sh
9:56:29 AM:     commandOrigin: config
9:56:29 AM:     environment:
9:56:29 AM:       - INCOMING_HOOK_BODY
9:56:29 AM:       - INCOMING_HOOK_TITLE
9:56:29 AM:       - INCOMING_HOOK_URL
9:56:29 AM:       - SANITY_AUTH_TOKEN
9:56:29 AM:       - STACKBIT_API_KEY
9:56:29 AM:     publish: /opt/build/repo/public
9:56:30 AM: Caching artifacts
9:56:30 AM: Started saving node modules
9:56:30 AM: Finished saving node modules
9:56:30 AM: Started saving build plugins
9:56:30 AM: Finished saving build plugins
9:56:30 AM: Started saving yarn cache
9:56:30 AM: Finished saving yarn cache
9:56:30 AM: Started saving pip cache
9:56:30 AM: Finished saving pip cache
9:56:30 AM: Started saving emacs cask dependencies
9:56:30 AM: Finished saving emacs cask dependencies
9:56:30 AM: Started saving maven dependencies
9:56:30 AM: Finished saving maven dependencies
9:56:30 AM: Started saving boot dependencies
9:56:30 AM: Finished saving boot dependencies
9:56:30 AM: Started saving go dependencies
9:56:30 AM: Finished saving go dependencies
9:56:30 AM: Error running command: Build script returned non-zero exit code: 1
9:56:30 AM: Failing build: Failed to build site
9:56:30 AM: Finished processing build request in 18.776754975s

hi there, yes, i think i have seen this before:

Did you deploy a site through stackbit, and then clone it down, and then push it again? I think this might be the problem.

humm, yes. We used their starter theme and now we are customizing it. Do you think this causes the permission error?

yes, i do. if it were me trying to troubleshoot this, I would probably leave the .sh file on the server and not try overwriting it - maybe ignore it with a gitignore?

Thanks Perry, this seems to be the solution but the problem when I check on github, the latest commited file stackbit-build.sh is identical to the original one.

Anyways I reverted back the file generated by ‘stackbit-projects’ on github but the build still failed.
Once I am able to make this work again, I will add “stackbit-build.sh” to gitignore.

I am also checking with Stackbit support, so in case there’s other fixes I can post here.
Thanks!

i think that’s a good call. I think that generally speaking, Stackbit doesn’t accommodate this workflow super well - i think the idea really is that you click together the stack, push the button, and then just use the CMS to create and edit content and don’t mess with the config past that point. But, obviously, there are people who want to do more editing and then they get stuck.

It would be great if stackbit had more information on what the best process is. Clearly an initial deploy is unproblematic, but its the following ones that seem to create these issues :thinking:

Hey man, Stackbit helped me fix the issue.

Pretty much I had to use a mac (or linux) to chmod 755 the stackbit-build.sh file, and then I didn’t have anymore the permission error.

But I started having another problem:

exit code 127 /usr/bin/env: ‘bash\r’: No such file or directory

To fix this other one I had to copy contents from the stackbit-build.sh file and save another one from scratch on a Mac using VS Code, and that pushed to my repo and it the build worked. Seems that there were some line endings compatibility issues if you edit the build file using windows and then push to Netlify environment that runs on linux.

Now that’s all fixed I added the file to gitignore.
Thanks for the help!

thanks for sharing! that’ll definitely be helpful for others!