[UPDATE] 10/14/2013 – Updated to match version 2.0 of the Stash Webhook for Jenkins
There are lots of posts about connecting Jenkins with GitHub, but not a lot about connecting Jenkins to Stash. So, hopefully this helps!
Triggering Jenkins from Stash
Using Git’s post-receive hooks, it’s possible to trigger builds on Jenkins after a commit. There is a little configuration required in both Jenkins and Stash.
Configuring Jenkins
- Install the Git Plugin in Jenkins.
- Configure your project to use Git for your Source Code Management. You will need to keep the Repository URL you use for configuration in Stash.
- Enable the Poll SCM option in the Build Triggers. This is required to remotely trigger a build. Since we don’t really need to poll, you can set the poll frequency to poll very infrequently.
- Save your project configuration.
Configuring Stash
- In Stash, install the Stash Webhook for Jenkins plugin (GitHub source).
- Navigate to your repository and hit the Settings tab.
- In the left-side navigation, click the Hooks link.
- Click the Enabled button for the Stash Post-Receive Webhook to Jenkins hook.
- Enter the URL for your Jenkins instance and the Repository URL that you configured Jenkins to use. You can use the dropdown to get the clone URL for each supported protocol. Afterwards, feel free to change it to match your Jenkins instance.
- Click the Trigger Jenkins button to test your configuration. If it worked, it’d look like this:
That’s it!
With both Jenkins and Stash now configured, if you commit code, a build trigger will automatically occur. What happens is the post-receive hook fires a GET request to Jenkins, which then tells it to poll the repository (why you need to have polling turned on). The poll checks to see if there are actually any changes. Since there are, it triggers the build!
Notifying Stash of Jenkins Build Result
Once the build has been completed, it’d be nice to let Stash know the results of the build. By installing the Jenkins Stash Notifier Plugin, it’s a piece of cake.
- Install the Stash Notifier Plugin in Jenkins.
- In Jenkins, go to your project’s configuration.
- At the bottom, add a “Post-build action” of “Notify Stash Instance.”
- Enter your Stash URL, username, and password.
- That’s it!
What it looks like
On the commit page, it shows the Build Result (in this case a pass) in the far-right column
Clicking the result displays a popup containing all builds associated with the commit. You can click on the title to go directly to the Jenkins page for that build.