-
New Feature
-
Resolution: Duplicate
-
Minor
-
None
create a credential of type secretText.
Attempt to use it in a workflow like
withCredentials([[$class: 'StringBinding', credentialsId: 'production_magic', variable: 'magicValue']]) { while (true) { def theguess= input id: 'guess', message: 'Please enter the magic value', parameters: [[$class: 'com.michelin.cio.hudson.plugins.passwordparam.PasswordParameterDefinition', name: 'Your guess']] if (magicValue != theguess) { echo "you guessed wrong!" } else { break } } echo "Congrats you guessed correctly!" }
This is not currently possible and to access the credential you need to read it from the environment
e.g.
withCredentials([[$class: 'StringBinding', credentialsId: 'production_magic', variable: 'magicValue']]) { while (true) { def theguess= input id: 'guess', message: 'Please enter the magic value', parameters: [[$class: 'com.michelin.cio.hudson.plugins.passwordparam.PasswordParameterDefinition', name: 'Your guess']] if (env.magicValue != theguess) { echo "you guessed wrong!" } else { break } } echo "Congrats you guessed correctly!" }
however - this does not work as the environment requires a node context!
So there should be a way to bind credentials (that make sense) to groovy without requiring a node as requiring a node can take resources and will be locked for the duration until whatever needs the credential is done (and if that is an input you lock an executor).
Current workaround for not locking executors is to get the variable in a block and assign it to another variable.
THis has the consequence that the variable exists outside of the scope of withcredentials - and it may be persisted somewhere.
- duplicates
-
JENKINS-27386 Access credentials value from workflow Groovy script
- Resolved