DEV Community 👩‍💻👨‍💻

Alexei Moussatov
Alexei Moussatov

Posted on • Updated on

Howto: Drop-down list Jira's components in Jenkins

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.


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 = ""
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(
        if( componentsMatcher ) {
            names +=
return names

Step 4: Set to "Referenced parameters" JIRA_PROJECT

Step 5: Enjoy!

Top comments (0)

🌚 Life is too short to browse without dark mode