-
Notifications
You must be signed in to change notification settings - Fork 409
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
escape double quotes in env variables under windows #220
Conversation
bouncing to run against updated CI |
Can I help the process with getting this in, like providing more details/documentation or adding tests for such special characters in environment variables? |
Hi @schribl if you could add some tests for the special characters that would be great! |
HI @car-roll I tried implementing some tests for this change (escaping arguments for Windows). But a real test would require the CI to have windows nodes with docker installed IMO. Doing some other tests require changes of the So I do not think this can really be tested without changes to the infrastructure or at least I do not see a good way for doing so. |
So the biggest concern is if this change breaks some other use cases. If you look at this method https://github.com/jenkinsci/jenkins/blob/449c5aced523a6e66fe3d6a804e5dbfd5c5c67c6/core/src/main/java/hudson/os/WindowsUtil.java#L53 you can see a bit of checking that goes on here. It might be possible to replace Would you happen to have a few examples that this PR is addressing? Thanks @dwnusbaum for the link to the code and basically this response. |
@car-roll @dwnusbaum Thank you! The link indeed looks good and I can understand the concern to break something else with this change. I will do some more tests and provide the feedback including the results for A simple example I tested with was:
And for the background what use case is affected: We are using GitLab and when the job is triggered the GitLab Plugin sets environment variables (including MR description). And it often occurs that quotes are used inside the MR description and this will result in job failures with "strange" error messages. |
I did some more tests and can now confirm that #215 did not resolve the issue as it does change if (variable.getValue().contains(" ") {
argb.addMasked(WindowsUtil.quoteArgument(variable.getKey() + "=" + variable.getValue()));
} else {
argb.addMasked(variable.getKey() + "=" + variable.getValue());
} This also worked for my simple test case but only quoting the value did not work as the function adds quotes around the string and as a result has to quote the full argument. I also think the @car-roll Is there a better way then copying the |
@schribl yes, in this case you will have to bump the jenkins version in the pom from 2.176.4 to 2.190.1 (you might have to resolve some dependencies in that case). update: just a quick correction, apparently |
1c8147e
to
d5c5812
Compare
Thanks @car-roll I did the changes for the proper update and it is using |
src/main/java/org/jenkinsci/plugins/docker/workflow/client/WindowsDockerClient.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/plugins/docker/workflow/client/WindowsDockerClient.java
Outdated
Show resolved
Hide resolved
d5c5812
to
cbc549b
Compare
@dwnusbaum Can you check the changes I made regarding your review comments? Thank you! |
@car-roll and @dwnusbaum Friendly reminder on this PR :) |
Problem description:
For Windows there is a problem with Javas ProcessBuilder and arguments that contain spaces and contain double quotes as ProcessBuilder adds double quotes around such argument.
See e.g. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6511002 and https://stackoverflow.com/questions/12124935/processbuilder-adds-extra-quotes-to-command-line
Solution:
For Windows all environment variables (only values) are escaped (currently only escapes quotes). No changes made to the Linux (and others) code as I could only reproduce this behavior with a Windows node.
Notes: