Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,414
Community Members
 
Community Events
165
Community Groups

Getting my Bitbucket Pipeline to work with the Runner

Ajay _view26_ Community Leader Dec 05, 2021

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.

 

Running the Runner

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

Private modules in Bitbucket Pipelines

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

 Screenshot 2021-11-30 211610.png

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/

 

Updating Node version

The node version in the default runner image is not up to date leading to npm install taking too much time..and eventually failing.

Screenshot 2021-12-06 130502.png

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:

 

Generating Artifacts correctly

 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 

Screenshot 2021-12-06 130742.png

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 😋

Screenshot 2021-12-06 131151.png

 

0 comments

Comment

Log in or Sign up to comment
TAGS

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