下面列出了怎么用hudson.model.EnvironmentContributor的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Return all job related vars without executor vars.
* I.e. slave is running in osx, but docker image for shell is linux.
*/
protected static EnvVars getEnvVars(Run run, TaskListener listener) throws IOException, InterruptedException {
final EnvVars envVars = run.getCharacteristicEnvVars();
// from run.getEnvironment(listener) but without computer vars
for (EnvironmentContributor ec : EnvironmentContributor.all().reverseView()) {
// job vars
ec.buildEnvironmentFor(run.getParent(), envVars, listener);
// build vars
if (ec instanceof CoreEnvironmentContributor) {
// exclude executor computer related vars
envVars.put("BUILD_DISPLAY_NAME", run.getDisplayName());
String rootUrl = Jenkins.getInstance().getRootUrl();
if (rootUrl != null) {
envVars.put("BUILD_URL", rootUrl + run.getUrl());
}
// and remove useless job var from CoreEnvironmentContributor
envVars.remove("JENKINS_HOME");
envVars.remove("HUDSON_HOME");
} else {
ec.buildEnvironmentFor(run, envVars, listener); // build vars
}
}
return envVars;
}