-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
withCredentials Returns the values as the name of the variables instead of the credential #532
Comments
Sorry, for the delay, I haven't had time to work on this project recently, but my team now has a hack sprint so I'll be examining this issue soon. |
So I had a look at this yesterday, and the fix isn't that difficult: --- a/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy
+++ b/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy
@@ -33,7 +33,7 @@ abstract class BasePipelineTest {
}
// we are in context of withCredentials([string()..]) { }
if(desc.variable) {
- return desc.variable
+ return [name: desc.credentialsId, value: desc.variable]
}
}
}
@@ -68,13 +68,16 @@ abstract class BasePipelineTest {
}
binding.setVariable(password, password)
} else {
- creds.each { var ->
+ creds.each { var, value ->
+ previousValues[var] = binding.getVariable(var)
try {
- previousValues[var] = binding.getVariable(var)
- } catch (MissingPropertyException e) {
+ Map credentials = binding.getVariable('credentials')
+ if (credentials.containsKey(creds.name)) {
+ binding.setVariable(creds.value, credentials[creds.name])
+ }
+ } catch (MissingPropertyException ignored) {
previousValues[var] = null
}
- binding.setVariable(var, var) ...the problem is that this breaks other stuff. In general, I'm not a huge fan of the current implementation of I'll keep hacking on this next week and see if I can come up with a good solution. |
Update: I did indeed spend some time hacking on this, but I couldn't come up with a good solution. I'll have to spend some more time in the future rewriting |
Any progress on this? |
Sorry, no, I've been too busy with other stuff to work on this. |
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
jenkins 2303.2
Reproduction steps
withCredential.groovy content
Expected Results
echo: USERNAME
echo: PASSWORD
Actual Results
echo: ARTIFACTORY_USER
echo: ARTIFACTORY_PASSWORD
Anything else?
To fix it I have to override the registry of withCredentials to actually read the credentials
i.e.
The text was updated successfully, but these errors were encountered: