diff --git a/doc/source/installation.rst b/doc/source/installation.rst index 7dd3d9a10..fd8f8b3e1 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -114,6 +114,12 @@ jenkins section **url** The base URL for your Jenkins installation. +**query_plugins_info** + Whether to query the Jenkins instance for plugin info when a configuration + file is provided. If a configuration file is not provided `jenkins-jobs` will + ignore this setting and skip querying for plugin information. True by + default. + Running ------- diff --git a/etc/jenkins_jobs.ini-sample b/etc/jenkins_jobs.ini-sample index 58b670680..bb1744742 100644 --- a/etc/jenkins_jobs.ini-sample +++ b/etc/jenkins_jobs.ini-sample @@ -10,6 +10,7 @@ allow_duplicates=False user=jenkins password=1234567890abcdef1234567890abcdef url=https://jenkins.example.com +query_plugins_info=False ##### This is deprecated, use job_builder section instead #ignore_cache=True diff --git a/jenkins_jobs/cmd.py b/jenkins_jobs/cmd.py index 8c1105994..f992add12 100755 --- a/jenkins_jobs/cmd.py +++ b/jenkins_jobs/cmd.py @@ -42,6 +42,7 @@ allow_empty_variables=False url=http://localhost:8080/ user= password= +query_plugins_info=True [hipchat] authtoken=dummy @@ -238,6 +239,11 @@ def execute(options, config): if not isinstance(plugins_info, list): raise JenkinsJobsException("{0} must contain a Yaml list!" .format(options.plugins_info_path)) + elif (not options.conf or not + config.getboolean("jenkins", "query_plugins_info")): + logger.debug("Skipping plugin info retrieval") + plugins_info = {} + if options.allow_empty_variables is not None: config.set('job_builder', 'allow_empty_variables', diff --git a/tests/cmd/fixtures/disable-query-plugins.conf b/tests/cmd/fixtures/disable-query-plugins.conf new file mode 100644 index 000000000..02f5a9391 --- /dev/null +++ b/tests/cmd/fixtures/disable-query-plugins.conf @@ -0,0 +1,3 @@ +[jenkins] +url=http://test-jenkins.with.non.default.url:8080/ +query_plugins_info=False diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py index 037c29539..a1697fe47 100644 --- a/tests/cmd/subcommands/test_test.py +++ b/tests/cmd/subcommands/test_test.py @@ -264,3 +264,30 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase): self.fail("jenkins.JenkinsException propagated to main") except: pass # only care about jenkins.JenkinsException for now + + @mock.patch('jenkins.Jenkins.get_plugins_info') + def test_skip_plugin_retrieval_if_no_config_provided( + self, get_plugins_info_mock): + """ + Verify that retrieval of information from Jenkins instance about its + plugins will be skipped when run if no config file provided. + """ + with mock.patch('sys.stdout'): + cmd.main(['test', os.path.join(self.fixtures_path, + 'cmd-001.yaml')]) + self.assertFalse(get_plugins_info_mock.called) + + @mock.patch('jenkins.Jenkins.get_plugins_info') + def test_skip_plugin_retrieval_if_disabled(self, get_plugins_info_mock): + """ + Verify that retrieval of information from Jenkins instance about its + plugins will be skipped when run if a config file provided and disables + querying through a config option. + """ + with mock.patch('sys.stdout'): + cmd.main(['--conf', + os.path.join(self.fixtures_path, + 'disable-query-plugins.conf'), + 'test', + os.path.join(self.fixtures_path, 'cmd-001.yaml')]) + self.assertFalse(get_plugins_info_mock.called)