Skip to content

Commit

Permalink
fix(updatecli) do not reset cron pipeline triggers when no cron expre…
Browse files Browse the repository at this point in the history
…ssion is passed (jenkins-infra#315)

* fix(updatecli) do not reset cron pipeline triggers when no cron expression is passed

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>

* nitpicks

Co-authored-by: Hervé Le Meur <hlemeur@cloudbees.com>
  • Loading branch information
2 people authored and smerle33 committed Jan 16, 2024
1 parent c870839 commit d41709a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
10 changes: 8 additions & 2 deletions vars/terraform.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions vars/updatecli.groovy
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,10 +17,14 @@ 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
properties([
pipelineTriggers(finalConfig.cronTriggerExpression ? [cron(finalConfig.cronTriggerExpression)] : [])
])
// Define a cron trigger only if requested by the user through attribute
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
Expand Down

0 comments on commit d41709a

Please sign in to comment.