Search in sources :

Example 11 with EnvVars

use of hudson.EnvVars in project vsphere-cloud-plugin by jenkinsci.

the class vSphereCloudSlaveTemplate method calculateVariablesForGuestInfo.

private EnvVars calculateVariablesForGuestInfo(final String cloneName, final TaskListener listener) throws IOException, InterruptedException {
    final EnvVars knownVariables = new EnvVars();
    // Maintenance note: If you update this method, you must also update the
    // UI help page to match.
    final String jenkinsUrl = Jenkins.getActiveInstance().getRootUrl();
    if (jenkinsUrl != null) {
        addEnvVar(knownVariables, "JENKINS_URL", jenkinsUrl);
        addEnvVar(knownVariables, "HUDSON_URL", jenkinsUrl);
    }
    final String slaveSecret = JnlpSlaveAgentProtocol.SLAVE_SECRET.mac(cloneName);
    if (slaveSecret != null) {
        addEnvVar(knownVariables, "JNLP_SECRET", slaveSecret);
    }
    addEnvVars(knownVariables, listener, Jenkins.getInstance().getGlobalNodeProperties());
    addEnvVars(knownVariables, listener, this.nodeProperties);
    addEnvVar(knownVariables, "NODE_NAME", cloneName);
    addEnvVar(knownVariables, "NODE_LABELS", getLabelSet() == null ? null : Util.join(getLabelSet(), " "));
    addEnvVar(knownVariables, "cluster", this.cluster);
    addEnvVar(knownVariables, "datastore", this.datastore);
    addEnvVar(knownVariables, "folder", this.folder);
    addEnvVar(knownVariables, "customizationSpec", this.customizationSpec);
    addEnvVar(knownVariables, "labelString", this.labelString);
    addEnvVar(knownVariables, "masterImageName", this.masterImageName);
    addEnvVar(knownVariables, "remoteFS", this.remoteFS);
    addEnvVar(knownVariables, "snapshotName", this.snapshotName);
    addEnvVar(knownVariables, "targetHost", this.targetHost);
    addEnvVar(knownVariables, "templateDescription", this.templateDescription);
    return knownVariables;
}
Also used : EnvVars(hudson.EnvVars)

Example 12 with EnvVars

use of hudson.EnvVars in project vsphere-cloud-plugin by jenkinsci.

the class vSphereCloudSlaveTemplate method calculateExtraConfigParameters.

private Map<String, String> calculateExtraConfigParameters(final String cloneName, final TaskListener listener) throws IOException, InterruptedException {
    final EnvVars knownVariables = calculateVariablesForGuestInfo(cloneName, listener);
    final Map<String, String> result = new LinkedHashMap<String, String>();
    final String jenkinsUrl = Jenkins.getActiveInstance().getRootUrl();
    if (jenkinsUrl != null) {
        result.put(VSPHERE_ATTR_FOR_JENKINSURL, jenkinsUrl);
    }
    List<? extends VSphereGuestInfoProperty> guestInfoConfig = this.guestInfoProperties;
    if (guestInfoConfig == null) {
        guestInfoConfig = Collections.emptyList();
    }
    for (final VSphereGuestInfoProperty property : guestInfoConfig) {
        final String name = property.getName();
        final String configuredValue = property.getValue();
        final String resolvedValue = Util.replaceMacro(configuredValue, knownVariables);
        result.put("guestinfo." + name, resolvedValue);
    }
    return result;
}
Also used : EnvVars(hudson.EnvVars) VSphereGuestInfoProperty(org.jenkinsci.plugins.vsphere.VSphereGuestInfoProperty) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with EnvVars

use of hudson.EnvVars in project nodejs-plugin by jenkinsci.

the class NodeJSInstallerProxyTest method test_proxy_settings.

@Issue("JENKINS-29266")
@Test
public void test_proxy_settings() throws Exception {
    r.getInstance().proxy = new ProxyConfiguration(host, port, username, password);
    NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS);
    EnvVars env = new EnvVars();
    Whitebox.invokeMethod(installer, "buildProxyEnvVars", env, log);
    assertThat(env.keySet(), hasItems("HTTP_PROXY", "HTTPS_PROXY"));
    assertThat(env.get("HTTP_PROXY"), is(expectedURL));
    assertThat(env.get("HTTPS_PROXY"), is(expectedURL));
    assertThat(env.keySet(), not(hasItem("NO_PROXY")));
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) EnvVars(hudson.EnvVars) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 14 with EnvVars

