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();
}
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);
}
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));
}
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));
}
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());
}
Aggregations