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
Open the id_rsa.pub. Note, if the file does not exist you should create it using
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
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.
Now you should see your key in the 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.
When you’ve finished you should see the plugin enabled.
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:
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
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.
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.