Go, gb and Bitbucket Pipelines

Using Go and gb together with Bitbucket Pipelines

May 24, 2016

Earlier today Atlassian announced Bitbucket Pipelines. It is basically CI built into Bitbucket. I gave it a try and it works perfectly fine for my not so extensive use case.

When setting up Pipelines, the documentation has NodeJS, Java, Ruby, Python and PHP covered. Unfortunately Go is nowhere to be found. Don’t fret, we can do it ourselves :).

Pipelines makes use of Docker images, so we’ll require a Docker image with both Go and gb installed. In order to build this Docker image, the most basic of Docker knowledge is required. However you may skip this step and rely on my image. I do advice against this however, because I won’t be maintaining it :).

Creating the required image

First we’ll have to create an image that has both go and gb installed.

This one is quite straightforward:

Dockerfile

FROM golang:1.6

RUN go get github.com/constabulary/gb/...

RUN mkdir /project
WORKDIR /project

After creating this file, build the image and push it to Docker Hub.

docker build -t "your_docker_username/golang-gb" .
docker push "your_docker_username/golang-gb"

That was step one.

Adding bitbucket-pipelines.yml

Next up is adding the bitbucket-pipelines.yml to your repository. Mine is very simplistic. It pulls in your dependencies, runs the tests and tries to build everything. You can extend this with automatic deployments and other cool stuff, if you want.

But for now we’ll stick with this. This way you’ll at least know your application will build with its current dependencies.

bitbucket-pipelines.yml

image: your_docker_username/golang-gb

pipelines:
  default:
    - step:
        script:
          - gb vendor restore
          - gb test
          - gb build all

Now, if you’d commit and Pipelines are enabled on your repository, you’ll see the build status under Pipelines in the menu, or when you look in your commit overview.

You can click any build and if all goes well, you’ll probably see something like this:

Bitbucket Pipelines

This is just a very basic way of building and testing your gb project using Bitbucket Pipelines. If you have any questions, feel free to ask them in the comments below. Otherwise you can always ping me on Twitter.