Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98dcefd
commit efb96d7
Showing
5 changed files
with
116 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,6 @@ public int executeScriptSection(FilePath scriptExecutionRoot, | |
|
||
} | ||
|
||
|
||
return 0; | ||
} | ||
|
||
|
81 changes: 81 additions & 0 deletions
81
src/main/java/org/jenkinsci/plugins/envinject/service/EnvironmentVariablesNodeLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.jenkinsci.plugins.envinject.service; | ||
|
||
import hudson.EnvVars; | ||
import hudson.FilePath; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Hudson; | ||
import hudson.model.Node; | ||
import hudson.remoting.Callable; | ||
import hudson.slaves.EnvironmentVariablesNodeProperty; | ||
import hudson.slaves.NodeProperty; | ||
import org.jenkinsci.lib.envinject.EnvInjectException; | ||
import org.jenkinsci.lib.envinject.EnvInjectLogger; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Gregory Boissinot | ||
*/ | ||
public class EnvironmentVariablesNodeLoader implements Serializable { | ||
|
||
public Map<String, String> gatherEnvironmentVariablesNode(AbstractBuild build, Node buildNode, EnvInjectLogger logger) throws EnvInjectException { | ||
|
||
logger.info("Loading node environment variables."); | ||
|
||
if (buildNode == null) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
FilePath nodePath = buildNode.getRootPath(); | ||
if (nodePath == null) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
//Default node envVars | ||
Map<String, String> configNodeEnvVars = new HashMap<String, String>(); | ||
|
||
try { | ||
|
||
//Get env vars for the current node | ||
Map<String, String> nodeEnvVars = nodePath.act( | ||
new Callable<Map<String, String>, IOException>() { | ||
public Map<String, String> call() throws IOException { | ||
return EnvVars.masterEnvVars; | ||
} | ||
} | ||
); | ||
|
||
for (NodeProperty<?> nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) { | ||
if (nodeProperty instanceof EnvironmentVariablesNodeProperty) { | ||
EnvironmentVariablesNodeProperty variablesNodeProperty = (EnvironmentVariablesNodeProperty) nodeProperty; | ||
EnvVars envVars = variablesNodeProperty.getEnvVars(); | ||
EnvInjectEnvVars envInjectEnvVars = new EnvInjectEnvVars(logger); | ||
configNodeEnvVars.putAll(envVars); | ||
envInjectEnvVars.resolveVars(configNodeEnvVars, nodeEnvVars); | ||
} | ||
} | ||
|
||
for (NodeProperty<?> nodeProperty : buildNode.getNodeProperties()) { | ||
if (nodeProperty instanceof EnvironmentVariablesNodeProperty) { | ||
EnvironmentVariablesNodeProperty variablesNodeProperty = (EnvironmentVariablesNodeProperty) nodeProperty; | ||
EnvVars envVars = variablesNodeProperty.getEnvVars(); | ||
EnvInjectEnvVars envInjectEnvVars = new EnvInjectEnvVars(logger); | ||
configNodeEnvVars.putAll(envVars); | ||
envInjectEnvVars.resolveVars(configNodeEnvVars, nodeEnvVars); | ||
} | ||
} | ||
|
||
return configNodeEnvVars; | ||
|
||
} catch (IOException ioe) { | ||
throw new EnvInjectException(ioe); | ||
} catch (InterruptedException ie) { | ||
throw new EnvInjectException(ie); | ||
} | ||
} | ||
|
||
} |