Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Pipeline error: "sh: 1: ng: Permission denied" (Angular Project)


I have built a pipeline using Bitbucket. The pipeline worked fine without running tests, but the moment I put the tests back into the yml file I get this error from BB:

+ npm run test
> deezer-plus@0.0.0 test /opt/atlassian/pipelines/agent/build
> ng test --watch=false --browsers=ChromeHeadless

sh: 1: ng: Permission denied
npm ERR! errno 126
npm ERR! deezer-plus@0.0.0 test: `ng test --watch=false --browsers=ChromeHeadless`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the deezer-plus@0.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-08-18T11_59_56_793Z-debug.log

Below is my entire yml file:


image: node:14

- step:
name: "Install and test"
deployment: production
- node
- npm -g config set user root
- npm install
- apt update
- npm run install-test-dependancies
- npm run test
- step:
deployment: development
name: "Build"
- node
- npm run build
- dist/**

- step:
name: "Deploy to Firebase"
- pipe: atlassian/firebase-deploy:0.2.1

The scripts in my **package.json** file look like this:

"scripts": {
"ng": "ng",
"start": "ng serve",
"watch": "ng build --watch --configuration development",
"lint": "ng lint",
"e2e": "ng e2e",
"test": "ng test --watch=false --browsers=ChromeHeadless",
"install-test-dependancies": "apt install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget",
"test-with-head": "ng test",
"build": "ng build",
"deploy": "firebase deploy --token $FIREBASE_TOKEN --non-interactive"

This is an extract of my **karma.conf.js** file:
browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
// Without a remote debugging port, Google Chrome exits immediately.
debug: true,
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
And finally for completeness sake my **/root/.npm/_logs/**

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'test' ]
2 info using npm@6.14.14
3 info using node@v14.17.5
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle deezer-plus@0.0.0~pretest: deezer-plus@0.0.0
6 info lifecycle deezer-plus@0.0.0~test: deezer-plus@0.0.0
7 verbose lifecycle deezer-plus@0.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle deezer-plus@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/opt/atlassian/pipelines/agent/build/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle deezer-plus@0.0.0~test: CWD: /opt/atlassian/pipelines/agent/build
10 silly lifecycle deezer-plus@0.0.0~test: Args: [ '-c', 'ng test --watch=false --browsers=ChromeHeadless' ]
11 silly lifecycle deezer-plus@0.0.0~test: Returned: code: 126 signal: null
12 info lifecycle deezer-plus@0.0.0~test: Failed to exec test script
13 verbose stack Error: deezer-plus@0.0.0 test: `ng test --watch=false --browsers=ChromeHeadless`
13 verbose stack Exit status 126
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:400:28)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:400:28)
13 verbose stack at maybeClose (internal/child_process.js:1055:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid deezer-plus@0.0.0
15 verbose cwd /opt/atlassian/pipelines/agent/build
16 verbose Linux 5.4.92-flatcar
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
18 verbose node v14.17.5
19 verbose npm v6.14.14
20 error code ELIFECYCLE
21 error errno 126
22 error deezer-plus@0.0.0 test: `ng test --watch=false --browsers=ChromeHeadless`
22 error Exit status 126
23 error Failed at the deezer-plus@0.0.0 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 126, true ]

Any ideas why I am getting this error and possible fixes - any help would be appreciated, Thank you

1 answer

0 votes
Mark C Atlassian Team Sep 01, 2021

Hi @Ruben Ferreira

Welcome to the community.

Based on the error message, it seems the build is erroring with a permission denied issue.

sh: 1: ng: Permission denied

For this, would it be possible for you to add the chown command below before your test command to make sure you have permission to the /build folder?

chown -R root:root $BITBUCKET_CLONE_DIR

Apart from that, I'd also recommend testing your Pipelines build locally in a Docker container.
Ideally, if it works locally in a Docker container, it should also work on Pipelines.

Let me know how it goes.

Mark C

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

1,495 views 4 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you