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()));
}
}
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;
}
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;
}
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());
}
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());
}
Aggregations