Getting started with Bitbucket Pipelines

illustrations illustrations illustrations illustrations illustrations illustrations illustrations
post-thumb

Published on 11 May 2023 by Andrew Owen (2 minutes)

I’m a big fan of GitHub Actions. But if you’re working for an enterprise software company, there’s a fair chance you’re using Atlassian’s Bitbucket Cloud (along with Confluence and Jira). If so, then you can use Pipelines to build continuous integration and deployment workflows. If you’re new to DevOps and CI/CD, I have a TL:DR for you.

  1. In Bitbucket, go to your repository and select Pipelines.
  2. Click Create your first pipeline to scroll down to the template section.
  3. Select the Starter pipeline. This will create a file called bitbucket-pipelines.yml.

Previously, I wrote a GitHub Action to unpack a zip archive. So let’s recreate that:

image: atlassian/default-image:3

pipelines:
  default:
    - step:
        name: 'extract a zip file'
        condition:
          changesets:
            includePaths:
              - "*.zip"
        script:
          - rm -r uploads/extracted
          - filename=$(basename -s .zip *.zip)
          - unzip *.zip
          - rm *.zip
          - mv $filename temp
          - mv temp/out/* .
          - rm -r temp
          - git add .
          - git commit -m "unzip"
          - git push origin main

When you’re done, click Commit File.

Bitbucket Pipelines runs your builds in Docker containers. So first you need to choose an image. The default is atlassian/default-image:latest. Atlassian recommends using this until you get your pipeline working and then finding a specific image. So in this instance, we’re using Ubuntu 20.04 LTS.

  • default tells the script to run when a commit is pushed to any branch.
  • parallel enables you to run steps simultaneously, but it’s not necessary here.
  • step is an individual task.
  • name is the display name of the step.
  • condition limits the circumstances under which the script runs.
  • changesets specifies changes to use as a condition.
  • includePath sets the file path that will match the condition.
  • script is the Linux CLI input.

The script is virtually identical to the GitHub Action I wrote, so for a more detailed explanation, you can read that.

Image: original by Sigmund.