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