Search in sources :

Example 1 with ConfigFileBuildWrapper

use of org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper in project promoted-builds-plugin by jenkinsci.

the class ConfigurationRoundtripTest method testRoundtrip.

/**
 * Configuration roundtrip test to detect data loss.
 */
@Test
public void testRoundtrip() throws Exception {
    FreeStyleProject down = j.createFreeStyleProject();
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("test");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.getBuildWrappersList().add(new ConfigFileBuildWrapper(new ArrayList<ManagedFile>()));
    proc.icon = "star-blue";
    // round trip
    JenkinsRule.WebClient wc = j.createWebClient();
    submit(wc.getPage(p, "configure").getFormByName("config"));
    // assert that the configuration is still intact
    pp = p.getProperty(JobPropertyImpl.class);
    assertEquals(1, pp.getItems().size());
    proc = pp.getItem("test");
    assertEquals(1, proc.conditions.toList().size());
    DownstreamPassCondition dcp = proc.conditions.get(DownstreamPassCondition.class);
    assertEquals(dcp.getJobs(), down.getName());
    assertEquals(1, proc.getBuildSteps().size());
    JavadocArchiver ja = (JavadocArchiver) proc.getBuildSteps().get(0);
    assertEquals("somedir", ja.getJavadocDir());
    assertTrue(ja.isKeepAll());
    ConfigFileBuildWrapper buildWrapper = (ConfigFileBuildWrapper) proc.getBuildWrappersList().get(0);
    assertNotNull(buildWrapper);
    assertEquals("star-blue", proc.icon);
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) ArrayList(java.util.ArrayList) ConfigFileBuildWrapper(org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper) JavadocArchiver(hudson.tasks.JavadocArchiver) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 2 with ConfigFileBuildWrapper

use of org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper in project workflow-cps-plugin by jenkinsci.

the class StepNodeTest method metastepConsoleShellClass.

@Test
public void metastepConsoleShellClass() throws Exception {
    WorkflowJob p = r.createProject(WorkflowJob.class);
    p.setDefinition(new CpsFlowDefinition("node {\n" + "  wrap([$class: 'ConfigFileBuildWrapper', managedFiles: []]) {\n" + "    writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + "    step([$class: 'ArtifactArchiver', artifacts: 'x.xml'])\n" + "  }\n" + "}", true));
    WorkflowRun b = r.buildAndAssertSuccess(p);
    List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step"));
    assertThat(coreStepNodes, hasSize(1));
    assertEquals("archiveArtifacts", coreStepNodes.get(0).getDisplayFunctionName());
    assertEquals(r.jenkins.getDescriptor(ArtifactArchiver.class).getDisplayName(), coreStepNodes.get(0).getDisplayName());
    List<FlowNode> coreWrapperStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), Predicates.and(new NodeStepTypePredicate("wrap"), new Predicate<FlowNode>() {

        @Override
        public boolean apply(FlowNode n) {
            return n instanceof StepStartNode && !((StepStartNode) n).isBody();
        }
    }));
    assertThat(coreWrapperStepNodes, hasSize(1));
    assertEquals("configFileProvider", coreWrapperStepNodes.get(0).getDisplayFunctionName());
    assertEquals(r.jenkins.getDescriptor(ConfigFileBuildWrapper.class).getDisplayName() + " : Start", coreWrapperStepNodes.get(0).getDisplayName());
    r.assertLogContains("[Pipeline] archiveArtifacts", b);
    r.assertLogContains("[Pipeline] configFileProvider", b);
    r.assertLogContains("[Pipeline] // configFileProvider", b);
}
Also used : NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ConfigFileBuildWrapper(org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Aggregations

ConfigFileBuildWrapper (org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper)2 Test (org.junit.Test)2 Predicate (com.google.common.base.Predicate)1 FreeStyleProject (hudson.model.FreeStyleProject)1 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)1 JavadocArchiver (hudson.tasks.JavadocArchiver)1 ArrayList (java.util.ArrayList)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 DepthFirstScanner (org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner)1 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)1