Java Code Examples for org.jenkinsci.plugins.workflow.job.WorkflowJob#addTrigger()
The following examples show how to use
org.jenkinsci.plugins.workflow.job.WorkflowJob#addTrigger() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractPipelineTestProject.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 6 votes |
protected void subscribeProject(ProjectFixture fixture) throws Exception { String name = UUID.randomUUID().toString(); WorkflowJob job = jenkinsRule.getInstance().createProject(WorkflowJob.class, name); String script = fixture.getPipelineScript().replace("${EmitEvent}", AbstractPipelineTestProject.class.getName() + ".emitBuildEvent()"); CpsFlowDefinition flowDefinition = new CpsFlowDefinition(script, true); job.setDefinition(flowDefinition); QueueTaskFuture<WorkflowRun> run = job.scheduleBuild2(0); WorkflowRun wfRun = run.get(); Assertions.assertThat(wfRun.getResult()) .describedAs("Pipeline unable to start succeed") .isEqualTo(Result.SUCCESS); jenkinsRule.assertBuildStatusSuccess(wfRun); resetPipelineBuildEvent(fixture); if (!fixture.isHasTrigger()) { return; } final String uuid = this.sqsQueue.getUuid(); SQSTrigger trigger = new SQSTrigger(uuid, fixture.isSubscribeInternalScm(), fixture.getScmConfigs()); job.addTrigger(trigger); trigger.start(job, false); }
Example 2
Source File: GHPullRequestSubscriberTest.java From github-integration-plugin with MIT License | 6 votes |
@Test public void shouldTriggerWorkflowJobOnIssueComment() throws Exception { when(trigger.getRepoFullName(any(Job.class))).thenReturn(create(REPO_URL_FROM_PAYLOAD)); when(trigger.getTriggerMode()).thenReturn(GitHubPRTriggerMode.HEAVY_HOOKS); WorkflowJob job = jenkins.getInstance().createProject(WorkflowJob.class, "workflow-job"); job.addProperty(new GithubProjectProperty(REPO_URL_FROM_PAYLOAD)); job.addTrigger(trigger); new GHPullRequestSubscriber().onEvent(new GHSubscriberEvent( "", GHEvent.ISSUE_COMMENT, classpath("payload/issue_comment.json")) ); verify(trigger).queueRun(eq(job), eq(1)); }
Example 3
Source File: WorkflowITest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void workflowTest() throws Exception { final WorkflowJob workflowJob = jRule.jenkins.createProject(WorkflowJob.class, "it-job"); workflowJob.addProperty(getPreconfiguredProperty(ghRule.getGhRepo())); workflowJob.addTrigger(getPreconfiguredPRTrigger()); workflowJob.setQuietPeriod(10); workflowJob.setDefinition( new CpsFlowDefinition(classpath(this.getClass(), "workflowTest.groovy"), false) ); workflowJob.save(); basicTest(workflowJob); }
Example 4
Source File: WorkflowITest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void testContextStatuses() throws Exception { final WorkflowJob workflowJob = jRule.jenkins.createProject(WorkflowJob.class, "testContextStatuses"); workflowJob.addProperty(getPreconfiguredProperty(ghRule.getGhRepo())); workflowJob.addTrigger(getPreconfiguredPRTrigger()); workflowJob.setDefinition( new CpsFlowDefinition(classpath(this.getClass(), "testContextStatuses.groovy"), false) ); workflowJob.save(); basicTest(workflowJob); GHPullRequest pullRequest = ghRule.getGhRepo().getPullRequest(1); assertThat(pullRequest, notNullValue()); WorkflowRun lastBuild = workflowJob.getLastBuild(); assertThat(lastBuild, notNullValue()); GitHubPRCause cause = lastBuild.getCause(GitHubPRCause.class); assertThat(cause, notNullValue()); List<GHCommitStatus> statuses = pullRequest.getRepository() .listCommitStatuses(cause.getHeadSha()) .asList(); assertThat(statuses, hasSize(7)); // final statuses assertThat("workflow Run.getResult() strange", statuses, hasItem(commitStatus("testContextStatuses", GHCommitState.ERROR, "Run #2 ended normally")) ); assertThat(statuses, hasItem(commitStatus("custom-context1", GHCommitState.SUCCESS, "Tests passed"))); assertThat(statuses, hasItem(commitStatus("custom-context2", GHCommitState.SUCCESS, "Tests passed"))); }
Example 5
Source File: DependencyGraphTest.java From pipeline-maven-plugin with MIT License | 4 votes |
/** * 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(); SqlTestsUtils.dump("select * from job_generated_artifacts", ((PipelineMavenPluginJdbcDao)GlobalPipelineMavenConfig.get().getDao()).getDataSource(), System.out); SqlTestsUtils.dump("select * from job_dependencies", ((PipelineMavenPluginJdbcDao)GlobalPipelineMavenConfig.get().getDao()).getDataSource(), System.out); 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()); }
Example 6
Source File: DependencyGraphTest.java From pipeline-maven-plugin with MIT License | 4 votes |
/** * 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()); }
Example 7
Source File: DependencyGraphTest.java From pipeline-maven-plugin with MIT License | 4 votes |
/** * NBM dependencies */ @Test public void verify_nbm_downstream_simple_pipeline_trigger() throws Exception { System.out.println("gitRepoRule: " + gitRepoRule); loadNbmDependencyMavenJarProjectInGitRepo(this.gitRepoRule); System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule); loadNbmBaseMavenProjectInGitRepo(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 mavenNbmDependency = jenkinsRule.createProject(WorkflowJob.class, "build-nbm-dependency"); mavenNbmDependency.setDefinition(new CpsFlowDefinition(mavenJarPipelineScript, true)); mavenNbmDependency.addTrigger(new WorkflowJobDependencyTrigger()); WorkflowRun mavenJarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenNbmDependency.scheduleBuild2(0)); // TODO check in DB that the generated artifact is recorded WorkflowJob mavenNbmBasePipeline = jenkinsRule.createProject(WorkflowJob.class, "build-nbm-base"); mavenNbmBasePipeline.setDefinition(new CpsFlowDefinition(mavenWarPipelineScript, true)); mavenNbmBasePipeline.addTrigger(new WorkflowJobDependencyTrigger()); WorkflowRun mavenWarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenNbmBasePipeline.scheduleBuild2(0)); // TODO check in DB that the dependency on the war project is recorded System.out.println("build-nbm-dependencyFirstRun: " + mavenWarPipelineFirstRun); WorkflowRun mavenJarPipelineSecondRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenNbmDependency.scheduleBuild2(0)); jenkinsRule.waitUntilNoActivity(); WorkflowRun mavenWarPipelineLastRun = mavenNbmBasePipeline.getLastBuild(); System.out.println("build-nbm-baseLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses()); assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1)); Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class); assertThat(upstreamCause, notNullValue()); }