use of hudson.EnvVars in project nodejs-plugin by jenkinsci.
the class NodeJSInstallationMockitoTest method test_installer_environment.
/**
* Ensure the use of {@link EnvVars#put(String, String)} instead
* {@code EnvVars#override(String, String)} to respect the
* {@link ToolInstallation#buildEnvVars(EnvVars)) API documentation.
* <p>
* A lot stuff rely on that logic.
*/
@Issue("JENKINS-41947")
@Test
public void test_installer_environment() throws Exception {
String nodeJSHome = "/home/nodejs";
String bin = nodeJSHome + "/bin";
NodeJSInstallation installer = PowerMockito.spy(new NodeJSInstallation("test", nodeJSHome, null));
PowerMockito.doReturn(bin).when(installer, "getBin");
EnvVars env = PowerMockito.spy(new EnvVars());
installer.buildEnvVars(env);
Mockito.verify(env, Mockito.never()).override(Mockito.anyString(), Mockito.anyString());
Mockito.verify(env, Mockito.never()).overrideAll(Mockito.<String, String>anyMap());
assertEquals("Unexpected value for " + ENVVAR_NODEJS_HOME, nodeJSHome, env.get(ENVVAR_NODEJS_HOME));
assertEquals("Unexpected value for " + ENVVAR_NODEJS_PATH, bin, env.get(ENVVAR_NODEJS_PATH));
assertNull("PATH variable should not appear in this environment", env.get("PATH"));
}
use of hudson.EnvVars in project nodejs-plugin by jenkinsci.
the class NodeJSCommandInterpreterTest method test_inject_path_variable.
@Issue("JENKINS-41947")
@Test
public void test_inject_path_variable() throws Exception {
NodeJSInstallation installation = mockInstaller();
NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_executable_value", installation, null, new CIBuilderHelper.Verifier() {
@Override
public void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception {
assertFalse("No Environments", build.getEnvironments().isEmpty());
EnvVars env = build.getEnvironment(listener);
assertThat(env.keySet(), CoreMatchers.hasItems(NodeJSConstants.ENVVAR_NODEJS_PATH, NodeJSConstants.ENVVAR_NODEJS_HOME));
assertEquals(getTestHome(), env.get(NodeJSConstants.ENVVAR_NODEJS_HOME));
assertEquals(getTestBin(), env.get(NodeJSConstants.ENVVAR_NODEJS_PATH));
}
});
FreeStyleProject job = j.createFreeStyleProject();
job.getBuildersList().add(builder);
j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
use of hudson.EnvVars 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 hudson.EnvVars in project nodejs-plugin by jenkinsci.
the class VerifyEnvVariableBuilder method perform.
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
EnvVars env = build.getEnvironment(listener);
verify(env);
return true;
}
use of hudson.EnvVars in project nodejs-plugin by jenkinsci.
the class NodeJSInstaller method refreshGlobalPackages.
/*
* Installing npm packages if needed
*/
protected void refreshGlobalPackages(Node node, TaskListener log, FilePath expected) throws IOException, InterruptedException {
String globalPackages = getNpmPackages();
if (StringUtils.isNotBlank(globalPackages)) {
// JENKINS-41876
boolean skipNpmPackageInstallation = areNpmPackagesUpToDate(expected, globalPackages, getNpmPackagesRefreshHours());
if (!skipNpmPackageInstallation) {
expected.child(NPM_PACKAGES_RECORD_FILENAME).delete();
ArgumentListBuilder npmScriptArgs = new ArgumentListBuilder();
if (platform == Platform.WINDOWS) {
npmScriptArgs.add("cmd");
npmScriptArgs.add("/c");
}
FilePath binFolder = expected.child(platform.binFolder);
FilePath npmExe = binFolder.child(platform.npmFileName);
npmScriptArgs.add(npmExe);
npmScriptArgs.add("install");
npmScriptArgs.add("-g");
for (String packageName : globalPackages.split("\\s")) {
npmScriptArgs.add(packageName);
}
EnvVars env = new EnvVars();
env.put(NodeJSConstants.ENVVAR_NODEJS_PATH, binFolder.getRemote());
try {
buildProxyEnvVars(env, log);
} catch (URISyntaxException e) {
log.error("Wrong proxy URL: " + e.getMessage());
}
hudson.Launcher launcher = node.createLauncher(log);
int returnCode = launcher.launch().envs(env).cmds(npmScriptArgs).stdout(log).join();
if (returnCode == 0) {
// leave a record for the next up-to-date check
expected.child(NPM_PACKAGES_RECORD_FILENAME).write(globalPackages, "UTF-8");
expected.child(NPM_PACKAGES_RECORD_FILENAME).act(new ChmodRecAPlusX());
}
}
}
}
Aggregations