Trigger a Build

Builds can be triggered from within Jira using the Build issue action or by opening the Issue Action panel and using the button Trigger a Build to open the Trigger Build dialog box.

With the Trigger a Build dialog open, you can simply select related Jobs or use the auto-complete search box to search for other jobs.

You can use the key of the issue from where you triggered the build in Jira within your build in Jenkins. When a build is triggered from Jira a special build cause is used, this cause is of type org.marvelution.jji.trigger.JiraCause and contains two fields issueKey and by, which are both accessible through a getter, getIssueKey() and getBy() respectively. The by field contains the username of the user that triggered the build from Jira, the issueKey field as is describes contains the key of the issue in Jira.

So you could obtain and use the issue key using the following Jenkins pipeline snippet.

def jiraCauses = currentBuild.getBuildCauses('org.marvelution.jji.trigger.JiraCause')

// This results in a JSON array for Jira Trigger build causes like this:
//  {
//    "_class":"org.marvelution.jji.trigger.JiraCause"
//    "shortDescription":"Started by admin through TEST-10",
//    "by":"admin",
//    "issueKey":"TEST-10"
//  }

def issueKey = jiraCauses[0]['issueKey']

Or for short.

def issueKey = currentBuild.getBuildCauses('org.marvelution.jji.trigger.JiraCause')[0]['issueKey']

You can also obtain the issue key through the raw build reference, see snippet below.

def issueKey = currentBuild.rawBuild.getBuildCauses('org.marvelution.jji.trigger.JiraCause').getIssueKey()