Search in sources :

Example 6 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class SimpleNodeJSCommandInterpreterTest method setUp.

@Before
public void setUp() {
    installation = new NodeJSInstallation("11.0.0", "", Collections.<ToolProperty<?>>emptyList());
    interpreter = new NodeJSCommandInterpreter(COMMAND, installation.getName(), null);
    descriptor = new NodeJSCommandInterpreter.NodeJsDescriptor();
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) ToolProperty(hudson.tools.ToolProperty) Before(org.junit.Before)

Example 7 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation 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()));
            }
        }
        FilePath workspace = build.getWorkspace();
        if (workspace != null) {
            // configure cache location
            FilePath cacheLocation = getCacheLocationStrategy().locate(workspace);
            if (cacheLocation != null) {
                newEnv.put(NodeJSConstants.NPM_CACHE_LOCATION, cacheLocation.getRemote());
            }
        }
        if (configId != null) {
            // add npmrc config
            ConfigFile cf = new ConfigFile(configId, null, true);
            FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, workspace, 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(Messages.NodeJSCommandInterpreter_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 8 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreterTest method test_calls_sequence_of_installer.

@Test
public void test_calls_sequence_of_installer() throws Exception {
    NodeJSInstallation installation = mockInstaller();
    NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_creation_of_config", installation, null);
    FreeStyleProject job = j.createFreeStyleProject("free");
    job.getBuildersList().add(builder);
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
    verify(installation).forNode(any(Node.class), any(TaskListener.class));
    verify(installation).forEnvironment(any(EnvVars.class));
    verify(installation).buildEnvVars(any(EnvVars.class));
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) EnvVars(hudson.EnvVars) Node(hudson.model.Node) TaskListener(hudson.model.TaskListener) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 9 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreterTest method test_creation_of_config.

@Test
public void test_creation_of_config() throws Exception {
    Config config = createSetting("my-config-id", "email=foo@acme.com", null);
    NodeJSInstallation installation = mockInstaller();
    NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_creation_of_config", installation, config.id, new Verifier() {

        @Override
        public void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception {
            EnvVars env = build.getEnvironment(listener);
            String var = NodeJSConstants.NPM_USERCONFIG;
            String value = env.get(var);
            assertTrue("variable " + var + " not set", env.containsKey(var));
            assertNotNull("empty value for environment variable " + var, value);
            assertTrue("file of variable " + var + " does not exists or is not a file", new File(value).isFile());
        }
    });
    FreeStyleProject job = j.createFreeStyleProject();
    job.getBuildersList().add(builder);
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
Also used : Config(org.jenkinsci.lib.configprovider.model.Config) NPMConfig(jenkins.plugins.nodejs.configfiles.NPMConfig) Verifier(jenkins.plugins.nodejs.CIBuilderHelper.Verifier) EnvVarVerifier(jenkins.plugins.nodejs.VerifyEnvVariableBuilder.EnvVarVerifier) FreeStyleProject(hudson.model.FreeStyleProject) IOException(java.io.IOException) DetectionFailedException(jenkins.plugins.nodejs.tools.DetectionFailedException) NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) EnvVars(hudson.EnvVars) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher) File(java.io.File) Test(org.junit.Test)

Example 10 with NodeJSInstallation

use of jenkins.plugins.nodejs.tools.NodeJSInstallation in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreterTest method test_executable_value.

@Test
public void test_executable_value() throws Exception {
    NodeJSInstallation installation = mockInstaller();
    NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_executable_value", installation, null);
    FreeStyleProject job = j.createFreeStyleProject();
    job.getBuildersList().add(builder);
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
    String[] buildCommandLine = builder.buildCommandLine(new FilePath(folder.newFile()));
    assertEquals(buildCommandLine[0], getTestExecutable());
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) FilePath(hudson.FilePath) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

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