Skip to content
Permalink
Browse files

Fix JENKINS-13167

  • Loading branch information
gboissinot committed Mar 21, 2012
1 parent c23ed21 commit bd3910e8513e6ebc8eadd13a3ff38463b5057637
Showing with 28 additions and 7 deletions.
  1. +9 −1 pom.xml
  2. +19 −6 src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
10 pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

@@ -47,11 +48,18 @@
</scm>

<dependencies>

<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
</dependency>

<dependency>
<groupId>org.jenkins-ci.lib</groupId>
<artifactId>envinject-lib</artifactId>
<version>${envinject.lib.version}</version>
</dependency>

</dependencies>

</project>
@@ -6,6 +6,7 @@
import hudson.Launcher;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.*;
import hudson.model.listeners.RunListener;
import hudson.remoting.Callable;
@@ -123,16 +124,21 @@ private void loadEnvironmentVariablesNode(AbstractBuild build, Node buildNode, B
}

@SuppressWarnings("unchecked")
private void addBuildWrapper(AbstractBuild build, BuildWrapper buildWrapper) throws EnvInjectException {
private void addBuildWrapper(AbstractBuild build, BuildWrapper buildWrapper, EnvInjectLogger logger) throws EnvInjectException {
try {
if (buildWrapper != null) {
AbstractProject abstractProject = build.getProject();
if (abstractProject instanceof MatrixProject) {
MatrixProject project = (MatrixProject) abstractProject;
project.getBuildWrappersList().add(buildWrapper);
} else {
} else if (abstractProject instanceof FreeStyleProject) {
Project project = (Project) abstractProject;
project.getBuildWrappersList().add(buildWrapper);
} else if (abstractProject instanceof MavenModuleSet) {
MavenModuleSet moduleSet = (MavenModuleSet) abstractProject;
moduleSet.getBuildWrappersList().add(buildWrapper);
} else {
logger.error(String.format("Job type %s is not supported by the EnvInject plugin.", abstractProject));
}
}
} catch (IOException ioe) {
@@ -272,6 +278,8 @@ private Environment setUpEnvironmentJobPropertyObject(AbstractBuild build, Launc
//Add an action
new EnvInjectActionSetter(rootPath).addEnvVarsToEnvInjectBuildAction(build, resultVariables);

addBuildWrapper(build, new JobSetupEnvironmentWrapper(), logger);

return new Environment() {
@Override
public void buildEnvVars(Map<String, String> env) {
@@ -329,7 +337,7 @@ private void injectPasswords(AbstractBuild build, EnvInjectJobProperty envInject
}
//--Inject passwords
if (passwordList.size() != 0) {
addBuildWrapper(build, new EnvInjectPasswordWrapper(passwordList));
addBuildWrapper(build, new EnvInjectPasswordWrapper(passwordList), logger);
}

}
@@ -377,7 +385,7 @@ public void onCompleted(Run run, TaskListener listener) {

//Remove technical wrappers
try {
removeTechnicalWrappers(build, JobSetupEnvironmentWrapper.class, EnvInjectPasswordWrapper.class);
removeTechnicalBuildWrappers(build, JobSetupEnvironmentWrapper.class, EnvInjectPasswordWrapper.class);
} catch (EnvInjectException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
@@ -418,16 +426,21 @@ public void onCompleted(Run run, TaskListener listener) {
}

@SuppressWarnings("unchecked")
private void removeTechnicalWrappers(AbstractBuild build, Class<JobSetupEnvironmentWrapper> jobSetupEnvironmentWrapperClass, Class<EnvInjectPasswordWrapper> envInjectPasswordWrapperClass) throws EnvInjectException {
private void removeTechnicalBuildWrappers(AbstractBuild build, Class<JobSetupEnvironmentWrapper> jobSetupEnvironmentWrapperClass, Class<EnvInjectPasswordWrapper> envInjectPasswordWrapperClass) throws EnvInjectException {

AbstractProject abstractProject = build.getProject();
DescribableList<BuildWrapper, Descriptor<BuildWrapper>> wrappersProject;
if (abstractProject instanceof MatrixProject) {
MatrixProject project = (MatrixProject) abstractProject;
wrappersProject = project.getBuildWrappersList();
} else {
} else if (abstractProject instanceof FreeStyleProject) {
Project project = (Project) abstractProject;
wrappersProject = project.getBuildWrappersList();
} else if (abstractProject instanceof MavenModuleSet) {
MavenModuleSet moduleSet = (MavenModuleSet) abstractProject;
wrappersProject = moduleSet.getBuildWrappersList();
} else {
throw new EnvInjectException(String.format("Job type %s is not supported", abstractProject));
}

Iterator<BuildWrapper> iterator = wrappersProject.iterator();

0 comments on commit bd3910e

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