V
V
Venot2021-05-24 19:10:33
Jenkins
Venot, 2021-05-24 19:10:33

How to read a file in jenkins script for getting dynamic parameters?

I want to make a dynamic display of the parameters, and take these parameters from the yaml file in the repository. Doesn't want to open the file, took out this piece in the stage, used only readYaml, it works, that is, it showed me the necessary parameters...

properties([
parameters([

[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT', filterLength: 1, filterable: false,
name: 'DTARGET', randomName: 'choice-parameter-11997779855545603',
description: '''Select DataBase''',
script: [$class: 'GroovyScript',
script:[ sandbox: true,
script: "return [${targets.collect{'\'' + it + '
], fallbackScript: [sandbox: true, script: "return ['update_pipeline']"]
]
],

[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT', filterLength: 1, filterable: false,
description: ''' Available scripts to run ''',
name: 'COMMAND', randomName: 'choice-parameter-119975603',
script: [$class: 'GroovyScript',
script:[ sandbox: true,
script: '''
try{
String hosts_file = new File("${env.WORKSPACE}/sql_request/queries.yaml").text
Yaml yaml = new Yaml()
Object data = yaml.load(hosts_file)
queries = []
for (item in data[DTARGET])
{
queries.add(item.key)
}
return queries
} catch (Exception ex) {
return [ex.toString()]
}
''' // script
], fallbackScript: [ sandbox: true, script: 'return["ScriptError"]']
], referencedParameters: 'DTARGET'
]
])
])

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question