Bitbucket pipeline npm docker build fails exit code: 137
Asked by Iwan van Staveren:

When I run the build \<redacted\> it fails with

Memory usage in bytes:  
15794
138018816  
15795
#10 1691.2 Killed  
15796
#10 ERROR: process "/bin/sh -c npm install && BUILD_NUMBER=\"${BUILD_NUMBER}\" npm --report-on-fatalerror --report-on-signal --max-old-space-size=2048 run build-prod" did not complete successfully: exit code: 137  
15797
------  
15798
> [build-nodejs 4/4] RUN npm install && BUILD_NUMBER="267" npm --report-on-fatalerror --report-on-signal --max-old-space-size=2048 run build-prod:  
15799
------  
15800
process "/bin/sh -c npm install && BUILD_NUMBER=\"${BUILD_NUMBER}\" npm --report-on-fatalerror --report-on-signal --max-old-space-size=2048 run build-prod" did not complete successfully: exit code: 137  
15801
task: Failed to run task "build": exit status 1

I have the memory use logs on. That doesn't seem to kill it. It is getting lower and still fine.  
Memory usage in bytes:  
15692
138735616  
15693
Wed Mar 6 08:50:25 UTC 2024  
15694
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND  
15695
root 1 0.0 0.0 2892 972 ? Ss 08:21 0:00 /bin/sh -c exit $( (/usr/bin/mkfifo /opt/atlassian/pipelines/agent/tmp/build_result && /bin/cat /opt/atlassian/pipelines/agent/tmp/build_result) || /bin/echo 1)  
15696
root 7 0.0 0.0 2892 108 ? S 08:21 0:00 /bin/sh -c exit $( (/usr/bin/mkfifo /opt/atlassian/pipelines/agent/tmp/build_result && /bin/cat /opt/atlassian/pipelines/agent/tmp/build_result) || /bin/echo 1)  
15697
root 8 0.0 0.0 3216 1016 ? S 08:21 0:00 /bin/cat /opt/atlassian/pipelines/agent/tmp/build_result  
15698
root 10 0.0 0.0 2892 976 ? Ss 08:21 0:00 /bin/sh /opt/atlassian/pipelines/agent/tmp/wrapperScript3458278447178824736.sh  
15699
root 39 0.0 0.0 2892 952 ? S 08:21 0:00 /bin/sh /opt/atlassian/pipelines/agent/tmp/buildScript11719303506556174579.sh  
15700
root 40 0.0 0.0 8872 7552 ? S 08:21 0:00 /bin/bash -i /opt/atlassian/pipelines/agent/tmp/bashScript17359917558946570271.sh  
15701
root 177 0.0 0.0 8872 5976 ? S 08:21 0:00 /bin/bash -i /opt/atlassian/pipelines/agent/tmp/bashScript17359917558946570271.sh  
15702
root 178 0.0 0.0 8872 5976 ? S 08:21 0:00 /bin/bash -i /opt/atlassian/pipelines/agent/tmp/bashScript17359917558946570271.sh  
15703
root 181 0.0 0.0 1233440 8940 ? Sl 08:21 0:00 task build -- GEN-114_backpack_storage-2024.03.06.0267  
15704
root 190 0.3 0.1 755392 37000 ? Sl 08:21 0:06 docker build --pull -t <redacted> --build-arg BACKPACK_USER=$BACKPACK_USER --build-arg BACKPACK_PASSWORD=$BACKPACK_PASSWORD --build-arg ENV=prod --build-arg BUILD_NUMBER=267 .  
15705
root 4458 0.0 0.0 3212 988 ? S 08:50 0:00 sleep 2  
15706
root 4460 0.0 0.0 7484 3372 ? R 08:50 0:00 ps aux

<br />

So my guess is something related to docker daemon. But how do I check that?  

Works fine on my local system.


Answers:
author: Patrik S
body: Hello [@Iwan van Staveren](/t5/user/viewprofilepage/user-id/5445928) and welcome to the Community!

The exit code 137 returned by npm command usually indicates a memory allocation issue, where npm is exceeding the current available memory in the environment.

Looking at the logs you shared with us, it seems like you are executing the npm command as part of a docker build (the npm command is inside a Dockerfile). Could you confirm if that is the case?

If yes, then I would suggest increasing the memory allocated to the docker service and verifying if it solves the issue. By default, the docker service in pipelines is allocated with 1GB of memory, out of the 4GB available for the step (8GB for [size:2x steps](https://support.atlassian.com/bitbucket-cloud/docs/step-options/#Size))

You can increase the memory allocated for docker service up to 3GB for normal steps, and 7GB for [size: 2x steps](https://support.atlassian.com/bitbucket-cloud/docs/step-options/#Size).

For that, you'd need to add a definition to your bitbucket-pipelines.yml file configuring the amount of memory you want. Following is an example of configuring the docker service to use 2GB of memory :

```
definitions:
  services:
   docker:
    memory: 2048 # increase the memory for docker service from 1GB to 2GB
```

You can start testing with 2GB, and then tweak that value according to the amount of memory used by your build and the commands you are executing in your pipeline.

For more details on how memory allocation works in pipelines, the following article may also be of help :

* [Databases and services containers](https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/)

Hope that helps! Should you have any questions, feel free to ask.

Thank you, [@Iwan van Staveren](/t5/user/viewprofilepage/user-id/5445928) !

Patrik S


Tags: bitbucket-cloud

cloud