简体   繁体   中英

How to trigger a Jenkins job from a status change in Jira

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

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

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 eg using REST API.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM