DEV Community

Amit Tiwary
Amit Tiwary

Posted on

Setup CI/CD pipeline in bitbucket

Nowadays we all use the cloud to deploy the frontend or backend code and Bitbucket for code hosting and collaborate with others. If we manually deploy our frontend or backend code on the cloud then it would take lots of our time and there is a chance of error. To save our time, effort and reduce the chance of error we automate this process and setup CI/CD. There are many tools to setup CI/CD process. Bitbucket also has the option to set up a pipeline to automate the deployment process. We used it to set up our CI/CD pipeline for our website, which is created using react, deployed on google app engine.

Bitbucket create bitbucket-pipelines.yml and we add code in this file to manage our CI/CD. We can add different deployment code depending on the different branch so that we can manage different build flavour like dev, prod, staging etc.

Steps to setup CI/CD pipeline:

Select the deployment option from left sidebar.

It opens an editable file bitbucket-pipelines.yml, we can edit the file there and commit or we can create that file locally, if not already created, edit it in editor and push on bitbucket.

Now comes the script part:

Indentation is essential in this script. We add different branch inside the branches block and then deployment code for that branch




There are two step in deployment for each branch build and then deploy


  • step:

script: # Modify the commands below to build your repository.

  • npm install

  • npm run build


  • build/**

It installs all the required library, runs the build step and creates the build folder. We can add different build command in our package.json for different build flavour and use in place of npm run build. Artifacts pass file from one step to others by compressing them from one step to others.

Second step


name: Deploy

deployment: production


  • pipe: atlassian/google-app-engine-deploy:0.2.1 //click on explore more pipes there is an option for google app engine, click on it and you will get the latest pipe.


KEY_FILE: 'we save the key in a variable and use the file name here'

PROJECT: "project id of the google cloud project"

This step uses to deploy code. The step to create key file added in variables are

go to your GCP dashboard →IAM admin → service account → app engine service account → click on 3 dot option and click on create a key and generate JSON file. There you will get the private key. In the deployment, you get the option to add a variable in the right side. Give some name and add the private in value and then use the name in KEY_FILE.

In my next blog post, I will write about how to add environment variable for different build flavour and build command in package.json file.

Top comments (0)