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 diff --git a/manifests/job/present.pp b/manifests/job/present.pp index dcfb891ee..34dc2419f 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. @@ -59,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.