Getting a simple pipeline to run on the Bitbucket runner is quite straightforward. All you need to do is follow the instructions mentioned in the Bitbucket Runner Documentation.
However, my repo had some unique configurations which made me face some challenges.
Summarized below are the challenges along with the solution/workarounds.
I had to make a small change in order to get the container run in the background, by using the -d flag
docker container run -it
changed to
docker container run -d
docker container run -d -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/containers:/var/lib/docker/containers:ro -e ACCOUNT_UUID=<> -e REPOSITORY_UUID=<> -e RUNNER_UUID={4ad29803-a07a-5ad7-8908-78da5fcaa943} -e RUNTIME_PREREQUISITES_ENABLED=true -e OAUTH_CLIENT_ID=<> -e OAUTH_CLIENT_SECRET=<> -e WORKING_DIRECTORY=/tmp --name runner-4ad29803-a07a-5ad7-8908-78da5fcaa943 docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner:1
The first issue faced with my pipeline was a 401 error, as I was using private modules in my package.json file ( React App) Ref - https://community.atlassian.com/t5/Bitbucket-questions/npm-install-not-working-with-Bitbucket-runner/qaq-p/1874539
Solution
If you are using private modules from either the public npm registry or your own private registry you can simply check in a .npmrc file at the root of your repository using repository variables. To avoid conflict with the local ~/.npmrc file during development you can simply name it .npmrc_config and rename it as part of the pipeline script.
.npmrc_config
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
registry=https://registry.npmjs.org
& in the Pipeline
pipelines:
default:
- step:
script:
- mv .npmrc_config .npmrc
- npm install
Ref - https://support.atlassian.com/bitbucket-cloud/docs/javascript-nodejs-with-bitbucket-pipelines/
The node version in the default runner image is not up to date leading to npm install taking too much time..and eventually failing.
Solution
This problem can be solved by updating the node image version in the pipeline YML script.
# Pipeline
image: node:10.15.3
pipelines:
branches:
develop:
I had to get the artefacts getting generated to be passed to my subsequent steps ( SCP & SSH). However, it used to fail in my SCP step
It took me some time to figure out the artefacts that need to have paths relative to the source repo. Adding the correct path fixed the issue..
Solution
artifacts:
- frontend/build/**
Finally, I now have the build working after 28 trials on my custom runner. Hope you find this useful to get the Runner configured & working with far shorter trials 😋