1
0
mirror of https://github.com/ansible-collections/community.general.git synced 2025-08-01 06:06:57 +03: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:
Juan Manuel Casanova González
2023-09-10 21:28:55 +02:00
committed by GitHub
parent 517e2d48eb
commit afeeb89af6
6 changed files with 464 additions and 3 deletions

View File

@ -75,6 +75,11 @@ class JenkinsMock():
def get_build_info(self, name, build_number):
if name == "host-delete":
raise jenkins.JenkinsException("job {0} number {1} does not exist".format(name, build_number))
elif name == "create-detached":
return {
"building": True,
"result": None
}
return {
"building": True,
"result": "SUCCESS"
@ -222,3 +227,38 @@ class TestJenkinsBuild(unittest.TestCase):
"token": "xyz"
})
jenkins_build.main()
@patch('ansible_collections.community.general.plugins.modules.jenkins_build.test_dependencies')
@patch('ansible_collections.community.general.plugins.modules.jenkins_build.JenkinsBuild.get_jenkins_connection')
@patch('ansible_collections.community.general.plugins.modules.jenkins_build.JenkinsBuild.get_build_status')
def test_module_create_build_without_detach(self, build_status, jenkins_connection, test_deps):
test_deps.return_value = None
jenkins_connection.return_value = JenkinsMock()
build_status.return_value = JenkinsBuildMock().get_build_status()
with self.assertRaises(AnsibleExitJson) as return_json:
set_module_args({
"name": "create-detached",
"user": "abc",
"token": "xyz"
})
jenkins_build.main()
self.assertFalse(return_json.exception.args[0]['changed'])
@patch('ansible_collections.community.general.plugins.modules.jenkins_build.test_dependencies')
@patch('ansible_collections.community.general.plugins.modules.jenkins_build.JenkinsBuild.get_jenkins_connection')
def test_module_create_build_detached(self, jenkins_connection, test_deps):
test_deps.return_value = None
jenkins_connection.return_value = JenkinsMock()
with self.assertRaises(AnsibleExitJson) as return_json:
set_module_args({
"name": "create-detached",
"user": "abc",
"token": "xyz",
"detach": True
})
jenkins_build.main()
self.assertTrue(return_json.exception.args[0]['changed'])