I’ve set a few PDP goals, one of which is to work in a more continuous integration (CI) kind of way. I’m planning on writing a series of documents to cover the areas that I’m working with, for my own future reference, and for anyone else who may wish to learn about it (or indeed point out where I’m going wrong).

The basic setup that I will be working with is Bitbucket and Jenkins.

Get the public key from the Jenkins box

ssh onto your jenkins box switch to the correct jenkins user. In my case, it’s the tomcat user

sudo su
su tomcat

navigate to ~/.ssh

cd ~/.ssh

Open the id_rsa.pub. Note, if the file does not exist you should create it using ssh-keygen.

vi id_rsa.pub

Copy the key, you may wish to store it for future reference so you don’t have to come back and get it again to link up further repos.

Add the key to your Bitbucket repo

Go to your repo that you want to link

Open the repository settings and select the “Access keys” link

01 add access key

Select “Add key” and paste your copied key into the box. We only need read access for this purpose so select that and the click the “Add key” button.

02 add access key

Now you should see your key in the list

03 key list

Install jenkins plugin for bitbucket and enable

If you don’t have the jenkins plugin you can add it using the “Add hook” mechanism via the repository settings. Once installed, edit the plugin and set the details for your git repo.

07 bitbucket webhook to jenkins

When you’ve finished you should see the plugin enabled.

08 bitbucket webhook to jenkins

Create a build job in Jenkins

Log into your jenkins web interface and create a new job that is linked to your Bitbucket repo.

In this example I am creating a job to build and deploy a config item for an application.

Link your job using the Git source Code Management plugin:

04 git repo linking

Make sure to put a long Poll in the “Poll SCM” build trigger. Whilst researching this I discovered Jenkins has to have to poll schedule completed to link and allow Bitbucket to build on push

05 git repo linking

As you can see, I have set the polling schedule to be “0 0 1 1 0” so that it will only run at very sparse intervals.

In this job, I have my Post build actions set to publish the repo to an S3 bucket.

06 publishing

Testing

To test I simply need to update the repo and push my changes, then I can see the job run and deploy to the S3 bucket.