Search in sources :

Example 41 with EnvVars

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

the class NodeJSBuildWrapper method setUp.

/*
     * (non-Javadoc)
     * @see jenkins.tasks.SimpleBuildWrapper#setUp(jenkins.tasks.SimpleBuildWrapper.Context, hudson.model.Run, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener, hudson.EnvVars)
     */
@Override
public void setUp(final Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException {
    // get specific installation for the node
    NodeJSInstallation ni = getNodeJS();
    if (ni == null) {
        throw new IOException(Messages.NodeJSBuilders_noInstallationFound(nodeJSInstallationName));
    }
    Computer computer = workspace.toComputer();
    if (computer == null) {
        throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
    }
    Node node = computer.getNode();
    if (node == null) {
        throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
    }
    ni = ni.forNode(node, listener);
    ni = ni.forEnvironment(initialEnvironment);
    String exec = ni.getExecutable(launcher);
    if (exec == null) {
        throw new AbortException(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
    }
    ni.buildEnvVars(new EnvVarsAdapter(context));
    EnvVars env = initialEnvironment.overrideAll(context.getEnv());
    // add npmrc config
    if (configId != null) {
        ConfigFile cf = new ConfigFile(configId, null, true);
        FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, workspace, listener, new ArrayList<String>());
        context.env(NodeJSConstants.NPM_USERCONFIG, configFile.getRemote());
        build.addAction(new CleanTempFilesAction(configFile.getRemote()));
    }
}
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) Computer(hudson.model.Computer) IOException(java.io.IOException) AbortException(hudson.AbortException)

Example 42 with EnvVars

use of hudson.EnvVars in project jenkins-client-plugin by openshift.

the class BaseStep method consolidateEnvVars.

// borrowed from openshift pipeline plugin
protected Map<String, String> consolidateEnvVars(TaskListener listener, AbstractBuild<?, ?> build, Launcher launcher) {
    // EnvVars extends TreeMap
    TreeMap<String, String> overrides = new TreeMap<String, String>();
    // merge from all potential sources
    if (build != null) {
        try {
            EnvVars buildEnv = build.getEnvironment(listener);
            if (isVerbose())
                listener.getLogger().println("build env vars:  " + buildEnv);
            overrides.putAll(buildEnv);
        } catch (IOException | InterruptedException e) {
            if (isVerbose())
                e.printStackTrace(listener.getLogger());
        }
    }
    try {
        EnvVars computerEnv = null;
        Computer computer = Computer.currentComputer();
        if (computer != null) {
            computerEnv = computer.getEnvironment();
        } else {
            if (launcher != null)
                computer = launcher.getComputer();
            if (computer != null) {
                computerEnv = computer.getEnvironment();
            }
        }
        if (isVerbose())
            listener.getLogger().println("computer env vars:  " + computerEnv);
        if (computerEnv != null)
            overrides.putAll(computerEnv);
    } catch (IOException | InterruptedException e2) {
        if (isVerbose())
            e2.printStackTrace(listener.getLogger());
    }
    return overrides;
}
Also used : EnvVars(hudson.EnvVars) Computer(hudson.model.Computer) IOException(java.io.IOException) TreeMap(java.util.TreeMap)

Example 43 with EnvVars

use of hudson.EnvVars in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfigurator method describe.

@Override
public Set<Attribute> describe() {
    final Set<Attribute> attributes = super.describe();
    final Jenkins jenkins = Jenkins.getInstance();
    attributes.add(new PersistedListAttribute<Cloud>("clouds", jenkins.clouds, Cloud.class));
    attributes.add(new Attribute<String>("jobs", String.class).multiple(true).setter((target, attribute, value) -> {
        JenkinsJobManagement mng = new JenkinsJobManagement(System.out, new EnvVars(), null, null, LookupStrategy.JENKINS_ROOT);
        for (String script : (List<String>) value) {
            new JenkinsDslScriptLoader(mng).runScript(script);
        }
    }));
    // Check for unclassified Descriptors
    final ExtensionList<Descriptor> descriptors = jenkins.getExtensionList(Descriptor.class);
    for (Descriptor descriptor : descriptors) {
        if (descriptor.getGlobalConfigPage() != null && descriptor.getCategory() instanceof GlobalConfigurationCategory.Unclassified) {
            final DescriptorConfigurator configurator = new DescriptorConfigurator(descriptor);
            attributes.add(new Attribute(configurator.getName(), configurator.getTarget()).setter(NOOP));
        }
    }
    // Add remoting security, all legwork will be done by a configurator
    attributes.add(new Attribute("remotingSecurity", AdminWhitelistRule.class).setter(NOOP));
    return attributes;
}
Also used : JenkinsDslScriptLoader(javaposse.jobdsl.plugin.JenkinsDslScriptLoader) JenkinsJobManagement(javaposse.jobdsl.plugin.JenkinsJobManagement) Descriptor(hudson.model.Descriptor) Jenkins(jenkins.model.Jenkins) AdminWhitelistRule(jenkins.security.s2m.AdminWhitelistRule) Set(java.util.Set) Logger(java.util.logging.Logger) Level(java.util.logging.Level) List(java.util.List) Map(java.util.Map) Extension(hudson.Extension) LookupStrategy(javaposse.jobdsl.plugin.LookupStrategy) EnvVars(hudson.EnvVars) Cloud(hudson.slaves.Cloud) ExtensionList(hudson.ExtensionList) GlobalConfigurationCategory(jenkins.model.GlobalConfigurationCategory) JenkinsJobManagement(javaposse.jobdsl.plugin.JenkinsJobManagement) JenkinsDslScriptLoader(javaposse.jobdsl.plugin.JenkinsDslScriptLoader) Jenkins(jenkins.model.Jenkins) EnvVars(hudson.EnvVars) Cloud(hudson.slaves.Cloud) Descriptor(hudson.model.Descriptor) GlobalConfigurationCategory(jenkins.model.GlobalConfigurationCategory)

Example 44 with EnvVars

use of hudson.EnvVars in project pipeline-aws-plugin by jenkinsci.

the class ProxyTest method shouldParseProxy.

@Test
public void shouldParseProxy() throws Exception {
    EnvVars vars = new EnvVars();
    vars.put(ProxyConfiguration.HTTPS_PROXY, "http://127.0.0.1:8888/");
    ClientConfiguration config = new ClientConfiguration();
    config.setProtocol(Protocol.HTTPS);
    ProxyConfiguration.configure(vars, config);
    Assert.assertNull(config.getProxyUsername());
    Assert.assertNull(config.getProxyPassword());
    Assert.assertEquals("127.0.0.1", config.getProxyHost());
    Assert.assertEquals(8888, config.getProxyPort());
}
Also used : EnvVars(hudson.EnvVars) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Example 45 with EnvVars

use of hudson.EnvVars in project pipeline-aws-plugin by jenkinsci.

the class ProxyTest method shouldParseProxyWithAuth.

@Test
public void shouldParseProxyWithAuth() throws Exception {
    EnvVars vars = new EnvVars();
    vars.put(ProxyConfiguration.HTTPS_PROXY, "http://foo:bar@127.0.0.1:8888/");
    ClientConfiguration config = new ClientConfiguration();
    config.setProtocol(Protocol.HTTPS);
    ProxyConfiguration.configure(vars, config);
    Assert.assertEquals("foo", config.getProxyUsername());
    Assert.assertEquals("bar", config.getProxyPassword());
    Assert.assertEquals("127.0.0.1", config.getProxyHost());
    Assert.assertEquals(8888, config.getProxyPort());
}
Also used : EnvVars(hudson.EnvVars) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

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