use of hudson.Launcher in project htmlpublisher-plugin by jenkinsci.
the class HtmlPublisherIntegrationTest method testVariableExpansion.
@Test
public void testVariableExpansion() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("variable_job");
addEnvironmentVariable("MYREPORTNAME", "reportname");
addEnvironmentVariable("MYREPORTFILES", "afile.html");
addEnvironmentVariable("MYREPORTTITLE", "A Title");
final String reportDir = "autogen";
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath ws = build.getWorkspace().child(reportDir);
ws.child("afile.html").write("hello", "UTF-8");
return true;
}
});
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportname", reportDir, "${MYREPORTFILES}", true, true, false);
target2.setReportTitles("${MYREPORTTITLE}");
List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target2);
p.getPublishersList().add(new HtmlPublisher(targets));
AbstractBuild build = j.buildAndAssertSuccess(p);
File base = new File(build.getRootDir(), "htmlreports");
assertNotNull(new File(base, "reportname").list());
List<String> tab2Files = Arrays.asList(new File(base, "reportname").list());
assertTrue(tab2Files.contains("afile.html"));
}
use of hudson.Launcher in project workflow-cps-plugin by jenkinsci.
the class ParallelStepTest method getDownstreamJob.
private FreeStyleProject getDownstreamJob(Result result) throws IOException {
FreeStyleProject ds = story.j.createFreeStyleProject();
ds.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.setResult(result);
return true;
}
});
ds.setQuietPeriod(0);
return ds;
}
use of hudson.Launcher 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.Launcher 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.Launcher 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