From 9eb9eb6ec6186c78c1b5104f48fcc7de622affe7 Mon Sep 17 00:00:00 2001 From: mthirdy Date: Wed, 10 Jan 2024 11:54:10 +0100 Subject: [PATCH 1/3] Adapted present.pp to be compatible to cloudbees-folder - the possible slashes in jobname are replaced by underscores to suppress the necessary of existing subfloders in the /tmp folder for temporary file creation --- manifests/job/present.pp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifests/job/present.pp b/manifests/job/present.pp index d2d7194fa..422867bb4 100644 --- a/manifests/job/present.pp +++ b/manifests/job/present.pp @@ -33,7 +33,9 @@ $tmp_config_path = $config_file } else { - $tmp_config_path = "/tmp/${jobname}-config.xml" + # in case of a cloudbees-folder element replace all '/' with underscore so only a file without subdirectory is created + $replaced_jobname = regsubst($jobname, /\//, '_', 'G') + $tmp_config_path = "/tmp/${replaced_jobname}-config.xml" # # When a Jenkins job is imported via the cli, Jenkins will # re-format the xml file based on its own internal rules. From 1c0081f6283c27f80f0501c50c9879717aba8c01 Mon Sep 17 00:00:00 2001 From: mthirdy Date: Wed, 10 Jan 2024 13:44:32 +0100 Subject: [PATCH 2/3] Adapted absent.pp to be compatible to cloudbees-folder - the possible slashes in jobname are replaced by underscores so the correct file is deleted - the possible slashes in jobname are replaced by '/jobs/' so the correct cloudbees-folder job config file is found and the job is deleted by jenkins api --- manifests/job/absent.pp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manifests/job/absent.pp b/manifests/job/absent.pp index 0bcdff906..6a6a2f6b6 100644 --- a/manifests/job/absent.pp +++ b/manifests/job/absent.pp @@ -13,8 +13,12 @@ fail('Management of Jenkins jobs requires \$jenkins::service_ensure to be set to \'running\'') } - $tmp_config_path = "/tmp/${jobname}-config.xml" - $job_dir = "${jenkins::job_dir}/${jobname}" + # in case of a cloudbees-folder element replace all '/' with underscore so only a file without subdirectory is deleted + $replaced_jobname = regsubst($jobname, /\//, '_', 'G') + $tmp_config_path = "/tmp/${replaced_jobname}-config.xml" + # in case of a cloudbees-folder element inserting sub-directory '/jobs' for every folder level so the existing config file is deleted + $job_subdir_name = regsubst($jobname, /\//, '/jobs/', 'G') + $job_dir = "${jenkins::job_dir}/${job_subdir_name}" $config_path = "${job_dir}/config.xml" # Temp file to use as stdin for Jenkins CLI executable From 6d5dc83c275b1476507918b59bcbaa873ed5bd46 Mon Sep 17 00:00:00 2001 From: mthirdy Date: Wed, 11 Sep 2024 08:12:57 +0200 Subject: [PATCH 3/3] cloudbees-folders are not created anymore if already existing - because of different jobdir for cloudbees-folder an already existing jobs was recreated --- manifests/job/present.pp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifests/job/present.pp b/manifests/job/present.pp index 422867bb4..1a3a402cd 100644 --- a/manifests/job/present.pp +++ b/manifests/job/present.pp @@ -61,7 +61,9 @@ } } - $job_dir = "${jenkins::job_dir}/${jobname}" + # in case of a cloudbees-folder element inserting sub-directory '/jobs' for every folder level so the existing config_path or job_dir/builds is found + $job_subdir_name = regsubst($jobname, /\//, '/jobs/', 'G') + $job_dir = "${jenkins::job_dir}/${job_subdir_name}" $config_path = "${job_dir}/config.xml" # Bring variables from Class['::jenkins'] into local scope.