From 9138197b29ebab9737e532bccaada13437fa3edc Mon Sep 17 00:00:00 2001 From: Stephan Folkes Date: Fri, 26 Mar 2021 12:27:23 +0000 Subject: [PATCH 1/2] Replacing the builder pattern with the recommended Map params. https://www.jenkins.io/doc/book/pipeline/shared-libraries/#defining-a-more-structured-dsl --- vars/closurePipeline.groovy | 8 ++------ vars/easyPipeline.groovy | 11 +++-------- vars/fooProject.groovy | 6 +----- vars/heartQ.groovy | 6 +----- vars/indigenous-cloudbees.groovy | 9 ++------- vars/indigenous.groovy | 7 +------ vars/indigenousPod.groovy | 17 ++++++----------- vars/javaMaven.groovy | 7 +------ vars/pipelineLoadYamlFile.groovy | 9 ++------- vars/superEasyPipeline.groovy | 6 +++--- vars/wip.groovy | 13 ++++--------- 11 files changed, 26 insertions(+), 73 deletions(-) diff --git a/vars/closurePipeline.groovy b/vars/closurePipeline.groovy index 0ab4fa10..9da517e5 100644 --- a/vars/closurePipeline.groovy +++ b/vars/closurePipeline.groovy @@ -1,8 +1,4 @@ -def call(body) { - def pipelineParams= [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams) { pipeline { agent { label "master" } @@ -24,7 +20,7 @@ def call(body) { } stage("SonarQube Scan") { when { - equals expected: "toomuch", actual: pipelineParams?.sonar?.sing + equals expected: "toomuch", actual: "${pipelineParams.sonar.sing}" } steps { echo 'scan' diff --git a/vars/easyPipeline.groovy b/vars/easyPipeline.groovy index 31800587..9bbe067c 100644 --- a/vars/easyPipeline.groovy +++ b/vars/easyPipeline.groovy @@ -1,9 +1,4 @@ -def call(String agentLabel,body) { - - def pipelineParams= [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(String agentLabel,Map pipelineParams) { pipeline { agent none @@ -15,7 +10,7 @@ def call(String agentLabel,body) { echo "${agentLabel}" echo "${pipelineParams.osConfiguration}" echo "${pipelineParams.osConfiguration.OS_VERSION}" - echo "${pipelineParams.osConfiguration.DIR_TYPE}" + echo "${pipelineParams.osConfiguration.DIR_TYPE}" } } stage("Prepare Build Environment") { @@ -75,7 +70,7 @@ def call(String agentLabel,body) { // } // echo "Webhook called with data: ${data}" // } - //} + //} } //post { // always { diff --git a/vars/fooProject.groovy b/vars/fooProject.groovy index d1c88c68..a503ce31 100644 --- a/vars/fooProject.groovy +++ b/vars/fooProject.groovy @@ -1,8 +1,4 @@ -def call(body) { - def pipelineParams = [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams=[:]) { println(pipelineParams) } diff --git a/vars/heartQ.groovy b/vars/heartQ.groovy index 374245c7..e5562f46 100644 --- a/vars/heartQ.groovy +++ b/vars/heartQ.groovy @@ -1,8 +1,4 @@ -def call(body) { - def pipelineParams= [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams) { pipeline { agent { diff --git a/vars/indigenous-cloudbees.groovy b/vars/indigenous-cloudbees.groovy index 387c63d8..1426580c 100644 --- a/vars/indigenous-cloudbees.groovy +++ b/vars/indigenous-cloudbees.groovy @@ -1,9 +1,4 @@ -def call(body) { - - def pipelineParams = [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams) { def autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") def runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") @@ -175,4 +170,4 @@ def call(body) { } } } -} \ No newline at end of file +} diff --git a/vars/indigenous.groovy b/vars/indigenous.groovy index e9655f94..9bc42ff1 100644 --- a/vars/indigenous.groovy +++ b/vars/indigenous.groovy @@ -1,9 +1,4 @@ -def call(body) { - - def pipelineParams = [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams) { def autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") def runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") diff --git a/vars/indigenousPod.groovy b/vars/indigenousPod.groovy index 27c3a977..59047817 100644 --- a/vars/indigenousPod.groovy +++ b/vars/indigenousPod.groovy @@ -1,9 +1,4 @@ -def call(body) { - - def pipelineParams = [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams) { def autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") def runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") @@ -34,22 +29,22 @@ def call(body) { command: - cat tty: true - - name: artifactory + - name: artifactory image: gcc:8.1.0 command: - cat tty: true - - name: deployer + - name: deployer image: gcc:8.1.0 command: - cat tty: true - - name: guismoketest + - name: guismoketest image: gcc:8.1.0 command: - cat tty: true - - name: servicesmoketest + - name: servicesmoketest image: gcc:8.1.0 command: - cat @@ -248,4 +243,4 @@ def call(body) { } } } -} \ No newline at end of file +} diff --git a/vars/javaMaven.groovy b/vars/javaMaven.groovy index c1f862be..30603231 100644 --- a/vars/javaMaven.groovy +++ b/vars/javaMaven.groovy @@ -1,9 +1,4 @@ -def call(body) { - - def pipelineParams= [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams) { // this found at https://stackoverflow.com/a/49132694 def agentLabel = null diff --git a/vars/pipelineLoadYamlFile.groovy b/vars/pipelineLoadYamlFile.groovy index ce9c1828..9979fa8b 100644 --- a/vars/pipelineLoadYamlFile.groovy +++ b/vars/pipelineLoadYamlFile.groovy @@ -1,9 +1,4 @@ -def call(body) { - - def pipelineParams = [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams=[:]) { pipeline { agent { @@ -29,4 +24,4 @@ def call(body) { } } } -} \ No newline at end of file +} diff --git a/vars/superEasyPipeline.groovy b/vars/superEasyPipeline.groovy index d6da17a2..e805baf0 100644 --- a/vars/superEasyPipeline.groovy +++ b/vars/superEasyPipeline.groovy @@ -1,3 +1,3 @@ -def call(body) { - easyPipeline("master",body) -} \ No newline at end of file +def call(Map pipelineParams) { + easyPipeline("master",pipelineParams) +} diff --git a/vars/wip.groovy b/vars/wip.groovy index c181b1ae..f86917a8 100644 --- a/vars/wip.groovy +++ b/vars/wip.groovy @@ -1,21 +1,16 @@ -def call(body) { - - def pipelineParams = [:] - body.resolveStrategy = Closure.DELEGATE_FIRST - body.delegate = pipelineParams - body() +def call(Map pipelineParams=[:]) { echo "${pipelineParams}" - + def autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") echo "autoDeploy = ${autoDeploy}" - + def runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") echo "runSmokeTests = ${runSmokeTests}" def notifyEmail = getValueOrDefault("${pipelineParams.notifyEmail}","a@a.com") echo "notifyEmail = ${notifyEmail}" - + pipeline { agent any stages { From 37d538fd2937c0ef808d31908a1f54130cc564dd Mon Sep 17 00:00:00 2001 From: Stephan Folkes Date: Fri, 26 Mar 2021 12:36:15 +0000 Subject: [PATCH 2/2] Moving variables for pipelines into environment blocks. --- vars/indigenous.groovy | 9 +++++---- vars/indigenousPod.groovy | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vars/indigenous.groovy b/vars/indigenous.groovy index 9bc42ff1..dae48c75 100644 --- a/vars/indigenous.groovy +++ b/vars/indigenous.groovy @@ -1,9 +1,5 @@ def call(Map pipelineParams) { - def autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") - def runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") - def notifyEmail = "${pipelineParams.notifyEmail}" - pipeline { agent none options { @@ -12,6 +8,11 @@ def call(Map pipelineParams) { skipDefaultCheckout() durabilityHint('PERFORMANCE_OPTIMIZED') } + environment { + autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") + runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") + notifyEmail = "${pipelineParams.notifyEmail}" + } stages { stage("Prepare Build Environment") { agent { label "linux" } diff --git a/vars/indigenousPod.groovy b/vars/indigenousPod.groovy index 59047817..c7a9bc7f 100644 --- a/vars/indigenousPod.groovy +++ b/vars/indigenousPod.groovy @@ -1,9 +1,5 @@ def call(Map pipelineParams) { - def autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") - def runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") - def notifyEmail = "${pipelineParams.notifyEmail}" - pipeline { agent { kubernetes { @@ -56,6 +52,11 @@ def call(Map pipelineParams) { buildDiscarder(logRotator(numToKeepStr: '5')) durabilityHint('PERFORMANCE_OPTIMIZED') } + environment { + autoDeploy = getValueOrDefault("${pipelineParams.autoDeploy}","n") + runSmokeTests = getValueOrDefault("${pipelineParams.runSmokeTests}","n") + notifyEmail = "${pipelineParams.notifyEmail}" + } stages { stage("Prepare Build Environment") { steps {