We want to automate project build using a Parametrised Jenkins Pipeline of the source code stored in Bitbucket Server.
Firstly, we need to install the necessary Jenkins plugins.
Git Parameter - https://plugins.jenkins.io/git-parameter/ - adds git parameters to the Jenkins pipelines, you can use it to specify the branch to check in or any other things used in the Jenkins pipeline.
Build Authorization Token Root Plugin - https://plugins.jenkins.io/build-token-root/ - allows to use the build token for external builds.
Secondly, create a Jenkins Pipeline that checks out and builds the code.
Afterwards, add branch as a parameter.
Generate an authentication token and make sure you don’t share it.
Add create your super simple pipeline that builds the branch or just print the hello world message.
Now we are ready for the Bitbucket Server configuration.
Install the Bitbucket Post Webhooks plugin and navigate to the repository settings to configure the triggers.
The url should be in the following format and parameters are passed in the url.
Click the test connection to see if it triggers the message.
Select the triggers for the notifications., For instance, it makes sense to sell “On push“.
Push the code to your master branch and trigger the build!
Enjoy the building and welcome to our world!