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.

By default, the issue key, url and the user display name of the user that triggers the build are passed to Jenkins. If you want this to be the user’s id, then select the User Id option, see Configuration User Id vs Display Name.

Triggering a Parameterized Build

Administrators can configure which issue fields are passed to Jenkins when triggering a build, see Parameter Issue Fields.

Issue fields are only passed to Jenkins if the field was enabled as parameter issue field, and the field has a value on the issue where the trigger was sends from. Parameter names are created by taking the issue field name and replacing any space with an underscore. The Jira Integration for Jenkins plugin will match parameters to actual job parameters.

By default, the following parameters are available even if no issue fields are configured as build parameter:

Parameter Names Description
issueKey, issue_key Key of the issue where the trigger was send from.
issueUrl, issue_url URL of the issue where the trigger was send from.

Matching of Jira send parameters to actual job parameters is case-insensitive. For example, if the ‘Fix versions’ field in enabled, Jira sends a parameter named ‘Fix_versions’ and Jenkins will match ‘Fix_versions’, ‘fix_versions’ and ‘FIX_VERSIONS’.

Access Trigger Data

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 Display name or id 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()