job cache now varies by remote url

When updating different Jenkins installations, JJB would end up
invalidating the job cache.  By adding the jenkins.url in the cache file
name, we can maintain a job cache per remote Jenkins instance.

Name of the cache file is based on Jenkins URL.

Change-Id: Ib9c08d8029267729e7a030a4e8bc0a9f05eb8ce3
Reviewed-on: https://review.openstack.org/24404
Reviewed-by: Arnaud Fabre <fabre.arnaud@gmail.com>
Approved: Jeremy Stanley <fungi@yuggoth.org>
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Tested-by: Jenkins
This commit is contained in:
Antoine Musso 2013-03-14 06:47:11 +01:00 committed by Jenkins
parent cd3cbd91cb
commit 3e6dac4602
2 changed files with 13 additions and 9 deletions
doc/source
jenkins_jobs

@ -66,12 +66,13 @@ can run::
jenkins-jobs update /path/to/config
Which will upload the configurations to Jenkins if needed. Jenkins
Job Builder maintains a cache of previously configured jobs, so that
you can run that command as often as you like, and it will only update
the configuration in Jenkins if the defined configuration has changed
since the last time it was run. Note: if you modify a job directly in
Jenkins, jenkins-jobs will not know about it and will not update it.
Which will upload the configurations to Jenkins if needed. Jenkins Job
Builder maintains, for each host, a cache of previously configured jobs,
so that you can run that command as often as you like, and it will only
update the configuration in Jenkins if the defined configuration has
changed since the last time it was run. Note: if you modify a job
directly in Jenkins, jenkins-jobs will not know about it and will not
update it.
To update a specific list of jobs, simply pass them as additional
arguments after the configuration path. To update Foo1 and Foo2 run::

@ -228,9 +228,12 @@ class XmlJob(object):
class CacheStorage(object):
def __init__(self):
def __init__(self, jenkins_url):
cache_dir = self.get_cache_dir()
self.cachefilename = os.path.join(cache_dir, 'jenkins_jobs_cache.yml')
# One cache per remote Jenkins URL:
host_vary = re.sub('[^A-Za-z0-9\-\~]', '_', jenkins_url)
self.cachefilename = os.path.join(
cache_dir, 'cache-host-jobs-' + host_vary + '.yml')
try:
yfile = file(self.cachefilename, 'r')
except IOError:
@ -300,7 +303,7 @@ class Builder(object):
def __init__(self, jenkins_url, jenkins_user, jenkins_password,
config=None):
self.jenkins = Jenkins(jenkins_url, jenkins_user, jenkins_password)
self.cache = CacheStorage()
self.cache = CacheStorage(jenkins_url)
self.global_config = config
def delete_job(self, name):