I'm creating a pipeline where, in the user input section, I aim to display a message that isn't a plain text but rather derived from the output obtained in earlier steps. Specifically, I intend to showcase the repositories that match the provided ApplicationName (where the application name is used to create repositories).
pipeline I am pasting here and I will attach the screenshot for the same:
Pipeline:
pipeline { agent any environment {
creds = credentials("xm_com")
search_string = "${params.ApplicationName.toLowerCase()}"
}
parameters {
choice(name: 'CommonName', choices: ['CP', 'Mag', 'COMMON', 'NOW'], description: 'Framework or CommonName')
string(name: 'ApplicationName', defaultValue: '', description: 'Enter Application Name')
choice(name: 'CodeOwner', choices: ['Osd', 'TF', 'TM'], description: 'Choose Code Owner')
text(name: 'Description', defaultValue: '', description: 'Write 1-2 lines about the purpose of repo')
}
stages {
stage("read parameters") {
steps {
script {
echo "CommonName: ${params.CommonName.toLowerCase()}"
echo "ApplicationName: ${params.ApplicationName.toLowerCase()}"
echo "Code_Owner: ${params.CodeOwner}"
echo "Description: ${params.Description}"
echo "Tool: $tool"
}
}
}
stage("Check ApplicationName and Confirm Build") {
steps {
script {
// Pull list of repositories
sh """
curl -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: token ${creds_PSW}' 'https://api.github.com/orgs/org/repos?visibility=all&page=1&per_page=500' | grep '\"name\":' | sed 's/\"name\": \"\\([^\\\"]*\\)\",/\\1/' > repositories
"""
// Check if any repositories match or repository in the search criteria
def matched_repositories = []
for (repo in readFile('repositories').readLines()) {
if (repo.toLowerCase().contains(search_string)) {
matched_repositories.add(repo)
}
}
if (matched_repositories.empty) {
echo "No repositories matched the search criteria."
input message: 'No repositories present with the given name Do you want to proceed with the build?', ok: 'Yes', submitter: 'user'
} else {
// facing problem here need to display matched_repositories
def userInput = input message: "Similar repos exist: ${matched_repositories.join(', ')}. Do you want to proceed with creating a new repository?",
ok: "Yes",
parameters: [
booleanParam(defaultValue: false, description: 'Proceed with creating a new repository', name: 'Proceed')
]
}
}
}
}
}
}
Solution on how to display a variable at input if possible. enter image description here