Search in sources :

Example 11 with Launcher

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"));
}
Also used : FilePath(hudson.FilePath) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TestBuilder(org.jvnet.hudson.test.TestBuilder) Launcher(hudson.Launcher) File(java.io.File) Test(org.junit.Test)

Example 12 with Launcher

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;
}
Also used : BuildListener(hudson.model.BuildListener) Launcher(hudson.Launcher) IOException(java.io.IOException) FreeStyleProject(hudson.model.FreeStyleProject) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) TestBuilder(org.jvnet.hudson.test.TestBuilder)

Example 13 with Launcher

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));
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) Verifier(jenkins.plugins.nodejs.CIBuilderHelper.Verifier) EnvVars(hudson.EnvVars) CIBuilderHelper(jenkins.plugins.nodejs.CIBuilderHelper) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher) FreeStyleProject(hudson.model.FreeStyleProject) IOException(java.io.IOException) DetectionFailedException(jenkins.plugins.nodejs.tools.DetectionFailedException) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 14 with Launcher

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));
}
Also used : Config(org.jenkinsci.lib.configprovider.model.Config) NPMConfig(jenkins.plugins.nodejs.configfiles.NPMConfig) Verifier(jenkins.plugins.nodejs.CIBuilderHelper.Verifier) 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 15 with Launcher

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());
            }
        }
    }
}
Also used : FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) Launcher(hudson.Launcher) ArgumentListBuilder(hudson.util.ArgumentListBuilder) URISyntaxException(java.net.URISyntaxException)

Aggregations

Launcher (hudson.Launcher)20 IOException (java.io.IOException)17 FilePath (hudson.FilePath)14 Test (org.junit.Test)11 TestBuilder (org.jvnet.hudson.test.TestBuilder)11 File (java.io.File)8 FreeStyleProject (hudson.model.FreeStyleProject)7 ArrayList (java.util.ArrayList)6 BuildListener (hudson.model.BuildListener)5 EnvVars (hudson.EnvVars)3 FreeStyleBuild (hudson.model.FreeStyleBuild)3 TaskListener (hudson.model.TaskListener)3 ArtifactArchiver (hudson.tasks.ArtifactArchiver)3 AbortException (hudson.AbortException)2 PollingResult (hudson.scm.PollingResult)2 SCMRevisionState (hudson.scm.SCMRevisionState)2 WorkspaceList (hudson.slaves.WorkspaceList)2 Verifier (jenkins.plugins.nodejs.CIBuilderHelper.Verifier)2 DetectionFailedException (jenkins.plugins.nodejs.tools.DetectionFailedException)2 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)2