Notes
Bitbucket Pipelines: Overview and Notes
an overview of bitbucket pipelines from using it on a .NET Core api and a react native app, covering steps, triggers, pipes, variables and caches
DevOps
3 minutes
So far i have used pipelines in 2 different projects. One is a .NET Core API that gets deployed to AWS Elastic Beanstalk and the other is a React Native app that gets deployed to Expo.
Here’s the tl;dr
Basically, you can use custom yaml files to describe what happens after you push code to your repository. Bitbucket will lift some instance and allocate computing power for you, for running the code you describe in the yaml, and you’re paying for the time it takes to run. You can also use some caching techniques to make sure you don’t download large libraries over and over again.
- Every build is run inside a Docker container. You can use any
imageyou want, and you can have seperateimages for separate steps in your pipeline. - You get 50 mins per month with the free Bitbucket plan. Use caches and manual triggers to save up on build times.
- While commands like
dotnet buildandnpm installmay not require installing your packages from scratch, it is recommended to rundotnet restoreandnpm cito do fresh installs of packages in CI/CD pipelines
Overview
Here’s a quick overview of most of the stuff i had to look up.
You can:
- Run different steps for different branches
- Manually or automatically
triggera deploy - Use
pipes to use 3rd-party integration. For example: send a notification to Slack channel, deploy to AWS Elastic Beanstalk, transfer files to S3 etc. - Use variables in your scripts and save their values in settings and not directly inside the pipeline.
- Run individual commands inside a
scriptor you can run a pre-written script. For example./cleanup.sh - It is possible to figure out if a
scriptwas successful or not by using$BITBUCKET_EXIT_CODE(0 = success, 1 = failed) in theafter-script
You save your configuration, written in YAML, in a file called
bitbucket-pipelines.ymlin the root of your repo’s main branch (usuallymaster). Pipelines, Deployments, and Repository variables will not work until you have that file in place. Bitbucket will automatically pick it up once it’s there. Easiest way to get started is to generate a config file online by going to Pipelines in Bitbucket.The configuration page is elaborate and has examples for most of the stuff you need
You can have variables in your pipelines. Those are saved under Settings > Repository varaibles, and referenced as
$SECRET_KEYor${SECRET_KEY}.You can save dependency caches to speed up build times. There are a bunch of pre-defined caches available (e.g:
node,dotnetcoreetc.). You can also define custom caches underdefinitions(e.g.node_modules)If you provide a
deploymentvalue, the builds will show on the Deployments page for that environment. You can setup custom deployment environments under Settings > Deployments. By defaultproduction,stagingandtestare available