Skip to content
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

[JENKINS-26583] - Do not suppress environment variables contributed by extensions #125

Merged
merged 14 commits into from Oct 6, 2017

Conversation

oleg-nenashev
Copy link
Member

It is a partial version of #124, which does not fix all tests created by @olivergondza. But it at least resolves the issue reported in JENKINS-26583, at least on the common paths.

More fixes are to come later.

@reviewbybees @olivergondza @recena

@ghost
Copy link

ghost commented Sep 29, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@carltonbrown
Copy link

I verified that this PR fixes https://issues.jenkins-ci.org/browse/JENKINS-26583 . Please merge asap!

@oleg-nenashev
Copy link
Member Author

Retriggering CI

for (Map.Entry<String, String> storedVar : currentEnvMap.entrySet()) {
final String varName = storedVar.getKey();
final String storedValue = storedVar.getValue();
final String envValue = env.get(storedVar.getKey());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use local variable varName defined 2 row above

}

if (usedExternalValue) { // The value was overridden, let's update the cache
LOGGER.log(Level.CONFIG, "Build {0}: Variable {1} is defined externally, overriding the stored value {2} by {3}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are password logged in plain text?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

boolean usedExternalValue = true;
if (parameterEnvVars != null) {
String parameterValue = parameterEnvVars.get(varName);
if (envValue.equals(parameterValue)) { // defined by parameter and not already overridden
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous comment you refer to shouldOverrideBuildParametersIfEnabled() settings.
I do not see where the value is taken, I would expect that value in && here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldOverrideBuildParametersIfEnabled() is a test, there is no such configuration option

Copy link
Member

@nfalco79 nfalco79 Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that option in the job configure page:

image

Should this option be ignored in override policy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, needs investigation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @nfalco79 here, I think since the existing behavior is being changed anyway, it makes sense to start checking that option here. From what I can see, that option is currently only used in the EnvInjectBuildVariableContributor class which does something similar to this piece of code. Tests pass for me locally with the change:

EnvInjectJobProperty envInjectJobProperty = RunHelper.getEnvInjectJobProperty(build);
if (parameterEnvVars != null && envInjectJobProperty != null && envInjectJobProperty.isOverrideBuildParameters() && parameterEnvVars != null) {
    String parameterValue = parameterEnvVars.get(varName);            

@oleg-nenashev
Copy link
Member Author

@nfalco79 Thanks for catching it! Updated the PR

@nfalco79
Copy link
Member

nfalco79 commented Oct 3, 2017

Also for me seems work (PATH env var is valid)

@oleg-nenashev
Copy link
Member Author

I still anticipate some regressions, likely I will add a compatibility warning. In #124 I tried to do more things about the resolution order (e.g. Extension listing order), but it is a subject for the next pull requests.

@ghost
Copy link

ghost commented Oct 3, 2017 via email

@oleg-nenashev
Copy link
Member Author

@dwnusbaum @nfalco79 done

Copy link
Member

@dwnusbaum dwnusbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐝

@oleg-nenashev
Copy link
Member Author

My plan is to release it today/tomorrow together with jenkinsci/envinject-lib#11 from @dwnusbaum

@oleg-nenashev
Copy link
Member Author

@reviewbybees done

@oleg-nenashev
Copy link
Member Author

Merging without squash since there are multiple contributors. No plans to backport this tricks anyway

@oleg-nenashev oleg-nenashev merged commit 0ce6662 into jenkinsci:master Oct 6, 2017
@oleg-nenashev
Copy link
Member Author

The fix caused regressions (no wonder), I am blacklisting the release for a while to investigate them: jenkins-infra/update-center2#167 . Likely I will respin the release and disable the new behavior by default (and add a flag in UI)

@dwnusbaum
Copy link
Member

dwnusbaum commented Oct 11, 2017

@oleg-nenashev I reproduced the reported issues and agree with blacklisting it for now. Hiding the new functionality behind a checkbox that says something like "Do not override environment variables defined elsewhere" makes sense to me, and I think we should also add a few tests to prevent a regression in the future.

I would like to know if the people who were blocked by JENKINS-26583 find that 2.1.4 works for them correctly or has any issues.

@nfalco79
Copy link
Member

Hiding the new functionality behind a checkbox that says something like "Do not override environment variables defined elsewhere"

Checkbox solution will not work because the issue JENKINS-26583 happens just installing this plugin.
With that kind of solution means that I have to tick the option in every job / pipeline just because the plugin is in the system.

Actually I had install 2.1.4 in our system and seems the PATH variable is ok because the nodejs command is available. Anyway let me do other try

@nfalco79
Copy link
Member

Just to be informed, what is the regression?

@dwnusbaum
Copy link
Member

@nfalco79 JENKINS-47364 and JENKINS-47370, users relied on environment variables defined elsewhere being overridden by the plugin, which is exactly the functionality that this PR removed.

@nfalco79
Copy link
Member

nfalco79 commented Oct 11, 2017

JENKINS-47364 seems a real regression where variables are not substituted.

Instead in JENKINS-47370 if I interpreted right the option "Override Build Parameters" he miss to enable it (taking care about only the use case in the issue description, not the following comments).

@dwnusbaum
Copy link
Member

For JENKINS-47370 I tested with that setting but it was still broken. From what I can tell the user just has it a set as a environment variable in Jenkins' global properties configuration, and the "Override Build Parameters" setting only deals with parameters, not global environment variables.

@oleg-nenashev
Copy link
Member Author

@nfalco79 In any case, I am not going to revert the fix.

My plan is to temporary disable it while I am figuring out what to do with regressions in non-Pipeline use-cases. In the case of Pipeline, we can break whatever we want in the current state (there is a warning in Wiki). Feature flag is something under consideration. If the impact is not high, I also consider keeping the new behavior by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants