Agent not finding rimraf
Asked by Alvaro Valderrama:

Hi,

I have a deployment pipeline which has been working find for the past couple of years. Yesterday It did deploy successfully. Today 10 feb 2021 an error started occurring when trying to deploy:

> upmcontainer@1.0.0 clean:dist /opt/atlassian/pipelines/agent/build> rimraf distsh: 1: rimraf: not foundnpm ERR! file shnpm ERR! code ELIFECYCLEnpm ERR! errno ENOENT

My initial guess is that the bitbucket agent might have changed ?

I have removed rimraf and sorted out my problem, but I'm curios to understand the cause of the problem.

Any theories or ideas are welcome.

Many thanks,


Answers:
author: ktomk
body: Hey [@Alvaro Valderrama](/t5/user/viewprofilepage/user-id/1251011) ,

you didn't share in your question whether or not the checksum of the pipeline container image has changed. I would first of all suspect that it changed and this caused the configuration change.

From first sight I wouldn't assume it's the Bitbucket Agent. However I remember being wrong once with this and that was this issue: <https://jira.atlassian.com/browse/BCLOUD-16846>

There it was not the Bitbucket Agent but AWS (where Bitbucket likely runs) and then an Alpine Linux based image (due to use of libmusl underneath).

Despite that I'd say as this is an npm module it is likely not the bitbucket agent that has changed -or- a change of the agent would not cause this error at all:

```
rimraf dist
sh: 1: rimraf: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
```

this is reportedly an issue not having the \`rimraf\` utility available which is confirmed by the first error message: \`sh: 1: rimraf: not found\` which means that the shell (sh) can not find the binary/command \`rimraf\`.

You can easily reproduce this by executing the command as well (with any command that is n/a). Example:

```
$ sh -c 'rimraf' 
sh: 1: rimraf: not found
```

In context of your pipeline it is just that there npm shell-executes that command \`rimraf dist\` and then fails for the said reason that \`rimraf\` is not found.

The rest is \`npm\` offering more error information in/from the npm execution context.

Technically this is an issue with the script that npm is executing as it does not verify all its requirements before it is doing the work.

There might have been a time where \`rimraf\` was available globally installed (in $PATH so that the shell is able to find it) and that time is over or within some configuration not in $PATH any longer.

As long as this is an npm managed project your can add rimraf to the projects package.json scripts section and this may already solve the issue:

    "scripts": {    ...    "rimraf": "./node_modules/rimraf/bin.js",}

Ref: [https://stackoverflow.com/a/57816466](https://stackoverflow.com/a/57816466/367456)

Likely you have not done any changes to your package.json and it did fail while it didn't earlier.

What could have changed - independent to the bitbucket agent - is the pipeline image in use.

If you don't use container image hashes but tags, they can change anytime. And with that the build can change anytime, and these changes include failures like in your question.

What helps is to pin the build container image revision so that you know in advance with what you build and then have a defined process to test and accept the images used for the build.


Tags: bitbucket-cloud

bitbucket-pipelines