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

kctang
  • 10,894
  • 8
  • 44
  • 63
user2131710
  • 265
  • 2
  • 6
  • 13

5 Answers5

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

Stan E
  • 3,396
  • 20
  • 31
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.

ceilfors
  • 2,617
  • 23
  • 33
  • Looks like jira only allows 80 and 443 ports :( "WebHooks can only use standard http and https ports (80 or 443)." – Stratos Ion Dec 21 '17 at 16:25
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.

joshi0788
  • 43
  • 11
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

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