mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
Added another decorator.
This allows us to pass in a proper Launcher that handles all the environment variables without asking individual user to fill in a proper environment variables
This commit is contained in:
1 parent
ba23c8b555
commit
f5cebdc843
1 file changed
+47
@@ -51,6 +51,7 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -690,6 +691,52 @@ public abstract class Launcher {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a decorated {@link Launcher} that automatically adds the specified environment
|
||||
* variables.
|
||||
*
|
||||
* Those that are specified in {@link ProcStarter#envs(String...)} will take precedence over
|
||||
* what's specified here.
|
||||
*
|
||||
* @since 1.488
|
||||
*/
|
||||
public final Launcher decorateByEnv(EnvVars _env) {
|
||||
final EnvVars env = new EnvVars(_env);
|
||||
final Launcher outer = this;
|
||||
return new Launcher(outer) {
|
||||
@Override
|
||||
public Proc launch(ProcStarter starter) throws IOException {
|
||||
EnvVars e = new EnvVars(env);
|
||||
if (starter.envs!=null) {
|
||||
for (int i=0; i<starter.envs.length; i+=2)
|
||||
e.put(starter.envs[i],starter.envs[i+1]);
|
||||
}
|
||||
|
||||
String[] r = new String[e.size()*2];
|
||||
int idx=0;
|
||||
for (Entry<String, String> i : e.entrySet()) {
|
||||
r[idx++] = i.getKey();
|
||||
r[idx++] = i.getValue();
|
||||
}
|
||||
|
||||
starter.envs = r;
|
||||
return outer.launch(starter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) throws IOException, InterruptedException {
|
||||
EnvVars e = new EnvVars(env);
|
||||
e.putAll(envVars);
|
||||
return outer.launchChannel(cmd,out,workDir,e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kill(Map<String, String> modelEnvVars) throws IOException, InterruptedException {
|
||||
outer.kill(modelEnvVars);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Launcher} that launches process locally.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user