diff --git a/bom-latest/pom.xml b/bom-latest/pom.xml index 7c1e5f664..02e669669 100644 --- a/bom-latest/pom.xml +++ b/bom-latest/pom.xml @@ -11,6 +11,7 @@ 1.43 4.3.0 + 1.7.2 2.6.3 1.20 2.40 @@ -316,6 +317,32 @@ jquery-detached 1.2.1 + + org.jenkinsci.plugins + pipeline-model-api + ${pipeline-model-definition-plugin.version} + + + org.jenkinsci.plugins + pipeline-model-definition + ${pipeline-model-definition-plugin.version} + + + org.jenkinsci.plugins + pipeline-model-definition + tests + ${pipeline-model-definition-plugin.version} + + + org.jenkinsci.plugins + pipeline-model-extensions + ${pipeline-model-definition-plugin.version} + + + org.jenkinsci.plugins + pipeline-stage-tags-metadata + ${pipeline-model-definition-plugin.version} + org.jenkins-ci diff --git a/sample-plugin/pom.xml b/sample-plugin/pom.xml index fb48dfe54..279e050d5 100644 --- a/sample-plugin/pom.xml +++ b/sample-plugin/pom.xml @@ -198,6 +198,11 @@ pipeline-input-step test + + org.jenkinsci.plugins + pipeline-model-definition + test + org.jenkins-ci.plugins pipeline-stage-step diff --git a/sample-plugin/src/test/java/io/jenkins/tools/bom/sample/DeclarativePipelineTest.java b/sample-plugin/src/test/java/io/jenkins/tools/bom/sample/DeclarativePipelineTest.java new file mode 100644 index 000000000..86356d679 --- /dev/null +++ b/sample-plugin/src/test/java/io/jenkins/tools/bom/sample/DeclarativePipelineTest.java @@ -0,0 +1,60 @@ +package io.jenkins.tools.bom.sample; + +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.BuildWatcher; +import org.jvnet.hudson.test.JenkinsRule; + +public class DeclarativePipelineTest { + @ClassRule + public static BuildWatcher buildWatcher = new BuildWatcher(); + + @Rule + public JenkinsRule r = new JenkinsRule(); + + @Test + public void smokes() throws Exception { + final WorkflowRun run = runPipeline(m( + "pipeline {", + " agent none", + " stages {", + " stage('Example') {", + " steps {", + " example(x: 'foobar')", + " }", + " }", + " }", + "}")); + + r.assertBuildStatusSuccess(run); + r.assertLogContains("Ran on foobar!", run); + } + + /** + * Run a pipeline job synchronously. + * + * @param definition the pipeline job definition + * @return the started job + */ + private WorkflowRun runPipeline(String definition) throws Exception { + final WorkflowJob project = r.createProject(WorkflowJob.class, "example"); + project.setDefinition(new CpsFlowDefinition(definition, true)); + final WorkflowRun workflowRun = project.scheduleBuild2(0).waitForStart(); + r.waitForCompletion(workflowRun); + return workflowRun; + } + + /** + * Approximates a multiline string in Java. + * + * @param lines the lines to concatenate with a newline separator + * @return the concatenated multiline string + */ + private static String m(String... lines) { + return String.join("\n", lines); + } +}