From 8bffa4d520edd1559d25c0fc7e2635f60e504d56 Mon Sep 17 00:00:00 2001 From: Chris Cheng Date: Mon, 24 Jun 2024 11:37:43 +0800 Subject: [PATCH] allow disabled to remain the last setting Change-Id: I5a31a38c8fd50b5bf8d952ad7bab38a535895ed5 --- jenkins_jobs/builder.py | 9 +++++++++ tests/cmd/subcommands/test_update.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index a48833e88..af09cb9b4 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -350,9 +350,18 @@ class JenkinsManager(object): @concurrent def parallel_update_job(self, job): + self.fix_disabled(job) self.update_job(job.name, job.output().decode("utf-8")) return (job.name, job.md5()) + def fix_disabled(self, job): + el = job.xml.find("./disabled") + if el is not None: + return + info = self.jenkins.get_job_info(job.name) + disabled = info["disabled"] + XML.SubElement(job.xml, "disabled").text = str(disabled).lower() + ################ # View related # ################ diff --git a/tests/cmd/subcommands/test_update.py b/tests/cmd/subcommands/test_update.py index 83aa21f11..1dc116c61 100644 --- a/tests/cmd/subcommands/test_update.py +++ b/tests/cmd/subcommands/test_update.py @@ -29,6 +29,7 @@ def test_update_jobs(mocker, fixtures_dir, default_config_file, execute_jenkins_ """ mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists") mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job") path = fixtures_dir / "cmd-002.yaml" @@ -53,6 +54,7 @@ def test_update_jobs_enabled_only( """ mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists") mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job") path = fixtures_dir / "cmd-002.yaml" @@ -77,6 +79,7 @@ def test_update_jobs_decode_job_output( mocker.patch("jenkins_jobs.builder.JenkinsManager.is_job", return_value=True) mocker.patch("jenkins_jobs.builder.JenkinsManager.get_jobs") mocker.patch("jenkins_jobs.builder.JenkinsManager.get_job_md5") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") update_job_mock = mocker.patch("jenkins_jobs.builder.JenkinsManager.update_job") # don't care about the value returned here @@ -104,6 +107,7 @@ def test_update_jobs_and_delete_old( True. """ mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") jenkins_get_all_jobs = mocker.patch( "jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs" ) @@ -241,6 +245,7 @@ def test_update_jobs_and_views( """ mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists") mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job") mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.view_exists") @@ -277,6 +282,7 @@ def test_update_jobs_only( """ mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists") mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") reconfig_job = mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job") mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.view_exists") @@ -365,6 +371,7 @@ def test_update_views_and_delete_old_jobs_only( No views should be deleted or updated. """ mocker.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists") + mocker.patch("jenkins_jobs.builder.JenkinsManager.fix_disabled") jenkins_get_all_jobs = mocker.patch( "jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs" )