Search in sources :

Example 1 with CleanTempFilesAction

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

Example 2 with CleanTempFilesAction

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

Aggregations

AbortException (hudson.AbortException)2 EnvVars (hudson.EnvVars)2 FilePath (hudson.FilePath)2 Node (hudson.model.Node)2 IOException (java.io.IOException)2 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)2 ConfigFile (org.jenkinsci.lib.configprovider.model.ConfigFile)2 CleanTempFilesAction (org.jenkinsci.plugins.configfiles.common.CleanTempFilesAction)2 Computer (hudson.model.Computer)1