Skip to content
Permalink
Browse files
Fix JENKINS-14645
  • Loading branch information
gboissinot committed Aug 1, 2012
1 parent 4d964fa commit 1f0b60388d84928bc03641dcfea41d8284a870fb
Showing with 38 additions and 35 deletions.
  1. +38 −35 src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
@@ -348,50 +348,34 @@ private FilePath getNodeRootPath() {

@Override
public void onCompleted(Run run, TaskListener listener) {
AbstractBuild build = (AbstractBuild) run;
if (isEligibleJobType(build)) {

if (!(build instanceof MatrixBuild)) {
EnvVars envVars = new EnvVars();
EnvInjectLogger logger = new EnvInjectLogger(listener);
if (!(run instanceof AbstractBuild)) {
return;
}

EnvInjectPluginAction envInjectAction = run.getAction(EnvInjectPluginAction.class);
if (envInjectAction != null) {
AbstractBuild build = (AbstractBuild) run;
if (!isEligibleJobType(build)) {
return;
}

//Remove technical wrappers
try {
BuildWrapperService wrapperService = new BuildWrapperService();
wrapperService.removeBuildWrappers(build, JobSetupEnvironmentWrapper.class);
} catch (EnvInjectException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}
if (!(build instanceof MatrixBuild)) {
EnvVars envVars = new EnvVars();
EnvInjectLogger logger = new EnvInjectLogger(listener);

} else {
//Keep classic injected env vars
AbstractBuild abstractBuild = (AbstractBuild) run;
try {
envVars.putAll(abstractBuild.getEnvironment(listener));
} catch (IOException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (InterruptedException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}
}

//Mask passwords
EnvInjectPasswordsMasker passwordsMasker = new EnvInjectPasswordsMasker();
passwordsMasker.maskPasswordsIfAny(build, logger, envVars);
EnvInjectPluginAction envInjectAction = run.getAction(EnvInjectPluginAction.class);
if (envInjectAction != null) {

//Add or override EnvInject Action
EnvInjectActionSetter envInjectActionSetter = new EnvInjectActionSetter(getNodeRootPath());
//Remove technical wrappers
try {
envInjectActionSetter.addEnvVarsToEnvInjectBuildAction((AbstractBuild<?, ?>) run, envVars);
BuildWrapperService wrapperService = new BuildWrapperService();
wrapperService.removeBuildWrappers(build, JobSetupEnvironmentWrapper.class);
} catch (EnvInjectException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}
} else {
try {
envVars.putAll(build.getEnvironment(listener));
} catch (IOException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
@@ -400,6 +384,25 @@ public void onCompleted(Run run, TaskListener listener) {
throw new Run.RunnerAbortedException();
}
}

//Mask passwords
EnvInjectPasswordsMasker passwordsMasker = new EnvInjectPasswordsMasker();
passwordsMasker.maskPasswordsIfAny(build, logger, envVars);

//Add or override EnvInject Action
EnvInjectActionSetter envInjectActionSetter = new EnvInjectActionSetter(getNodeRootPath());
try {
envInjectActionSetter.addEnvVarsToEnvInjectBuildAction((AbstractBuild<?, ?>) run, envVars);
} catch (EnvInjectException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (IOException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (InterruptedException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}
}
}

0 comments on commit 1f0b603

Please sign in to comment.