The Jenkins credentials plugin provides a withCredentials
function that can store the value of a credential into a scoped environment variable as seen here.
node {
withCredentials([usernameColonPassword(credentialsId: 'mylogin', variable: 'USERPASS')]) {
sh '''
set +x
curl -u "$USERPASS" https://private.server/ > output
'''
}
}
I want to write a groovy method we store in our Jenkins vars shared library that does something similar; a list of pairs for an ID to operate on and the name of an environment variable to store that ID within scope of the function. Something like
withMyOwnVars([
['some-input', 'VAR_NAME'], // Value of VAR_NAME will be set under the hood somehow.
['another-one', 'VAR2']
])
{
print("$VAR_NAME")
}
Does Groovy provide this functionality?