Overview
This article will focus on a step-by-step setup guide for a continuous integration pipeline leveraging Jenkins and Bitbucket Cloud.
Prerequisites
+ Jenkins server hosted on a AWS EC2 Instance+ Bitbucket Private Repo
Install Bitbucket Source Plugin
In Jenkins navigate to Manage plugins, search for the "Bitbucket Branch Source" plugin. Start the install process.Configure the Bitbucket Source Plugin
We need to add our Bitbucket credentials in Jenkins to link with the newly installed plugin. We will use username and password for this purpose.Manage Jenkins > Configure System > scroll down to "Bitbucket Endpoints" section > Add Credential.
Make sure to check "manage hooks" so the plugin knows to create a repo webhook automatically for any new pipeline jobs added.
Create a New Multi Branch Pipeline Job in Jenkins
Navigate to Jenkins Home, then "New Item" Selecting Multibranch Pipeline.Give it a name and save.Next we will link the new Job to our Bitbucket Repo. Select Bitbucket for branch source.
And select our username/password credentials that we created for the plugin configuration. If authentication is successful you should get a list of your repos in the dropdown. I'll select my repo "test_repo".
This pipeline will build leveraging a Jenkinsfile written in Apache's Groovy language and located at the root of my repo.
Apply and save - now we can verify this worked as expected by navigating to our repo in Bitbucket and going to settings > webhooks - verify the webhook is pointed to your Jenkins server followed by "/bitbucket-scmsource-hook/notify"
Next we can add a Jenkinsfile to the repo. This will kick off the first build of our new pipeline!
Conclusion
That's it! Checkout the new pipeline!
Build status' can also be monitored directly from your repo in Bitbucket. It also links directly into Jenkins to view the build info.
Enjoy customizing your new Jenkins Pipeline with Bitbucket!
Resources
Jenkins Pipeline docs (https://www.jenkins.io/doc/book/pipeline/)
Jenkins Bitbucket Plugin (https://plugins.jenkins.io/cloudbees-bitbucket-branch-source/)
Bitbucket (https://bitbucket.org/)
No comments:
Post a Comment