Skip to content

Commit 2e39d0b

Browse files
Add pull link to changelog and modify install latest deps function
1 parent c47e285 commit 2e39d0b

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
bugfixes:
2-
- "jenkins_plugin - install latest compatible version instead of latest (https://github.com/ansible-collections/community.general/issues/854)."
3-
- "jenkins_plugin - seperate Jenkins and external URL credentials (https://github.com/ansible-collections/community.general/issues/4419)."
2+
- "jenkins_plugin - install latest compatible version instead of latest (https://github.com/ansible-collections/community.general/issues/854, https://github.com/ansible-collections/community.general/pull/10346)."
3+
- "jenkins_plugin - separate Jenkins and external URL credentials (https://github.com/ansible-collections/community.general/issues/4419, https://github.com/ansible-collections/community.general/pull/10346)."
44

55
minor_changes:
6-
- "jenkins_plugin - install dependencies for specific version (https://github.com/ansible-collections/community.general/issue/4995)."
6+
- "jenkins_plugin - install dependencies for specific version (https://github.com/ansible-collections/community.general/issue/4995, https://github.com/ansible-collections/community.general/pull/10346)."

plugins/modules/jenkins_plugin.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@
124124
with_dependencies:
125125
description:
126126
- Defines whether to install plugin dependencies.
127-
- In earlier versions, this option had no effect when a specific C(version) was set.
128-
- Since community.general 11.1.0, dependencies are also installed for versioned plugins.
127+
- In earlier versions, this option had no effect when a specific O(version) was set.
128+
Since community.general 11.1.0, dependencies are also installed for versioned plugins.
129129
type: bool
130130
default: true
131131
@@ -519,7 +519,10 @@ def _install_dependencies(self):
519519
dep_params = self.params.copy()
520520
dep_params['name'] = dep_name
521521
dep_params['version'] = dep_version
522-
dep_module = self.module
522+
dep_module = AnsibleModule(
523+
argument_spec=self.module.argument_spec,
524+
supports_check_mode=self.module.check_mode
525+
)
523526
dep_module.params = dep_params
524527
dep_plugin = JenkinsPlugin(dep_module)
525528
if not dep_plugin.install():
@@ -687,27 +690,27 @@ def _get_latest_compatible_plugin_version(self, plugin_name=None):
687690
cache_path = "{}/ansible_jenkins_plugin_cache.json".format(self.params['jenkins_home'])
688691

689692
try: # Check if file is saved localy
690-
with open(cache_path, "r") as f:
693+
if os.path.exists(cache_path):
691694
file_mtime = os.path.getmtime(cache_path)
692-
now = time.time()
693-
if now - file_mtime < 86400:
694-
plugin_data = json.load(f)
695-
else:
696-
raise FileNotFoundError("Cache file is outdated.")
697-
except Exception:
698-
response, info = fetch_url(self.module, "https://updates.jenkins.io/current/plugin-versions.json") # Get list of plugins and their dependencies
699-
700-
if info['status'] != 200:
701-
self.module.fail_json(msg="Failed to fetch plugin-versions.json", details=info)
695+
else:
696+
file_mtime = 0
702697

703-
try:
698+
now = time.time()
699+
if now - file_mtime >= 86400:
700+
response, info = fetch_url(self.module, "https://updates.jenkins.io/current/plugin-versions.json")
701+
if info['status'] != 200:
702+
self.module.fail_json(msg="Failed to fetch plugin-versions.json", details=info)
704703
plugin_data = json.loads(to_native(response.read()), object_pairs_hook=OrderedDict)
705704

706705
# Save it to file for next time
707706
with open(cache_path, "w") as f:
708707
json.dump(plugin_data, f)
709-
except Exception as e:
710-
self.module.fail_json(msg="Failed to parse plugin-versions.json", details=to_native(e))
708+
709+
with open(cache_path, "r") as f:
710+
plugin_data = json.load(f)
711+
712+
except Exception as e:
713+
self.module.fail_json(msg="Failed to parse plugin-versions.json", details=to_native(e))
711714

712715
plugin_versions = plugin_data.get("plugins", {}).get(name)
713716
if not plugin_versions:

0 commit comments

Comments
 (0)