From dbbad4e08ea742a840fcf8f6de38581fd7c3941a Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Sun, 6 Mar 2022 15:56:14 +0100 Subject: [PATCH 1/2] fix(updatecli) do not reset cron pipeline triggers when no cron expression is passed Signed-off-by: Damien Duportal --- vars/terraform.groovy | 10 ++++++++-- vars/updatecli.groovy | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/vars/terraform.groovy b/vars/terraform.groovy index f022fd316..2715facfd 100644 --- a/vars/terraform.groovy +++ b/vars/terraform.groovy @@ -27,10 +27,16 @@ def call(userConfig = [:]) { final String sharedToolsSubDir = '.shared-tools' final String makeCliCmd = "make --directory=${sharedToolsSubDir}/terraform/" + // Only define a cron trigger on the "principal" branch + if(isBuildOnProductionBranch && finalConfig.cronTriggerExpression) { + properties([ + pipelineTriggers([ + cron(finalConfig.cronTriggerExpression) + ]), + ]) + } properties([ - // Defines a cron trigger only on the production branch - pipelineTriggers(isBuildOnProductionBranch ? [cron(finalConfig.cronTriggerExpression)] : []), // Only run 1 build at a time, on a given branch, to ensure that infrastructure changes are sequentials (easier to audit) disableConcurrentBuilds(), // Only keep build history for long on the principal branch diff --git a/vars/updatecli.groovy b/vars/updatecli.groovy index e53e41e51..0a0efa583 100644 --- a/vars/updatecli.groovy +++ b/vars/updatecli.groovy @@ -1,10 +1,11 @@ def call(userConfig = [:]) { def defaultConfig = [ - action: 'diff', - config: './updatecli/updatecli.d', - values: './updatecli/values.yaml', - updatecliDockerImage: 'jenkinsciinfra/helmfile:2.3.0', - containerMemory: '512Mi' + action: 'diff', // updatecli subcommand to execute + config: './updatecli/updatecli.d', // config manifest used by updatecli (can be a file or a directory) - + values: './updatecli/values.yaml', // values file used by updatecli + updatecliDockerImage: 'jenkinsciinfra/helmfile:2.3.0', // Container image to use for running updatecli + containerMemory: '512Mi', // When using 'updatecliDockerImage', this is the memory limit+request of the container + cronTriggerExpression: '', // When specified, it enables cron trigger for the calling pipeline ] // Merging the 2 maps - https://blog.mrhaki.com/2010/04/groovy-goodness-adding-maps-to-map_21.html @@ -17,9 +18,13 @@ def call(userConfig = [:]) { updatecliCommand += finalConfig.values ? " --values ${finalConfig.values}" : '' // Define a cron trigger only if it's requested by the user through attribute - properties([ - pipelineTriggers(finalConfig.cronTriggerExpression ? [cron(finalConfig.cronTriggerExpression)] : []) - ]) + if(finalConfig.cronTriggerExpression) { + properties([ + pipelineTriggers([ + cron(finalConfig.cronTriggerExpression) + ]) + ]) + } // The podTemplate must define only a single container, named `jnlp` // Ref - https://support.cloudbees.com/hc/en-us/articles/360054642231-Considerations-for-Kubernetes-Clients-Connections-when-using-Kubernetes-Plugin From cd96ec9835bf4439e43663292506f48a84f4814b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Sun, 6 Mar 2022 16:33:00 +0100 Subject: [PATCH 2/2] nitpicks --- vars/terraform.groovy | 2 +- vars/updatecli.groovy | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vars/terraform.groovy b/vars/terraform.groovy index 2715facfd..2c5371f09 100644 --- a/vars/terraform.groovy +++ b/vars/terraform.groovy @@ -28,7 +28,7 @@ def call(userConfig = [:]) { final String makeCliCmd = "make --directory=${sharedToolsSubDir}/terraform/" // Only define a cron trigger on the "principal" branch - if(isBuildOnProductionBranch && finalConfig.cronTriggerExpression) { + if (isBuildOnProductionBranch && finalConfig.cronTriggerExpression) { properties([ pipelineTriggers([ cron(finalConfig.cronTriggerExpression) diff --git a/vars/updatecli.groovy b/vars/updatecli.groovy index 0a0efa583..93099bc2c 100644 --- a/vars/updatecli.groovy +++ b/vars/updatecli.groovy @@ -1,8 +1,8 @@ def call(userConfig = [:]) { def defaultConfig = [ - action: 'diff', // updatecli subcommand to execute - config: './updatecli/updatecli.d', // config manifest used by updatecli (can be a file or a directory) - - values: './updatecli/values.yaml', // values file used by updatecli + action: 'diff', // Updatecli subcommand to execute + config: './updatecli/updatecli.d', // Config manifest used by updatecli (can be a file or a directory) + values: './updatecli/values.yaml', // Values file used by updatecli updatecliDockerImage: 'jenkinsciinfra/helmfile:2.3.0', // Container image to use for running updatecli containerMemory: '512Mi', // When using 'updatecliDockerImage', this is the memory limit+request of the container cronTriggerExpression: '', // When specified, it enables cron trigger for the calling pipeline @@ -17,8 +17,8 @@ def call(userConfig = [:]) { // Do not add the flag "--values" if the provided value is "empty string" updatecliCommand += finalConfig.values ? " --values ${finalConfig.values}" : '' - // Define a cron trigger only if it's requested by the user through attribute - if(finalConfig.cronTriggerExpression) { + // Define a cron trigger only if requested by the user through attribute + if (finalConfig.cronTriggerExpression) { properties([ pipelineTriggers([ cron(finalConfig.cronTriggerExpression)