Search in sources :

Example 6 with GitStep

use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.

the class CpsScmFlowDefinitionTest method lightweight.

@Issue({ "JENKINS-33273", "JENKINS-63305" })
@Test
public void lightweight() throws Exception {
    sampleRepo.init();
    sampleRepo.write("flow.groovy", "echo 'version one'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=init");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    GitStep step = new GitStep(sampleRepo.toString());
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(step.createSCM(), "flow.groovy");
    def.setLightweight(true);
    TestDurabilityHintProvider provider = Jenkins.get().getExtensionList(TestDurabilityHintProvider.class).get(0);
    provider.registerHint("p", FlowDurabilityHint.PERFORMANCE_OPTIMIZED);
    p.setDefinition(def);
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, b.getExecution().getDurabilityHint());
    r.assertLogNotContains("Cloning the remote Git repository", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    r.assertLogContains("Obtained flow.groovy from git " + sampleRepo, b);
    r.assertLogContains("version one", b);
}
Also used : TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) GitStep(jenkins.plugins.git.GitStep) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 7 with GitStep

use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.

the class CpsScmFlowDefinitionTest method missingFile.

@Issue("JENKINS-59425")
@Test
public void missingFile() throws Exception {
    sampleRepo.init();
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    GitStep step = new GitStep(sampleRepo.toString());
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(step.createSCM(), "flow.groovy");
    def.setLightweight(true);
    p.setDefinition(def);
    WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
    r.assertLogNotContains("Cloning the remote Git repository", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    r.assertLogContains("Unable to find flow.groovy from git " + sampleRepo, b);
}
Also used : WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) GitStep(jenkins.plugins.git.GitStep) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 8 with GitStep

use of jenkins.plugins.git.GitStep in project workflow-cps-plugin by jenkinsci.

the class CpsScmFlowDefinitionTest method changelogAndPolling.

@Test
public void changelogAndPolling() throws Exception {
    sampleRepo.init();
    sampleRepo.write("flow.groovy", "echo 'version one'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=init");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    // no schedule, use notifyCommit only
    p.addTrigger(new SCMTrigger(""));
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "flow.groovy");
    def.setLightweight(false);
    p.setDefinition(def);
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    r.assertLogContains("Cloning the remote Git repository", b);
    r.assertLogContains("version one", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    sampleRepo.write("flow.groovy", "echo 'version two'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=next");
    sampleRepo.notifyCommit(r);
    b = p.getLastBuild();
    assertEquals(2, b.number);
    r.assertLogContains("Fetching changes from the remote Git repository", b);
    r.assertLogContains("version two", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets();
    assertEquals(1, changeSets.size());
    ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0);
    assertEquals(b, changeSet.getRun());
    assertEquals("git", changeSet.getKind());
    Iterator<? extends ChangeLogSet.Entry> iterator = changeSet.iterator();
    assertTrue(iterator.hasNext());
    ChangeLogSet.Entry entry = iterator.next();
    assertEquals("[flow.groovy]", entry.getAffectedPaths().toString());
    assertFalse(iterator.hasNext());
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) SCMTrigger(hudson.triggers.SCMTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) GitStep(jenkins.plugins.git.GitStep) Test(org.junit.Test)

Aggregations

GitStep (jenkins.plugins.git.GitStep)8 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)8 Test (org.junit.Test)8 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)7 Issue (org.jvnet.hudson.test.Issue)6 ChangeLogSet (hudson.scm.ChangeLogSet)2 Path (java.nio.file.Path)2 SubversionSCM (hudson.scm.SubversionSCM)1 SCMTrigger (hudson.triggers.SCMTrigger)1 File (java.io.File)1 FileMatchers.anExistingFile (org.hamcrest.io.FileMatchers.anExistingFile)1 TestDurabilityHintProvider (org.jenkinsci.plugins.workflow.TestDurabilityHintProvider)1