diff --git a/examples/src/main/kotlin/com/code42/jenkins/pipelinekt/examples/ConditionalPipeline.kt b/examples/src/main/kotlin/com/code42/jenkins/pipelinekt/examples/ConditionalPipeline.kt index e903e3d8..452aaea1 100644 --- a/examples/src/main/kotlin/com/code42/jenkins/pipelinekt/examples/ConditionalPipeline.kt +++ b/examples/src/main/kotlin/com/code42/jenkins/pipelinekt/examples/ConditionalPipeline.kt @@ -1,7 +1,5 @@ package com.code42.jenkins.pipelinekt.examples -import com.code42.jenkins.pipelinekt.core.vars.Var -import com.code42.jenkins.pipelinekt.core.vars.ext.environmentVar import com.code42.jenkins.pipelinekt.core.vars.ext.parameter import com.code42.jenkins.pipelinekt.dsl.PipelineDsl import com.code42.jenkins.pipelinekt.dsl.`when`.expression @@ -18,7 +16,6 @@ fun PipelineDsl.conditionalPipeline() = pipeline { `when` { expression { "DO_BUILD".parameter().statement() }} steps { sh("./build.sh") - val myPath: Var.Variable = def("PATH".environmentVar()) val isRelease = def { sh(script = "./isRelease.sh", returnStdout = true) } `if`((isRelease `==` "true") `||` "DO_RELEASE".parameter(), `then` = { diff --git a/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/Mail.kt b/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/Mail.kt index d8ea38f5..90b1dbf8 100644 --- a/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/Mail.kt +++ b/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/Mail.kt @@ -20,7 +20,17 @@ import com.code42.jenkins.pipelinekt.core.writer.GroovyWriter * @param mimeType Email body MIME type. Defaults to text/plain. * @param charset Email body character encoding. Defaults to UTF-8. */ -data class Mail(val to: Var.Literal.Str = "".strSingle(), val subject: Var.Literal.Str = "".strSingle(), val body: Var.Literal.Str = "".strSingle(), val cc: Var.Literal.Str = "".strSingle(), val bcc: Var.Literal.Str = "".strSingle(), val from: Var.Literal.Str = "".strSingle(), val replyTo: Var.Literal.Str = "".strSingle(), val mimeType: Var.Literal.Str = "".strSingle(), val charset: Var.Literal.Str = "".strSingle()) : DeclarativeStep, SingletonStep { +data class Mail( + val to: Var.Literal.Str = "".strSingle(), + val subject: Var.Literal.Str = "".strSingle(), + val body: Var.Literal.Str = "".strSingle(), + val cc: Var.Literal.Str = "".strSingle(), + val bcc: Var.Literal.Str = "".strSingle(), + val from: Var.Literal.Str = "".strSingle(), + val replyTo: Var.Literal.Str = "".strSingle(), + val mimeType: Var.Literal.Str = "".strSingle(), + val charset: Var.Literal.Str = "".strSingle() +) : DeclarativeStep, SingletonStep { override fun toGroovy(writer: GroovyWriter) { writer.writeln("mail to: ${to.toGroovy()}, subject: ${subject.toGroovy()}, body: ${body.toGroovy()}, from: ${from.toGroovy()}, cc: ${cc.toGroovy()}, bcc: ${bcc.toGroovy()}, replyTo: ${replyTo.toGroovy()}, mimeType: ${mimeType.toGroovy()}, charset: ${charset.toGroovy()}") } diff --git a/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/scripted/SetBuildDescription.kt b/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/scripted/SetBuildDescription.kt new file mode 100644 index 00000000..fa16533c --- /dev/null +++ b/internal/src/main/kotlin/com/code42/jenkins/pipelinekt/internal/step/scripted/SetBuildDescription.kt @@ -0,0 +1,16 @@ +package com.code42.jenkins.pipelinekt.internal.step.scripted + +import com.code42.jenkins.pipelinekt.core.step.ScriptedStep +import com.code42.jenkins.pipelinekt.core.step.SingletonStep +import com.code42.jenkins.pipelinekt.core.writer.GroovyWriter + +/** + * Set the description of a build. + * + * @param description The description of this build. + */ +data class SetBuildDescription(val description: String) : ScriptedStep, SingletonStep { + override fun scriptedGroovy(writer: GroovyWriter) { + writer.writeln("currentBuild.description = \"${description}\"") + } +} diff --git a/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/RecordIssuesTest.kt b/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/RecordIssuesTest.kt index 1d4b513c..4d1c2ace 100644 --- a/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/RecordIssuesTest.kt +++ b/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/RecordIssuesTest.kt @@ -5,6 +5,7 @@ import com.code42.jenkins.pipelinekt.core.issues.RecordIssuesTool import com.code42.jenkins.pipelinekt.core.vars.ext.boolVar import com.code42.jenkins.pipelinekt.core.vars.ext.strSingle import com.code42.jenkins.pipelinekt.internal.step.declarative.RecordIssues +import kotlin.test.assertEquals import org.junit.Test class RecordIssuesTest : GroovyScriptTest() { @@ -13,8 +14,13 @@ class RecordIssuesTest : GroovyScriptTest() { val id = "my-id".strSingle() val pattern = "my/includes,and/more".strSingle() - val expected = "recordIssues enabledForFailure: true, aggregateResults: true, tool: spotbugs(pattern: ${pattern.toGroovy()}, id: ${id.toGroovy()}, name: ${name.toGroovy()})" + val expected = "recordIssues enabledForFailure: true," + + " aggregatingResults: true," + + " tool: spotBugs(pattern: ${pattern.toGroovy()}," + + " id: ${id.toGroovy()}," + + " name: ${name.toGroovy()})\n" RecordIssues(true.boolVar(), RecordIssuesTool.Spotbugs(pattern, id, name)).toGroovy(writer) + assertEquals(expected, out.toString()) } @Test fun recordCheckstyleIssue() { @@ -22,7 +28,13 @@ class RecordIssuesTest : GroovyScriptTest() { val id = "my-id".strSingle() val pattern = "my/includes,and/more".strSingle() - val expected = "recordIssues enabledForFailure: true, aggregateResults: true, tool: checkStyle(pattern: ${pattern.toGroovy()}, id: ${id.toGroovy()}, name: ${name.toGroovy()})" - RecordIssues(true.boolVar(), RecordIssuesTool.Spotbugs(pattern, id, name)).toGroovy(writer) + val expected = "recordIssues enabledForFailure: true," + + " aggregatingResults: true," + + " tool: checkStyle(pattern: ${pattern.toGroovy()}," + + " id: ${id.toGroovy()}," + + " name: ${name.toGroovy()})\n" + + RecordIssues(true.boolVar(), RecordIssuesTool.CheckStyle(pattern, id, name)).toGroovy(writer) + assertEquals(expected, out.toString()) } } diff --git a/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/MailTest.kt b/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/MailTest.kt index edb16965..8db4bb35 100644 --- a/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/MailTest.kt +++ b/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/declarative/MailTest.kt @@ -7,20 +7,56 @@ import org.junit.Test class MailTest : GroovyScriptTest() { @Test fun empty_email() { - val expected = "mail to: '', subject: '', body: '', from: '', cc: '', bcc: '', replyTo: '', mimeType: '', charset: ''\n" + val expected = "mail to: ''," + + " subject: ''," + + " body: ''," + + " from: ''," + + " cc: ''," + + " bcc: ''," + + " replyTo: ''," + + " mimeType: ''," + + " charset: ''\n" + Mail().toGroovy(writer) assertEquals(expected, out.toString()) } @Test fun basic_email() { - val expected = "mail to: 'test@example.com', subject: 'Job Failure', body: 'Jenkins job build failure!', from: '', cc: '', bcc: '', replyTo: '', mimeType: '', charset: ''\n" - Mail("test@example.com".strSingle(), "Job Failure".strSingle(), "Jenkins job build failure!".strSingle()).toGroovy(writer) + val expected = "mail to: 'test@example.com'," + + " subject: 'Job Failure'," + + " body: 'Jenkins job build failure!'," + + " from: ''," + + " cc: ''," + + " bcc: ''," + + " replyTo: ''," + + " mimeType: ''," + + " charset: ''\n" + + Mail("test@example.com".strSingle(), + "Job Failure".strSingle(), + "Jenkins job build failure!".strSingle()).toGroovy(writer) assertEquals(expected, out.toString()) } @Test fun all_parameters_email() { - val expected = "mail to: 'test@example.com', subject: 'Job Failure', body: 'Jenkins job build failure!', from: 'jenkins@example.com', cc: 'test2@example.com', bcc: 'test3@example.com', replyTo: 'jenkins2@example.com', mimeType: 'text/plain', charset: 'UTF-8'\n" - Mail("test@example.com".strSingle(), "Job Failure".strSingle(), "Jenkins job build failure!".strSingle(), "test2@example.com".strSingle(), "test3@example.com".strSingle(), "jenkins@example.com".strSingle(), "jenkins2@example.com".strSingle(), "text/plain".strSingle(), "UTF-8".strSingle()).toGroovy(writer) + val expected = "mail to: 'test@example.com'," + + " subject: 'Job Failure'," + + " body: 'Jenkins job build failure!'," + + " from: 'jenkins@example.com'," + + " cc: 'test2@example.com'," + + " bcc: 'test3@example.com'," + + " replyTo: 'jenkins2@example.com'," + + " mimeType: 'text/plain', charset: 'UTF-8'\n" + + Mail("test@example.com".strSingle(), + "Job Failure".strSingle(), + "Jenkins job build failure!".strSingle(), + "test2@example.com".strSingle(), + "test3@example.com".strSingle(), + "jenkins@example.com".strSingle(), + "jenkins2@example.com".strSingle(), + "text/plain".strSingle(), + "UTF-8".strSingle()).toGroovy(writer) assertEquals(expected, out.toString()) } } diff --git a/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/scripted/SetBuildDescriptionTest.kt b/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/scripted/SetBuildDescriptionTest.kt new file mode 100644 index 00000000..5eb12ddf --- /dev/null +++ b/internal/src/test/kotlin/com/code42/jenkins/pipelinekt/internal/step/scripted/SetBuildDescriptionTest.kt @@ -0,0 +1,16 @@ +package com.code42.jenkins.pipelinekt.internal.step.scripted + +import com.code42.jenkins.pipelinekt.GroovyScriptTest +import kotlin.test.assertEquals +import org.junit.Test + +class SetBuildDescriptionTest : GroovyScriptTest() { + @Test fun setBuildDescription() { + val description = "Special Build Description Here!" + SetBuildDescription(description).toGroovy(writer) + val expected = "script {\n" + + "\tcurrentBuild.description = \"Special Build Description Here!\"\n" + + "}\n" + assertEquals(expected, out.toString()) + } +}