use of hudson.EnvVars in project nodejs-plugin by jenkinsci.

the class NodeJSInstallerProxyTest method test_no_proxy_settings.

@Test
public void test_no_proxy_settings() throws Exception {
    r.getInstance().proxy = new ProxyConfiguration(host, port, username, password, noProxy);
    NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS);
    EnvVars env = new EnvVars();
    Whitebox.invokeMethod(installer, "buildProxyEnvVars", env, log);
    assertThat(env.keySet(), hasItems("HTTP_PROXY", "HTTPS_PROXY"));
    assertThat(env.get("NO_PROXY"), is("*.npm.org,registry.npm.org"));
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 15 with EnvVars

use of hudson.EnvVars in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreter method perform.

/*
     * (non-Javadoc)
     * @see hudson.tasks.CommandInterpreter#perform(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.TaskListener)
     */
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
    try {
        EnvVars env = build.getEnvironment(listener);
        EnvVars newEnv = new EnvVars();
        // get specific installation for the node
        NodeJSInstallation ni = getNodeJS();
        if (ni == null) {
            if (nodeJSInstallationName != null) {
                throw new AbortException(Messages.NodeJSBuilders_noInstallationFound(nodeJSInstallationName));
            }
            // use system NodeJS if any, in case let fails later
            nodeExec = (launcher.isUnix() ? Platform.LINUX : Platform.WINDOWS).nodeFileName;
        } else {
            Node node = build.getBuiltOn();
            if (node == null) {
                throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
            }
            ni = ni.forNode(node, listener);
            ni = ni.forEnvironment(env);
            String exec = ni.getExecutable(launcher);
            if (exec == null) {
                listener.fatalError(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
                return false;
            }
            ni.buildEnvVars(newEnv);
            // enhance env with installation environment because is passed to supplyConfig
            env.overrideAll(newEnv);
            nodeExec = ni.getExecutable(launcher);
            if (nodeExec == null) {
                throw new AbortException(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
            }
        }
        if (configId != null) {
            // add npmrc config
            ConfigFile cf = new ConfigFile(configId, null, true);
            FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, build.getWorkspace(), listener, new ArrayList<String>());
            newEnv.put(NodeJSConstants.NPM_USERCONFIG, configFile.getRemote());
            build.addAction(new CleanTempFilesAction(configFile.getRemote()));
        }
        // add an Environment so when the in super class is called build.getEnviroment() gets the enhanced env
        build.getEnvironments().add(Environment.create(newEnv));
    } catch (AbortException e) {
        // NOSONAR
        listener.fatalError(e.getMessage());
        return false;
    } catch (IOException e) {
        Util.displayIOException(e, listener);
        e.printStackTrace(listener.fatalError(hudson.tasks.Messages.CommandInterpreter_CommandFailed()));
    }
    return internalPerform(build, launcher, listener);
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) ConfigFile(org.jenkinsci.lib.configprovider.model.ConfigFile) CleanTempFilesAction(org.jenkinsci.plugins.configfiles.common.CleanTempFilesAction) Node(hudson.model.Node) IOException(java.io.IOException) AbortException(hudson.AbortException)

Aggregations

EnvVars (hudson.EnvVars)64 Test (org.junit.Test)23 IOException (java.io.IOException)15 FilePath (hudson.FilePath)11 ClientConfiguration (com.amazonaws.ClientConfiguration)7 ArgumentListBuilder (hudson.util.ArgumentListBuilder)7 TaskListener (hudson.model.TaskListener)6 AbortException (hudson.AbortException)5 HashMap (java.util.HashMap)5 MavenModuleSet (hudson.maven.MavenModuleSet)4 FreeStyleProject (hudson.model.FreeStyleProject)4 ParameterValue (hudson.model.ParameterValue)4 Launcher (hudson.Launcher)3 GitException (hudson.plugins.git.GitException)3 LogTaskListener (hudson.util.LogTaskListener)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)3 ConduitAPIClient (com.uber.jenkins.phabricator.conduit.ConduitAPIClient)2 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)2