How to trigger a Jenkins job from a status change in Jira
Asked Answered
H

5

5

I have been looking for a while now for a way to trigger a Jenkins job from the status or a ticket/story in Jira changing status. To give a more detailed example when my team moves a ticket to the 'ready for test' column we would like to be able to trigger a sanity test pack in Jenkins, the ideal situation would then be that we are able to post the results (generated as a html) as a comment on the ticket within Jira. Failing that we would like to be able to publish the results as simply pass/fail.

I have recently been looking at the Jenkins Jira plugin but this does not seem to have the functionality to work both ways, in other words it can post results after a job has run but you cannot trigger the job from a change of status in Jira. Is there any such plugin available or is it something that we will need to create ourselves?

Cheers in advance

Horme answered 6/5, 2015 at 15:20 Comment(0)
V
5

So, basicly there are webhooks in jira (https://developer.atlassian.com/jiradev/jira-architecture/webhooks). With it you can configure it to trigger specific url on issue status change. The specific url should be jenkins API, for example for triggering a build you should call an external url like (if you are building with parameters): http://server/job/myjob/buildWithParameters?token=TOKEN&PARAMETER=Value

Some more info https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

Voidable answered 6/5, 2015 at 21:5 Comment(0)
B
4

I have written a Jenkins plugin that supports JIRA status change trigger: jira-trigger-plugin.

This plugin also injects an environment variable of JIRA_ISSUE_KEY, so you can utilise this information to publish your result back to JIRA e.g. using REST API.

Bryozoan answered 16/2, 2016 at 8:13 Comment(1)
Looks like jira only allows 80 and 443 ports :( "WebHooks can only use standard http and https ports (80 or 443)."Maurilia
K
2

Please follow as mentioned below:

GIT:

You can set the web hooks for git/ bitbucket /stash on commit which inturn should change the state of task in JIRA.

JIRA:

Once you in JIRA. define the workflow for your task. In this particular workflow you can set a post-function where the web hook should be configured. In this configuration of webhook in events define JQL as below:

status CHANGED FROM "To Do" TO "ready to test".

In the same mention the job that needs to be fired in the URL section.

Kampmeier answered 12/1, 2017 at 21:15 Comment(0)
D
1

You can look through webhooks in Jira : https://support.atlassian.com/jira-cloud-administration/docs/manage-webhooks/

You also need to add the Generic Webhook Trigger plugin to your Jenkins : https://plugins.jenkins.io/generic-webhook-trigger/

You can find here an example on how to use the Generic Webhook Trigger plugin with Bitbucket Github and Gitlab. https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd

Drafty answered 13/6, 2022 at 10:4 Comment(0)
D
0

It involved multiple steps If you are using Git/Stash/BitBucket (which i implemented), You can simply

  1. configure the commit hooks in your Stash/Bitbucket
  2. Attach events to your JIRA workflow
  3. Jenkins JOB - post build events - configure Notify
  4. Stash plugin Set the Poll SCM

That's it

Dispersant answered 22/9, 2016 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.