DEV Community

Alexei Moussatov
Alexei Moussatov

Posted on • Edited on

1 3

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.

Prerequisites:

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!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay