use of hudson.EnvVars in project nodejs-plugin by jenkinsci.
the class NodeJSInstaller method refreshGlobalPackages.
/*
* Installing npm packages if needed
*/
protected void refreshGlobalPackages(Node node, TaskListener log, FilePath expected) throws IOException, InterruptedException {
String globalPackages = getNpmPackages();
if (StringUtils.isNotBlank(globalPackages)) {
// JENKINS-41876
boolean skipNpmPackageInstallation = areNpmPackagesUpToDate(expected, globalPackages, getNpmPackagesRefreshHours());
if (!skipNpmPackageInstallation) {
expected.child(NPM_PACKAGES_RECORD_FILENAME).delete();
ArgumentListBuilder npmScriptArgs = new ArgumentListBuilder();
if (platform == Platform.WINDOWS) {
npmScriptArgs.add("cmd");
npmScriptArgs.add("/c");
}
FilePath binFolder = expected.child(platform.binFolder);
FilePath npmExe = binFolder.child(platform.npmFileName);
npmScriptArgs.add(npmExe);
npmScriptArgs.add("install");
npmScriptArgs.add("-g");
for (String packageName : globalPackages.split("\\s")) {
npmScriptArgs.add(packageName);
}
EnvVars env = new EnvVars();
env.put(NodeJSConstants.ENVVAR_NODEJS_PATH, binFolder.getRemote());
try {
buildProxyEnvVars(env, log);
} catch (URISyntaxException e) {
log.error("Wrong proxy URL: " + e.getMessage());
}
hudson.Launcher launcher = node.createLauncher(log);
int returnCode = launcher.launch().envs(env).cmds(npmScriptArgs).stdout(log).join();
if (returnCode == 0) {
// leave a record for the next up-to-date check
expected.child(NPM_PACKAGES_RECORD_FILENAME).write(globalPackages, "UTF-8");
expected.child(NPM_PACKAGES_RECORD_FILENAME).act(new ChmodRecAPlusX());
}
}
}
}
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 htmlpublisher-plugin by jenkinsci.
the class HtmlPublisherIntegrationTest method addEnvironmentVariable.
private void addEnvironmentVariable(String key, String value) {
EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty();
EnvVars envVars = prop.getEnvVars();
envVars.put(key, value);
j.jenkins.getGlobalNodeProperties().add(prop);
}
Aggregations