In Jenkins I have username/password credential named ‘jenkins-user’. How do I use those credentials with e.g. curl in pipelineJob JobDSL like below:
pipelineJob("my-pipeline") {
parameters {
credentialsParam('jenkins-user') {
type('com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl')
required()
defaultValue('jenkins-user')
description('Jenkins username/password')
}
activeChoiceReactiveParam('test') {
choiceType('SINGLE_SELECT')
groovyScript {
script('''
try {
def curlCmd = "curl -u$JENKINS_USER:$JENKINS_PASS host".execute()
def result = curlCmd.text
} catch (Exception e){
e.printStackTrace();
}
''')
fallbackScript('"fallback choice"')
}
referencedParameter('test')
}
}
}
What I am missing there is the binding to env var part like here:
but I don’t see how I can use withCredentials in a JobDSL pipeline job.
Any suggestions?