From e8bdec27336d8d532b2224233c429d028f502211 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 26 Feb 2023 15:37:16 +0100 Subject: [PATCH] jenkins_plugin: avoid undefined variable when updates file is not downloaded (#6100) Avoid undefined variable when updates file is not downloaded. --- changelogs/fragments/6100-jenkins_plugin.yml | 2 ++ plugins/modules/jenkins_plugin.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/6100-jenkins_plugin.yml diff --git a/changelogs/fragments/6100-jenkins_plugin.yml b/changelogs/fragments/6100-jenkins_plugin.yml new file mode 100644 index 0000000000..1f01d26083 --- /dev/null +++ b/changelogs/fragments/6100-jenkins_plugin.yml @@ -0,0 +1,2 @@ +bugfixes: + - "jenkins_plugin - fix error due to undefined variable when updates file is not downloaded (https://github.com/ansible-collections/community.general/pull/6100)." diff --git a/plugins/modules/jenkins_plugin.py b/plugins/modules/jenkins_plugin.py index b3ebf3f93c..2fbc83e03f 100644 --- a/plugins/modules/jenkins_plugin.py +++ b/plugins/modules/jenkins_plugin.py @@ -641,6 +641,8 @@ class JenkinsPlugin(object): self.module.fail_json( msg="Cannot close the tmp updates file %s." % tmp_updates_file, details=to_native(e)) + else: + tmp_updates_file = updates_file # Open the updates file try: @@ -651,15 +653,15 @@ class JenkinsPlugin(object): data = json.loads(f.readline()) except IOError as e: self.module.fail_json( - msg="Cannot open temporal updates file.", + msg="Cannot open%s updates file." % (" temporary" if tmp_updates_file != updates_file else ""), details=to_native(e)) except Exception as e: self.module.fail_json( - msg="Cannot load JSON data from the tmp updates file.", + msg="Cannot load JSON data from the%s updates file." % (" temporary" if tmp_updates_file != updates_file else ""), details=to_native(e)) # Move the updates file to the right place if we could read it - if download_updates: + if tmp_updates_file != updates_file: self.module.atomic_move(tmp_updates_file, updates_file) # Check if we have the plugin data available