<img height="1" width="1" src="https://www.facebook.com/tr?id=1101141206686180&amp;ev=PageView &amp;noscript=1">

Blog

Bitbucket Pipelines - Just a Series of Tubes

 

What are we trying to solve?

In my previous blog post, we discussed setting up the Heroku pipeline with a Ruby on Rails application to provide us with a local test environment, a staging server, and a production server. While this works great for ensuring we properly test our application before releasing it on the world, it has one major flaw. Heroku does not provide a great interface for maintaining a repository in a multi-developer environment. Heroku does not provide a good interface for handling pull requests, linking commits to issues in an issue tracker system (JIRA), or even a good branch history visualization tool.

 

Bitbucket

Bitbucket Cloud is a service for hosting Git repositories. It is a popular competitor to Github, owned by Atlassian. Bitbucket offers integration with Jira and Confluence to better support software development, branch management, and issue tracking. Bitbucket is the service we use internally.

 

What is a pipeline?

For the purposes of this blog post, we are only discussing pipelines in the context of Continuous Integration/Continuous Deployment. A pipeline is essentially a script for automating software deployment tasks. Your pipeline can automate executing unit testing, running environment set-up tasks, and deployment of your end-product to another server.

Pipeline Flow

Picture1-1

Figure 1- Visualizing Software Flow

 

Figure 1 shows a swimlane diagram describing the order of operations we want to occur. First, a developer will push a commit to the develop branch on Bitbucket, triggering the execution of our pipeline. During execution, we’ll set up docker images for Ruby on Rails and Postgres, build our application, run our unit tests, and finally push the code to Heroku for a final build and deploy.

 

Configuring the Pipeline

 

Bitbucket pipelines are defined through a YAML file named “bitbucket-pipelines.yml”. When you push your repository to Bitbucket, Bitbucket will automatically check for the YAML file and begin executing the steps described in that file.

 

Designing the YAML File

Bitbucket offers great documentation on configuring a YAML file. To start, there are two top level objects that must be defined:

  • Image – the image to use, in our case ruby:2.7
  • Pipelines – A set of pipelines for specific triggers (branches, tags, pull requests, etc.)

 

Picture2-1

For the workflow in Figure 1, let’s focus only on pipelines for branches. So let’s tell bitbucket to set up a pipeline for the develop and master branches.

Picture3

Let’s focus on the develop branch, and define some pipeline steps for building our application and pushing it to Heroku.

Picture4

To build and test my application, I need a postgres database. So let’s inform bitbucket, using the services tag.

Picture5

Great! Now we need to provide the script tag. This tag defines the list of CLI commands to run. We’ll use the CLI to build our application, configure our test database, and execute our unit tests (RSpec for our Ruby on Rails application).

Picture6

The above pipeline configuration does all the build and testing. Now it’s time to define the staging deployment step. This step will be much easier, a simple push to the Heroku repository.

 

Picture7

 

Wait… what’s “$HEROKU_API_KEY”?

This is a repository variable. In Bitbucket, navigate to:

Repository Settings > Repository Variables

Once there, you’ll see a menu for providing Key/Value pairs:

Picture8

 

How do I get my HEROKU_API_KEY?

Heroku provides a nice command line option for generating an API key. Open up a bash/cmd prompt and type:

heroku authorizations:create

 

Picture9

You will see the above output. The UUID labeled “Token” is your API key. Copy that and paste it into your repository variables with the name “HEROKU_API_KEY”.

 

 

Executing Our Pipeline

Now that the pipeline is configured, add the bitbucket_pipelines.yml to your commit and push the commit to your bitbucket develop branch.

Bitbucket will automatically begin executing your pipeline. Navigate to Bitbucket and click on the Pipelines menu to see a list of previous and currently executing pipelines.

From there, you can click on an actively running pipeline to get a live view of the pipeline executing.

Picture10

Summing It up

Pipelines provide a very easy way to execute common tasks in response to developer actions. Our script provides a way to execute our unit testing (ensuring that no code ever hits our staging server without passing our tests) and deploy our code to our staging server.

This is not the limit for pipelines. You can set up pipelines to respond to pull requests from developers, build installers for your desktop software, upload files to dropbox, and interact with may other services.

 

Recent Posts:

Introduction to PCB Design and Manufacturing Part 4: PCB Manufacturing 
Publish Date 03 Dec 2021 Nathan SzantoNathan Szanto

So, you’ve created your schematic, you’ve laid out your PCB, you’ve had multiple [..]

How to Build a Better MWD Hand
Publish Date 03 Dec 2021 Jason GalleJason Galle

What skills and experiences should we be looking for in new hires and what kind of [..]

Customer Experience means everything to us, Here's Why...
Publish Date 03 Dec 2021 Casey MayesCasey Mayes

Here at Erdos Miller, we all strive for the same goal, and that is to provide our [..]

NVCC – Intro to Utilizing GPU Power to Offload the CPU Part 2
Publish Date 03 Dec 2021 Jack BakerJack Baker

Assumptions: Machine has a Nvidia CUDA Core GPU (such as a GeForce) with installed [..]

Comparing different methods to get the 50th Fibonacci number in C++
Publish Date 03 Dec 2021 Jamison GrayJamison Gray

When comparing different algorithms, we typically look at space and time complexity, [..]

Introduction to PID Control Loops
Publish Date 03 Dec 2021 Yifang YangYifang Yang

A Proportional Integral Derivative controller (PID Controller) is a closed loop [..]

Making a calculator with Pyside
Publish Date 03 Dec 2021 Ashton ScaliseAshton Scalise

Python is not really the first language that comes to mind when thinking about GUI [..]