本文整理汇总了Java中org.jenkinsci.plugins.workflow.job.WorkflowJob.getLastBuild方法的典型用法代码示例。如果您正苦于以下问题:Java WorkflowJob.getLastBuild方法的具体用法?Java WorkflowJob.getLastBuild怎么用?Java WorkflowJob.getLastBuild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jenkinsci.plugins.workflow.job.WorkflowJob
的用法示例。
在下文中一共展示了WorkflowJob.getLastBuild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDefaultJenkinsFile
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
@Test
public void testDefaultJenkinsFile() throws Exception {
GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
ConfigFileStore store = globalConfigFiles.get();
Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
"semaphore 'wait'; node {checkout scm; echo readFile('file')}");
store.save(config);
sampleGitRepo.init();
sampleGitRepo.write("file", "initial content");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
assertEquals(1, b1.getNumber());
SemaphoreStep.success("wait/1", null);
r.assertLogContains("initial content", r.waitForCompletion(b1));
}
示例2: testDefaultJenkinsFileLoadFromWorkspace
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
@Test
public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
ConfigFileStore store = globalConfigFiles.get();
Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
"semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
store.save(config);
sampleGitRepo.init();
sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
sampleGitRepo.git("add", "Jenkinsfile");
sampleGitRepo.write("file", "initial content");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
new DefaultBranchPropertyStrategy(new BranchProperty[0])));
WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
assertEquals(1, b1.getNumber());
SemaphoreStep.success("wait/1", null);
r.assertLogContains("initial content", r.waitForCompletion(b1));
}
示例3: verify_downstream_simple_pipeline_trigger
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* The maven-war-app has a dependency on the maven-jar-app
*/
@Test
public void verify_downstream_simple_pipeline_trigger() throws Exception {
System.out.println("gitRepoRule: " + gitRepoRule);
loadMavenJarProjectInGitRepo(this.gitRepoRule);
System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule);
loadMavenWarProjectInGitRepo(this.downstreamArtifactRepoRule);
String mavenJarPipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
String mavenWarPipelineScript = "node('master') {\n" +
" git($/" + downstreamArtifactRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
WorkflowJob mavenJarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-jar");
mavenJarPipeline.setDefinition(new CpsFlowDefinition(mavenJarPipelineScript, true));
mavenJarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenJarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
// TODO check in DB that the generated artifact is recorded
WorkflowJob mavenWarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-war");
mavenWarPipeline.setDefinition(new CpsFlowDefinition(mavenWarPipelineScript, true));
mavenWarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenWarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenWarPipeline.scheduleBuild2(0));
// TODO check in DB that the dependency on the war project is recorded
System.out.println("mavenWarPipelineFirstRun: " + mavenWarPipelineFirstRun);
WorkflowRun mavenJarPipelineSecondRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineLastRun = mavenWarPipeline.getLastBuild();
System.out.println("mavenWarPipelineLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses());
assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1));
Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class);
assertThat(upstreamCause, notNullValue());
}
示例4: verify_downstream_multi_branch_pipeline_trigger
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* The maven-war-app has a dependency on the maven-jar-app
*/
@Test
public void verify_downstream_multi_branch_pipeline_trigger() throws Exception {
System.out.println("gitRepoRule: " + gitRepoRule);
loadMavenJarProjectInGitRepo(this.gitRepoRule);
System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule);
loadMavenWarProjectInGitRepo(this.downstreamArtifactRepoRule);
String script = "node('master') {\n" +
" checkout scm\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
gitRepoRule.write("Jenkinsfile", script);
gitRepoRule.git("add", "Jenkinsfile");
gitRepoRule.git("commit", "--message=jenkinsfile");
downstreamArtifactRepoRule.write("Jenkinsfile", script);
downstreamArtifactRepoRule.git("add", "Jenkinsfile");
downstreamArtifactRepoRule.git("commit", "--message=jenkinsfile");
// TRIGGER maven-jar#1 to record that "build-maven-jar" generates this jar and install this maven jar in the local maven repo
WorkflowMultiBranchProject mavenJarPipeline = jenkinsRule.createProject(WorkflowMultiBranchProject.class, "build-maven-jar");
mavenJarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
mavenJarPipeline.getSourcesList().add(new BranchSource(new GitSCMSource(null, gitRepoRule.toString(), "", "*", "", false)));
System.out.println("trigger maven-jar#1...");
WorkflowJob mavenJarPipelineMasterPipeline = WorkflowMultibranchProjectTestsUtils.scheduleAndFindBranchProject(mavenJarPipeline, "master");
assertEquals(1, mavenJarPipeline.getItems().size());
System.out.println("wait for maven-jar#1...");
jenkinsRule.waitUntilNoActivity();
assertThat(mavenJarPipelineMasterPipeline.getLastBuild().getNumber(), is(1));
// TODO check in DB that the generated artifact is recorded
// TRIGGER maven-war#1 to record that "build-maven-war" has a dependency on "build-maven-jar"
WorkflowMultiBranchProject mavenWarPipeline = jenkinsRule.createProject(WorkflowMultiBranchProject.class, "build-maven-war");
mavenWarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
mavenWarPipeline.getSourcesList().add(new BranchSource(new GitSCMSource(null, downstreamArtifactRepoRule.toString(), "", "*", "", false)));
System.out.println("trigger maven-war#1...");
WorkflowJob mavenWarPipelineMasterPipeline = WorkflowMultibranchProjectTestsUtils.scheduleAndFindBranchProject(mavenWarPipeline, "master");
assertEquals(1, mavenWarPipeline.getItems().size());
System.out.println("wait for maven-war#1...");
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineFirstRun = mavenWarPipelineMasterPipeline.getLastBuild();
// TODO check in DB that the dependency on the war project is recorded
// TRIGGER maven-jar#2 so that it triggers "maven-war" and creates maven-war#2
System.out.println("trigger maven-jar#2...");
Future<WorkflowRun> mavenJarPipelineMasterPipelineSecondRunFuture = mavenJarPipelineMasterPipeline.scheduleBuild2(0, new CauseAction(new Cause.RemoteCause("127.0.0.1", "junit test")));
System.out.println("wait for maven-jar#2...");
mavenJarPipelineMasterPipelineSecondRunFuture.get();
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineLastRun = mavenWarPipelineMasterPipeline.getLastBuild();
System.out.println("mavenWarPipelineLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses());
assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1));
Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class);
assertThat(upstreamCause, notNullValue());
}
示例5: verify_downstream_pipeline_triggered_on_parent_pom_build
import org.jenkinsci.plugins.workflow.job.WorkflowJob; //导入方法依赖的package包/类
/**
* The maven-war-app has a dependency on the maven-jar-app
*/
@Test
public void verify_downstream_pipeline_triggered_on_parent_pom_build() throws Exception {
System.out.println("gitRepoRule: " + gitRepoRule);
loadMavenJarProjectInGitRepo(this.gitRepoRule);
System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule);
loadMavenWarProjectInGitRepo(this.downstreamArtifactRepoRule);
String mavenJarPipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
String mavenWarPipelineScript = "node('master') {\n" +
" git($/" + downstreamArtifactRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
WorkflowJob mavenJarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-jar");
mavenJarPipeline.setDefinition(new CpsFlowDefinition(mavenJarPipelineScript, true));
mavenJarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenJarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
// TODO check in DB that the generated artifact is recorded
WorkflowJob mavenWarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-war");
mavenWarPipeline.setDefinition(new CpsFlowDefinition(mavenWarPipelineScript, true));
mavenWarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenWarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenWarPipeline.scheduleBuild2(0));
// TODO check in DB that the dependency on the war project is recorded
System.out.println("mavenWarPipelineFirstRun: " + mavenWarPipelineFirstRun);
WorkflowRun mavenJarPipelineSecondRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineLastRun = mavenWarPipeline.getLastBuild();
System.out.println("mavenWarPipelineLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses());
assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1));
Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class);
assertThat(upstreamCause, notNullValue());
}