Deploying from Bitbucket using Bitbucket Pipelines


Hi,I had this problem I didn’t know how to deploy automatically on push from Bitbucket. Well, didn’t know there is a CLI that makes everything really easy for deployment. So here is an example for how to easily deploy with Bitbucket Pipelines.

  1. First you will have to setup your variables in Bitbucket. There are multiple level of variables: User Variables, Team Variables, Repo Variables, Deployment Variables. Each one overrides the other in the order detailed here:

For the CLI you will need to set a variable for the OpsCaptain API KEY you could call it OPS_CAPTAIN_API_KEY.

  1. Then you have to go to the Pipelines item in the menu or create a file called bitbucket-pipelines.yml. There is an entire documentation to how to setup bitbucket pipelines:

  2. My bitbucket pipeline looks something like this (oversimplified for the example)

image: node:10.15.3

    - step:
          - node
        script: # Modify the commands below to build your repository.
          - npm install
          - npm test
    - step:
        name: Deployment
        deployment: production
        # trigger: manual
          - npm install -g opscaptain-cli
          - oc login -k $OPS_CAPTAIN_API_KEY
          - oc deploy -ev "SOME_VAR_FOR_OPS=$SOME_VAR_SET_IN_BITBUCKET" -n myapp

Of course this pipeline will execute on every push(you won’t want that). In the Bitbucket Pipelines tutorial you will see how to create pipelines when a tag/branch/etc. is pushed.


Nice, thanks for this.