hudson.model.EnvironmentContributor Java Examples

The following examples show how to use hudson.model.EnvironmentContributor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerShellStep.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
/**
 * 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;
}