Only query jenkins plugins if config provided

Limit querying for plugin information from Jenkins to where an explicit
configuration file has been provided. Where no file is provided, should
avoid any requests that could result in attempting connections.

Add a config options to control this behaviour explicitly so that if a
config file is provided, it may explicitly disable querying jenkins for
additional information from plugins.

The `test` command can use this behaviour to ensure that a basic run is
possible without providing any configuration files, and can be
explicitly configured to disable querying should a config file be used
for testing.

Ensure the default sample configuration skips attempting to query so
that users may use it as a quick test for a working installation without
any network or valid jenkins url dependencies.

Change-Id: I641a3188013debf3765aaff109c4f5fa82a4cedb
This commit is contained in:
Darragh Bailey 2015-02-24 19:19:13 +00:00
parent d976466c10
commit f68831bd2e
5 changed files with 43 additions and 0 deletions

View File

@ -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
-------

View File

@ -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

View File

@ -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',

View File

@ -0,0 +1,3 @@
[jenkins]
url=http://test-jenkins.with.non.default.url:8080/
query_plugins_info=False

View File

@ -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)