Skip to content

Instantly share code, notes, and snippets.

@t3knoid
Created February 2, 2018 16:15
Show Gist options
  • Save t3knoid/cb09da16b042bb55ddda370615d73c3e to your computer and use it in GitHub Desktop.
Save t3knoid/cb09da16b042bb55ddda370615d73c3e to your computer and use it in GitHub Desktop.
Jenkins pipeline script that will create an HTML formatted list of Jira issues
def getJiraIssueList() {
/**
* Returns an HTML formatted list of Jira issues related in the build.
* This requires the Jenkins JIRA Pipeline Steps plugin https://jenkinsci.github.io/jira-steps-plugin/getting-started/
* @param None
* @return An HTML string containing Jira issues
*/
def jiraServer = 'JIRA-PROD' // Define a Jira server entry in the Jenkins Jira Steps configuration named JIRA-PROD
def jiraURL = "http://my.jiraserver.com:8080" // Define the Jira URL
def jiraIssues = jiraIssueSelector(issueSelector: [$class: 'DefaultIssueSelector']) // Get all related Jira issues in a list
def issueList = "<h2>No changes since last build.</h2><ul>"
if (jiraIssues.size() != 0) {
issueList = "<h2>List of Changes</h2><ul>"
jiraIssues.each { issueID ->
def issue = jiraGetIssue idOrKey: issueID, site: jiraServer // Retrieves the Jira issue
def summary = issue.data.fields.summary.toString() // Retrieves the summary field
issueList = issueList.concat("<li><a href=\"${jiraURL}/browse/${issueID}\">${issueID} : ${summary}</a></li>")
}
issueList = issueList.concat("</ul>")
}
return (issueList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment