mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 22:33:25 +00:00
[PR #7204/afeeb89a backport][stable-7] Improvements to the jenkins_build module and new jenkins_build_info module (#7234)
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
(cherry picked from commit afeeb89af6)
Co-authored-by: Juan Manuel Casanova González <juan.casanova.922@gmail.com>
This commit is contained in:
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user