-
Notifications
You must be signed in to change notification settings - Fork 389
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
Assertion on withEnv fails when Env Var value contains equals (=) sign #388
Comments
At the moment this is working for me: helper.registerAllowedMethod(
'withEnv', // see https://github.com/jenkinsci/JenkinsPipelineUnit/issues/388
[List, Closure],
{ List list, Closure c ->
def stashedEnv = [:]
try {
stashedEnv.putAll(binding.getVariable('env') as Map)
} catch (MissingPropertyException e) {
// 'env' not set yet?
}
list.each {
def item = it.split('=', 2)
assert item.size() == 2, "Variable ${it} in withEnv (${list}) cannot be split in NAME/VALUE pair"
addEnvVar(item[0], item[1])
}
try {
c.delegate = binding
helper.callClosure(c)
} finally {
// Restore original contents of 'env'
binding.setVariable('env', stashedEnv)
}
}
) |
Another usual use-case that's also hit by this bug is when setting a custom
suggested patch works, but that forces us to overwrite the complete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, and thank you for working on JenkinsPipelineUnit.
When environment variables containing equals signs in their values are used in
withEnv
, the BasePipelineTest check fails erroneously because it splits the variable "too much".A use case is passing tags or other parameters to the AWS CLI:
However, the above causes an assertion failure in the BasePipelineTest because the code uses
item.split('=')
which splits along all=
resulting in an array of more than 2 elements. Unfortunately, this is breaking some tests on pipelines that otherwise work fine.JenkinsPipelineUnit/src/main/groovy/com/lesfurets/jenkins/unit/BasePipelineTest.groovy
Lines 249 to 250 in 075a7b2
IIUC something like
should do the correct thing and split along the first
=
only.Thank you.
The text was updated successfully, but these errors were encountered: