Skip to content
Permalink
Browse files

[JENKINS-22126] override build parameters only when explicitly reques…

…ted on configuration
  • Loading branch information...
ndeloof committed Mar 11, 2014
1 parent 0287bec commit f99197cea54c828365736984c6c4e184774e6b12
@@ -4,6 +4,7 @@
import hudson.model.*;
import org.jenkinsci.lib.envinject.EnvInjectException;
import org.jenkinsci.lib.envinject.EnvInjectLogger;
import org.jenkinsci.plugins.envinject.service.EnvInjectVariableGetter;
import org.jenkinsci.plugins.envinject.service.EnvironmentVariablesNodeLoader;

import java.util.HashMap;
@@ -25,6 +26,15 @@ public void buildVariablesFor(AbstractBuild build, Map<String, String> variables
//Only for a parameterized job
if (parameters != null) {

EnvInjectVariableGetter variableGetter = new EnvInjectVariableGetter();
EnvInjectJobProperty envInjectJobProperty = variableGetter.getEnvInjectJobProperty(build);
if (envInjectJobProperty == null) {
// Don't override anything if envinject isn't enabled on this job
return;
}

if (!envInjectJobProperty.isOverrideBuildParameters()) return;

//Gather global variables for the current node
EnvironmentVariablesNodeLoader environmentVariablesNodeLoader = new EnvironmentVariablesNodeLoader();
Map<String, String> nodeEnvVars = new HashMap<String, String>();
@@ -28,6 +28,7 @@
private boolean on;
private boolean keepJenkinsSystemVariables;
private boolean keepBuildVariables;
private boolean overrideBuildParameters;
private EnvInjectJobPropertyContributor[] contributors;

private transient EnvInjectJobPropertyContributor[] contributorsComputed;
@@ -52,6 +53,11 @@ public boolean isKeepBuildVariables() {
return keepBuildVariables;
}

@SuppressWarnings("unused")
public boolean isOverrideBuildParameters() {
return overrideBuildParameters;
}

@SuppressWarnings("unused")
public EnvInjectJobPropertyContributor[] getContributors() {
if (contributorsComputed == null) {
@@ -114,11 +120,14 @@ public void setKeepBuildVariables(boolean keepBuildVariables) {
this.keepBuildVariables = keepBuildVariables;
}

public void setOverrideBuildParameters(boolean overrideBuildParameters) {
this.overrideBuildParameters = overrideBuildParameters;
}

public void setContributors(EnvInjectJobPropertyContributor[] jobPropertyContributors) {
this.contributors = jobPropertyContributors;
}


@Override
public JobProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws Descriptor.FormException {
EnvInjectJobProperty property = (EnvInjectJobProperty) super.reconfigure(req, form);
@@ -164,6 +173,7 @@ public EnvInjectJobProperty newInstance(StaplerRequest req, JSONObject formData)
JSONObject onJSONObject = (JSONObject) onObject;
envInjectJobProperty.setKeepJenkinsSystemVariables(onJSONObject.getBoolean("keepJenkinsSystemVariables"));
envInjectJobProperty.setKeepBuildVariables(onJSONObject.getBoolean("keepBuildVariables"));
envInjectJobProperty.setOverrideBuildParameters(onJSONObject.getBoolean("overrideBuildParameters"));

//Process contributions
setContributors(req, envInjectJobProperty, onJSONObject);
@@ -17,6 +17,13 @@
checked="${instance.keepBuildVariables}" default="${true}"/>
</f:entry>

<f:entry field="overrideBuildParameters" title="${%Override Build Parameters}">
<f:checkbox
name="overrideBuildParameters"
checked="${instance.overrideBuildParameters}" default="${false}"/>
</f:entry>


<f:entry title="${%Script File Path}"
help="/descriptor/org.jenkinsci.plugins.envinject.EnvInjectJobProperty/help/scriptFilePath">
<f:textbox

0 comments on commit f99197c

Please sign in to comment.
You can’t perform that action at this time.