In the previous receipt about Drop-down list for values we learned how-to choice any predefined project.
At this receipt I've tell about how to create drop-down list for choosing component's names by regex from Jira via API.
Prerequisites:
- Active Choices plugin
- Jira credentials
Step 1: In job configuration add parameter Active Choice Reactive Parameter
Step 2: Set name for your parameter (for example COMPONENT)
Step 3: Select Groovy script and add next groovy-code
import groovy.json.JsonSlurperClassic
import java.util.regex.*
def regexLine = "(((my|other)-(int|sys|bpl|pl|stp|tst)-([a-z,0-9,-]*)))"
def jiraUrl = "http://jira.domain.org"
def jiraProjectKey = JIRA_PROJECT
def juser = "JenkinsJiraUser"
def jpass = "PasswordOfJenkinsJiraUser"
def url = "curl -u ${juser}:${jpass} ${jiraUrl}/rest/api/2/project/${jiraProjectKey}/components"
def json = url.execute().text.replaceAll("\r\n", "")
def data = new JsonSlurperClassic().parseText(json)
def names = []
data.each{ component->
if (component) {
Matcher componentsMatcher = Pattern.compile(regexLine).matcher(component.name)
if( componentsMatcher ) {
names += component.name
}
}
}
return names
Step 4: Set to "Referenced parameters" JIRA_PROJECT
Step 5: Enjoy!
Top comments (0)