Search in sources :

Example 16 with NodeJSInstallation

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())));
    }
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) ConfigFile(org.jenkinsci.lib.configprovider.model.ConfigFile) Node(hudson.model.Node) Computer(hudson.model.Computer) IOException(java.io.IOException) AbortException(hudson.AbortException)

Example 17 with NodeJSInstallation

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();
    }
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) DescriptorImpl(jenkins.plugins.nodejs.tools.NodeJSInstallation.DescriptorImpl)

Aggregations

NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)17 Test (org.junit.Test)11 FreeStyleProject (hudson.model.FreeStyleProject)10 EnvVars (hudson.EnvVars)9 Launcher (hudson.Launcher)7 Node (hudson.model.Node)7 TaskListener (hudson.model.TaskListener)7 NPMConfig (jenkins.plugins.nodejs.configfiles.NPMConfig)5 IOException (java.io.IOException)4 FilePath (hudson.FilePath)3 Config (org.jenkinsci.lib.configprovider.model.Config)3 Issue (org.jvnet.hudson.test.Issue)3 AbortException (hudson.AbortException)2 File (java.io.File)2 Verifier (jenkins.plugins.nodejs.CIBuilderHelper.Verifier)2 EnvVarVerifier (jenkins.plugins.nodejs.VerifyEnvVariableBuilder.EnvVarVerifier)2 DetectionFailedException (jenkins.plugins.nodejs.tools.DetectionFailedException)2 ConfigFile (org.jenkinsci.lib.configprovider.model.ConfigFile)2 Computer (hudson.model.Computer)1 InstallSourceProperty (hudson.tools.InstallSourceProperty)1