use of jenkins.plugins.nodejs.tools.NodeJSInstallation 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());
// configure cache location
FilePath cacheLocation = cacheLocationStrategy.locate(workspace);
if (cacheLocation != null) {
context.env(NodeJSConstants.NPM_CACHE_LOCATION, cacheLocation.getRemote());
}
// 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());
context.setDisposer(new TempFileCleaner(Arrays.asList(configFile.getRemote())));
}
}
use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.
the class NodeJSPlugin method setInstallations.
/**
* Set the NodeJS installation.
*
* @param installations an array of {@link NodeJSInstallation}
* @deprecated You should not set manually system NodeJS installation, in
* case use the standard
* {@link Jenkins#getDescriptorByType(Class)
* #setInstallations(NodeJSInstallation[])}
*/
@Deprecated
public void setInstallations(@NonNull NodeJSInstallation[] installations) {
DescriptorImpl descriptor = Jenkins.getActiveInstance().getDescriptorByType(NodeJSInstallation.DescriptorImpl.class);
if (descriptor != null) {
descriptor.setInstallations(installations != null ? installations : new NodeJSInstallation[0]);
descriptor.save();
}
}
Aggregations