From 347b5578c3d0cae85d1e773b36c23255ebbf8efe Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 16 Oct 2021 10:17:34 -0500 Subject: [PATCH] ci: lib: Skip remount if empty limit pattern Some playbooks apply only to hosts that do not have read-only root filesystems. For these, the `rw_limit` pattern will be empty. The *Remount R/W* and *Remount R/O* stages should be skipped when this is the case. --- vars/applyConfigPolicy.groovy | 43 ++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/vars/applyConfigPolicy.groovy b/vars/applyConfigPolicy.groovy index d134996..c16c15d 100644 --- a/vars/applyConfigPolicy.groovy +++ b/vars/applyConfigPolicy.groovy @@ -1,4 +1,5 @@ import groovy.transform.Field +import org.jenkinsci.plugins.pipeline.modeldefinition.Utils @Field def DOCKER_ARGS = '''\ @@ -52,15 +53,20 @@ def stageKinit() { def stageRemountRW(limit) { - stage('Remount R/W') { - ansiblePlaybook \ - playbook: 'remount.yml', - limit: limit, - become: true, - vaultCredentialsId: 'ansible-vault', - extraVars: [ - remount_state: 'rw', - ] + def STAGE_NAME = 'Remount R/W' + stage(STAGE_NAME) { + if (limit) { + ansiblePlaybook \ + playbook: 'remount.yml', + limit: limit, + become: true, + vaultCredentialsId: 'ansible-vault', + extraVars: [ + remount_state: 'rw', + ] + } else { + Utils.markStageSkippedForConditional(STAGE_NAME) + } } } @@ -80,13 +86,18 @@ def generateStages(stages) { } def stageRemountRO(limit) { - stage('Remount R/O') { - ansiblePlaybook \ - playbook: 'remount.yml', - limit: limit + ':!rw-root', - become: true, - vaultCredentialsId: 'ansible-vault', - extras: '--diff' + def STAGE_NAME = 'Remount R/W' + stage(STAGE_NAME) { + if (limit) { + ansiblePlaybook \ + playbook: 'remount.yml', + limit: limit + ':!rw-root', + become: true, + vaultCredentialsId: 'ansible-vault', + extras: '--diff' + } else { + Utils.markStageSkippedForConditional(STAGE_NAME) + } } }