mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-19 03:10:22 -07:00
Improvements to the jenkins_build module and new jenkins_build_info module (#7204)
* Add detach option so the task doesn't wait until the Jenkins job is finished * Add new time_between_checks to be able to configure the sleep time between requests * New jenkins_build_info to get information about a specific build * Add version_added to the new module * Add changelog fragment for jenkins_build changes * Fix tests that required the python-jenkins module * Remove tests that failed Doesn't really make sense to test that with a mock * Fix pep8 error * Update maintainers for the jenkins_build and jenkins_build_info modules * Improve format and add link to PR * Move version_added documentation to the right file * Fix incorrect examples * Improve text format * Fix incorrect code style * Fix incorrect YAML for documentation * Add version_added documentation to the new options
This commit is contained in:
parent
517e2d48eb
commit
afeeb89af6
6 changed files with 464 additions and 3 deletions
|
@ -20,6 +20,7 @@ requirements:
|
|||
author:
|
||||
- Brett Milford (@brettmilford)
|
||||
- Tong He (@unnecessary-username)
|
||||
- Juan Casanova (@juanmcasanova)
|
||||
extends_documentation_fragment:
|
||||
- community.general.attributes
|
||||
attributes:
|
||||
|
@ -65,6 +66,19 @@ options:
|
|||
description:
|
||||
- User to authenticate with the Jenkins server.
|
||||
type: str
|
||||
detach:
|
||||
description:
|
||||
- Enable detached mode to not wait for the build end.
|
||||
default: false
|
||||
type: bool
|
||||
version_added: 7.4.0
|
||||
time_between_checks:
|
||||
description:
|
||||
- Time in seconds to wait between requests to the Jenkins server.
|
||||
- This times must be higher than the configured quiet time for the job.
|
||||
default: 10
|
||||
type: int
|
||||
version_added: 7.4.0
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -152,6 +166,8 @@ class JenkinsBuild:
|
|||
self.user = module.params.get('user')
|
||||
self.jenkins_url = module.params.get('url')
|
||||
self.build_number = module.params.get('build_number')
|
||||
self.detach = module.params.get('detach')
|
||||
self.time_between_checks = module.params.get('time_between_checks')
|
||||
self.server = self.get_jenkins_connection()
|
||||
|
||||
self.result = {
|
||||
|
@ -235,7 +251,14 @@ class JenkinsBuild:
|
|||
build_status = self.get_build_status()
|
||||
|
||||
if build_status['result'] is None:
|
||||
sleep(10)
|
||||
# If detached mode is active mark as success, we wouldn't be able to get here if it didn't exist
|
||||
if self.detach:
|
||||
result['changed'] = True
|
||||
result['build_info'] = build_status
|
||||
|
||||
return result
|
||||
|
||||
sleep(self.time_between_checks)
|
||||
self.get_result()
|
||||
else:
|
||||
if self.state == "stopped" and build_status['result'] == "ABORTED":
|
||||
|
@ -273,6 +296,8 @@ def main():
|
|||
token=dict(no_log=True),
|
||||
url=dict(default="http://localhost:8080"),
|
||||
user=dict(),
|
||||
detach=dict(type='bool', default=False),
|
||||
time_between_checks=dict(type='int', default=10),
|
||||
),
|
||||
mutually_exclusive=[['password', 'token']],
|
||||
required_if=[['state', 'absent', ['build_number'], True], ['state', 'stopped', ['build_number'], True]],
|
||||
|
@ -288,7 +313,7 @@ def main():
|
|||
else:
|
||||
jenkins_build.absent_build()
|
||||
|
||||
sleep(10)
|
||||
sleep(jenkins_build.time_between_checks)
|
||||
result = jenkins_build.get_result()
|
||||
module.exit_json(**result)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue