summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanh Ha <zxiiro@gmail.com>2019-08-23 09:14:39 -0400
committerSorin Sbarnea <ssbarnea@redhat.com>2019-09-09 19:23:24 +0100
commit4d90c187a945c04b9949d5ee7738a049dd634897 (patch)
tree106bf6e05ad1f2260823e7cd68651b535b8ac3ef
parentead185134d8aa5d3d0974207356de6c4fdb2e6e8 (diff)
downloadpython-jenkins-job-builder-4d90c187a945c04b9949d5ee7738a049dd634897.tar.gz
python-jenkins-job-builder-4d90c187a945c04b9949d5ee7738a049dd634897.tar.xz
python-jenkins-job-builder-4d90c187a945c04b9949d5ee7738a049dd634897.zip
Auto-generated output from python-black
Please review the following patch containing the code changes in the repo. This patch is a transition patch and is the auto-generated output of the python-black tool. Change-Id: I2d2de71da8a105fb62b561899ae78441ddab4032 Signed-off-by: Thanh Ha <zxiiro@gmail.com>
-rw-r--r--doc/source/conf.py71
-rwxr-xr-xjenkins_jobs/alphanum.py20
-rw-r--r--jenkins_jobs/builder.py229
-rw-r--r--jenkins_jobs/cache.py45
-rw-r--r--jenkins_jobs/cli/entry.py94
-rw-r--r--jenkins_jobs/cli/parser.py97
-rw-r--r--jenkins_jobs/cli/subcommand/base.py21
-rw-r--r--jenkins_jobs/cli/subcommand/delete.py38
-rw-r--r--jenkins_jobs/cli/subcommand/delete_all.py44
-rw-r--r--jenkins_jobs/cli/subcommand/get_plugins_info.py23
-rw-r--r--jenkins_jobs/cli/subcommand/list.py30
-rw-r--r--jenkins_jobs/cli/subcommand/test.py61
-rw-r--r--jenkins_jobs/cli/subcommand/update.py119
-rw-r--r--jenkins_jobs/config.py208
-rw-r--r--jenkins_jobs/errors.py51
-rw-r--r--jenkins_jobs/formatter.py39
-rw-r--r--jenkins_jobs/local_yaml.py148
-rw-r--r--jenkins_jobs/modules/builders.py2807
-rw-r--r--jenkins_jobs/modules/general.py111
-rw-r--r--jenkins_jobs/modules/helpers.py740
-rw-r--r--jenkins_jobs/modules/hipchat_notif.py112
-rw-r--r--jenkins_jobs/modules/hudson_model.py45
-rw-r--r--jenkins_jobs/modules/metadata.py57
-rw-r--r--jenkins_jobs/modules/notifications.py54
-rw-r--r--jenkins_jobs/modules/parameters.py591
-rw-r--r--jenkins_jobs/modules/project_externaljob.py2
-rw-r--r--jenkins_jobs/modules/project_flow.py12
-rw-r--r--jenkins_jobs/modules/project_folder.py21
-rw-r--r--jenkins_jobs/modules/project_freestyle.py2
-rw-r--r--jenkins_jobs/modules/project_matrix.py177
-rwxr-xr-xjenkins_jobs/modules/project_maven.py162
-rw-r--r--jenkins_jobs/modules/project_multibranch.py1168
-rw-r--r--jenkins_jobs/modules/project_multijob.py5
-rw-r--r--jenkins_jobs/modules/project_pipeline.py49
-rw-r--r--jenkins_jobs/modules/project_workflow.py27
-rw-r--r--jenkins_jobs/modules/properties.py654
-rw-r--r--jenkins_jobs/modules/publishers.py4829
-rw-r--r--jenkins_jobs/modules/reporters.py44
-rw-r--r--jenkins_jobs/modules/scm.py1252
-rw-r--r--jenkins_jobs/modules/triggers.py1701
-rw-r--r--jenkins_jobs/modules/view_all.py13
-rw-r--r--jenkins_jobs/modules/view_jobfilters.py202
-rw-r--r--jenkins_jobs/modules/view_list.py212
-rw-r--r--jenkins_jobs/modules/view_pipeline.py60
-rw-r--r--jenkins_jobs/modules/wrappers.py1881
-rw-r--r--jenkins_jobs/modules/zuul.py218
-rw-r--r--jenkins_jobs/parallel.py24
-rw-r--r--jenkins_jobs/parser.py289
-rw-r--r--jenkins_jobs/registry.py99
-rw-r--r--jenkins_jobs/sphinx/yaml.py40
-rw-r--r--jenkins_jobs/utils.py32
-rw-r--r--jenkins_jobs/version.py2
-rw-r--r--jenkins_jobs/xml_config.py41
-rw-r--r--setup.cfg8
-rw-r--r--setup.py4
-rw-r--r--tests/base.py209
-rw-r--r--tests/builders/test_builders.py2
-rw-r--r--tests/cachestorage/test_cachestorage.py19
-rw-r--r--tests/cmd/subcommands/test_delete.py48
-rw-r--r--tests/cmd/subcommands/test_delete_all.py26
-rw-r--r--tests/cmd/subcommands/test_list.py79
-rw-r--r--tests/cmd/subcommands/test_test.py338
-rw-r--r--tests/cmd/subcommands/test_update.py96
-rw-r--r--tests/cmd/test_cmd.py11
-rw-r--r--tests/cmd/test_config.py107
-rw-r--r--tests/cmd/test_recurse_path.py79
-rw-r--r--tests/duplicates/test_duplicates.py4
-rw-r--r--tests/errors/test_exceptions.py39
-rw-r--r--tests/general/test_general.py2
-rw-r--r--tests/hipchat/test_hipchat.py2
-rw-r--r--tests/jenkins_manager/test_manager.py55
-rw-r--r--tests/jsonparser/test_jsonparser.py4
-rw-r--r--tests/localyaml/test_localyaml.py45
-rw-r--r--tests/macros/test_macros.py2
-rw-r--r--tests/moduleregistry/test_moduleregistry.py79
-rw-r--r--tests/modules/test_helpers.py117
-rw-r--r--tests/multibranch/test_multibranch.py6
-rw-r--r--tests/notifications/test_notifications.py2
-rw-r--r--tests/parallel/test_parallel.py13
-rw-r--r--tests/parameters/test_parameters.py2
-rw-r--r--tests/properties/test_properties.py2
-rw-r--r--tests/publishers/test_publishers.py2
-rw-r--r--tests/reporters/test_reporters.py2
-rw-r--r--tests/scm/test_scm.py2
-rw-r--r--tests/triggers/test_triggers.py2
-rw-r--r--tests/views/test_views.py6
-rw-r--r--tests/wrappers/test_wrappers.py2
-rw-r--r--tests/xml_config/test_xml_config.py18
-rw-r--r--tests/yamlparser/test_yamlparser.py24
89 files changed, 10537 insertions, 9994 deletions
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 08fe56d9..57ae43fd 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -18,8 +18,8 @@ from jenkins_jobs.version import version_info as jenkins_jobs_version
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-sys.path.insert(0, os.path.abspath('../..'))
-sys.path.insert(0, os.path.abspath('../../jenkins_jobs/modules'))
+sys.path.insert(0, os.path.abspath("../.."))
+sys.path.insert(0, os.path.abspath("../../jenkins_jobs/modules"))
# -- General configuration ----------------------------------------------------
@@ -28,25 +28,30 @@ sys.path.insert(0, os.path.abspath('../../jenkins_jobs/modules'))
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage',
- 'jenkins_jobs.sphinx.yaml', 'sphinxcontrib.programoutput',
- 'sphinx.ext.extlinks', 'sphinx.ext.doctest']
+extensions = [
+ "sphinx.ext.autodoc",
+ "sphinx.ext.coverage",
+ "jenkins_jobs.sphinx.yaml",
+ "sphinxcontrib.programoutput",
+ "sphinx.ext.extlinks",
+ "sphinx.ext.doctest",
+]
# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
+templates_path = ["_templates"]
# The suffix of source filenames.
-source_suffix = '.rst'
+source_suffix = ".rst"
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
-master_doc = 'index'
+master_doc = "index"
# General information about the project.
-project = u'Jenkins Job Builder'
-copyright = u'2012, Jenkins Job Builder Maintainers'
+project = u"Jenkins Job Builder"
+copyright = u"2012, Jenkins Job Builder Maintainers"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -86,7 +91,7 @@ exclude_patterns = []
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
+pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
@@ -96,7 +101,7 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
-html_theme = 'default'
+html_theme = "default"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@@ -169,7 +174,7 @@ html_theme = 'default'
# html_file_suffix = None
# Output file base name for HTML help builder.
-htmlhelp_basename = 'JenkinsJobBuilderdoc'
+htmlhelp_basename = "JenkinsJobBuilderdoc"
# -- Options for LaTeX output -------------------------------------------------
@@ -177,10 +182,8 @@ htmlhelp_basename = 'JenkinsJobBuilderdoc'
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
-
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
-
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
@@ -189,8 +192,13 @@ latex_elements = {
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
- ('index', 'JenkinsJobBuilder.tex', u'Jenkins Job Builder Documentation',
- u'Jenkins Job Builder Maintainers', 'manual'),
+ (
+ "index",
+ "JenkinsJobBuilder.tex",
+ u"Jenkins Job Builder Documentation",
+ u"Jenkins Job Builder Maintainers",
+ "manual",
+ )
]
# The name of an image file (relative to this directory) to place at the top of
@@ -225,8 +233,13 @@ linkcheck_timeout = 15
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
- ('index', 'jenkins-jobs', u'Jenkins Job Builder Documentation',
- [u'Jenkins Job Builder Maintainers'], 1)
+ (
+ "index",
+ "jenkins-jobs",
+ u"Jenkins Job Builder Documentation",
+ [u"Jenkins Job Builder Maintainers"],
+ 1,
+ )
]
# If true, show URL addresses after external links.
@@ -239,10 +252,15 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- ('index', 'JenkinsJobBuilder', u'Jenkins Job Builder Documentation',
- u'Jenkins Job Builder Maintainers',
- 'JenkinsJobBuilder', 'One line description of project.',
- 'Miscellaneous'),
+ (
+ "index",
+ "JenkinsJobBuilder",
+ u"Jenkins Job Builder Documentation",
+ u"Jenkins Job Builder Maintainers",
+ "JenkinsJobBuilder",
+ "One line description of project.",
+ "Miscellaneous",
+ )
]
# Documents to append as an appendix to all manuals.
@@ -254,6 +272,7 @@ texinfo_documents = [
# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'
-extlinks = {'jenkins-wiki': ('https://wiki.jenkins.io/display/JENKINS/%s',
- None),
- 'jenkins-plugins': ('https://plugins.jenkins.io/%s', None)}
+extlinks = {
+ "jenkins-wiki": ("https://wiki.jenkins.io/display/JENKINS/%s", None),
+ "jenkins-plugins": ("https://plugins.jenkins.io/%s", None),
+}
diff --git a/jenkins_jobs/alphanum.py b/jenkins_jobs/alphanum.py
index 7eb44bfc..6d2f9673 100755
--- a/jenkins_jobs/alphanum.py
+++ b/jenkins_jobs/alphanum.py
@@ -42,9 +42,9 @@ def getchunk(item):
# Subtract the matched portion from the original string
# if there was a match, otherwise set it to ""
- item = (item[itemchunk.end():] if itemchunk else "")
+ item = item[itemchunk.end() :] if itemchunk else ""
# Don't return the match object, just the text
- itemchunk = (itemchunk.group() if itemchunk else "")
+ itemchunk = itemchunk.group() if itemchunk else ""
return (itemchunk, item)
@@ -54,28 +54,28 @@ def cmp(a, b):
def alphanum(a, b):
- a = a.name if hasattr(a, 'name') else str(a)
- b = b.name if hasattr(b, 'name') else str(b)
+ a = a.name if hasattr(a, "name") else str(a)
+ b = b.name if hasattr(b, "name") else str(b)
n = 0
- while (n == 0):
+ while n == 0:
# Get a chunk and the original string with the chunk subtracted
(ac, a) = getchunk(a)
(bc, b) = getchunk(b)
# Both items contain only letters
- if (re_letters.match(ac) and re_letters.match(bc)):
+ if re_letters.match(ac) and re_letters.match(bc):
n = cmp(ac, bc)
else:
# Both items contain only numbers
- if (re_numbers.match(ac) and re_numbers.match(bc)):
+ if re_numbers.match(ac) and re_numbers.match(bc):
n = cmp(int(ac), int(bc))
# item has letters and one item has numbers, or one item is empty
else:
n = cmp(ac, bc)
# Prevent deadlocks
- if (n == 0):
+ if n == 0:
n = 1
return n
@@ -105,5 +105,5 @@ class AlphanumSort(object):
if __name__ == "__main__":
- mylist = ['a2', 'a1', 'a10', 'a']
- assert sorted(mylist, key=AlphanumSort) == ['a', 'a1', 'a2', 'a10']
+ mylist = ["a2", "a1", "a10", "a"]
+ assert sorted(mylist, key=AlphanumSort) == ["a", "a1", "a2", "a10"]
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py
index 32c0c39b..180d49d0 100644
--- a/jenkins_jobs/builder.py
+++ b/jenkins_jobs/builder.py
@@ -34,9 +34,7 @@ from jenkins_jobs.constants import MAGIC_MANAGE_STRING
from jenkins_jobs.parallel import concurrent
from jenkins_jobs import utils
-__all__ = [
- "JenkinsManager"
-]
+__all__ = ["JenkinsManager"]
logger = logging.getLogger(__name__)
@@ -44,22 +42,22 @@ _DEFAULT_TIMEOUT = object()
class JenkinsManager(object):
-
def __init__(self, jjb_config):
- url = jjb_config.jenkins['url']
- user = jjb_config.jenkins['user']
- password = jjb_config.jenkins['password']
- timeout = jjb_config.jenkins['timeout']
+ url = jjb_config.jenkins["url"]
+ user = jjb_config.jenkins["user"]
+ password = jjb_config.jenkins["password"]
+ timeout = jjb_config.jenkins["timeout"]
if timeout != _DEFAULT_TIMEOUT:
self.jenkins = jenkins.Jenkins(url, user, password, timeout)
else:
self.jenkins = jenkins.Jenkins(url, user, password)
- self.cache = JobCache(jjb_config.jenkins['url'],
- flush=jjb_config.builder['flush_cache'])
+ self.cache = JobCache(
+ jjb_config.jenkins["url"], flush=jjb_config.builder["flush_cache"]
+ )
- self._plugins_list = jjb_config.builder['plugins_info']
+ self._plugins_list = jjb_config.builder["plugins_info"]
self._jobs = None
self._job_list = None
self._views = None
@@ -69,16 +67,15 @@ class JenkinsManager(object):
def _setup_output(self, output, item, config_xml=False):
output_dir = output
output_fn = os.path.join(output, item)
- if '/' in item:
+ if "/" in item:
# in item folder
output_fn = os.path.join(output, os.path.normpath(item))
output_dir = os.path.dirname(output_fn)
# if in a folder, re-adding name to the directory here
if config_xml:
- output_dir = os.path.join(
- output_dir, os.path.basename(item))
- output_fn = os.path.join(output_dir, 'config.xml')
+ output_dir = os.path.join(output_dir, os.path.basename(item))
+ output_fn = os.path.join(output_dir, "config.xml")
if output_dir != output:
logger.debug("Creating directory %s" % output_dir)
@@ -102,36 +99,43 @@ class JenkinsManager(object):
def job_list(self):
if self._job_list is None:
# python-jenkins uses 'fullname' for folder/name combination
- self._job_list = set(job['fullname'] for job in self.jobs)
+ self._job_list = set(job["fullname"] for job in self.jobs)
return self._job_list
def _job_format(self, job_name):
# returns job name or url based on config option
- if self._jjb_config.builder['print_job_urls']:
- return self._jjb_config.jenkins['url'] + \
- '/job/' + quote(
- '/job/'.join(job_name.split('/')).encode('utf8')) + '/'
+ if self._jjb_config.builder["print_job_urls"]:
+ return (
+ self._jjb_config.jenkins["url"]
+ + "/job/"
+ + quote("/job/".join(job_name.split("/")).encode("utf8"))
+ + "/"
+ )
else:
return job_name
def _view_format(self, view_name):
# returns job name or url based on config option
- if self._jjb_config.builder['print_job_urls']:
- parts = view_name.split('/')
- return self._jjb_config.jenkins['url'] + \
- ''.join(['/job/' + item for item in parts[:-1]]) + \
- '/view/' + parts[-1] + '/'
+ if self._jjb_config.builder["print_job_urls"]:
+ parts = view_name.split("/")
+ return (
+ self._jjb_config.jenkins["url"]
+ + "".join(["/job/" + item for item in parts[:-1]])
+ + "/view/"
+ + parts[-1]
+ + "/"
+ )
else:
return view_name
def update_job(self, job_name, xml):
if self.is_job(job_name):
- logger.info("Reconfiguring jenkins job {0}".format(
- self._job_format(job_name)))
+ logger.info(
+ "Reconfiguring jenkins job {0}".format(self._job_format(job_name))
+ )
self.jenkins.reconfig_job(job_name, xml)
else:
- logger.info("Creating jenkins job {0}".format(
- self._job_format(job_name)))
+ logger.info("Creating jenkins job {0}".format(self._job_format(job_name)))
self.jenkins.create_job(job_name, xml)
def is_job(self, job_name, use_cache=True):
@@ -143,7 +147,7 @@ class JenkinsManager(object):
def get_job_md5(self, job_name):
xml = self.jenkins.get_job_config(job_name)
- return hashlib.md5(xml.encode('utf-8')).hexdigest()
+ return hashlib.md5(xml.encode("utf-8")).hexdigest()
def delete_job(self, job_name):
if self.is_job(job_name):
@@ -162,10 +166,10 @@ class JenkinsManager(object):
logger.warning(
"Unable to retrieve Jenkins Plugin Info from {0},"
" using default empty plugins info list.".format(
- self.jenkins.server))
- plugins_list = [{'shortName': '',
- 'version': '',
- 'longName': ''}]
+ self.jenkins.server
+ )
+ )
+ plugins_list = [{"shortName": "", "version": "", "longName": ""}]
else:
raise
logger.debug("Jenkins Plugin Info {0}".format(pformat(plugins_list)))
@@ -181,7 +185,7 @@ class JenkinsManager(object):
def is_managed(self, job_name):
xml = self.jenkins.get_job_config(job_name)
try:
- out = XML.fromstring(xml.encode('utf-8'))
+ out = XML.fromstring(xml.encode("utf-8"))
description = out.find(".//description").text
return description.endswith(MAGIC_MANAGE_STRING)
except (TypeError, AttributeError):
@@ -202,18 +206,21 @@ class JenkinsManager(object):
for job in jobs:
# python-jenkins stores the folder and name as 'fullname'
# Check if the job was deleted when his parent folder was deleted
- if job['fullname'] not in keep and \
- self.is_job(job['fullname'], use_cache=False):
- if self.is_managed(job['fullname']):
- logger.info("Removing obsolete jenkins job {0}"
- .format(job['fullname']))
- self.delete_job(job['fullname'])
+ if job["fullname"] not in keep and self.is_job(
+ job["fullname"], use_cache=False
+ ):
+ if self.is_managed(job["fullname"]):
+ logger.info(
+ "Removing obsolete jenkins job {0}".format(job["fullname"])
+ )
+ self.delete_job(job["fullname"])
deleted_jobs += 1
else:
- logger.info("Not deleting unmanaged jenkins job %s",
- job['fullname'])
+ logger.info(
+ "Not deleting unmanaged jenkins job %s", job["fullname"]
+ )
else:
- logger.debug("Keeping job %s", job['fullname'])
+ logger.debug("Keeping job %s", job["fullname"])
return deleted_jobs
def delete_jobs(self, jobs):
@@ -221,15 +228,17 @@ class JenkinsManager(object):
logger.info("Removing jenkins job(s): %s" % ", ".join(jobs))
for job in jobs:
self.delete_job(job)
- if(self.cache.is_cached(job)):
- self.cache.set(job, '')
+ if self.cache.is_cached(job):
+ self.cache.set(job, "")
self.cache.save()
def delete_all_jobs(self):
jobs = self.get_jobs()
logger.info("Number of jobs to delete: %d", len(jobs))
- script = ('for(job in jenkins.model.Jenkins.theInstance.getAllItems())'
- ' { job.delete(); }')
+ script = (
+ "for(job in jenkins.model.Jenkins.theInstance.getAllItems())"
+ " { job.delete(); }"
+ )
self.jenkins.run_script(script)
# Need to clear the JJB cache after deletion
self.cache.clear()
@@ -237,8 +246,9 @@ class JenkinsManager(object):
def changed(self, job):
md5 = job.md5()
- changed = (self._jjb_config.builder['ignore_cache'] or
- self.cache.has_changed(job.name, md5))
+ changed = self._jjb_config.builder["ignore_cache"] or self.cache.has_changed(
+ job.name, md5
+ )
if not changed:
logger.debug("'{0}' has not changed".format(job.name))
return changed
@@ -249,15 +259,20 @@ class JenkinsManager(object):
logger.debug("'{0}' does not currently exist".format(job.name))
return exists
- def update_jobs(self, xml_jobs, output=None, n_workers=None,
- existing_only=None, config_xml=False):
+ def update_jobs(
+ self,
+ xml_jobs,
+ output=None,
+ n_workers=None,
+ existing_only=None,
+ config_xml=False,
+ ):
orig = time.time()
logger.info("Number of jobs generated: %d", len(xml_jobs))
xml_jobs.sort(key=AlphanumSort)
- if (output and not hasattr(output, 'write') and
- not os.path.isdir(output)):
+ if output and not hasattr(output, "write") and not os.path.isdir(output):
logger.debug("Creating directory %s" % output)
try:
os.makedirs(output)
@@ -267,11 +282,11 @@ class JenkinsManager(object):
if output:
# ensure only wrapped once
- if hasattr(output, 'write'):
+ if hasattr(output, "write"):
output = utils.wrap_stream(output)
for job in xml_jobs:
- if hasattr(output, 'write'):
+ if hasattr(output, "write"):
# `output` is a file-like object
logger.info("Job name: %s", job.name)
logger.debug("Writing XML to '{0}'".format(output))
@@ -289,39 +304,31 @@ class JenkinsManager(object):
output_fn = self._setup_output(output, job.name, config_xml)
logger.debug("Writing XML to '{0}'".format(output_fn))
- with io.open(output_fn, 'w', encoding='utf-8') as f:
- f.write(job.output().decode('utf-8'))
+ with io.open(output_fn, "w", encoding="utf-8") as f:
+ f.write(job.output().decode("utf-8"))
return xml_jobs, len(xml_jobs)
# Filter out the jobs that did not change
- logging.debug('Filtering %d jobs for changed jobs',
- len(xml_jobs))
+ logging.debug("Filtering %d jobs for changed jobs", len(xml_jobs))
step = time.time()
- jobs = [job for job in xml_jobs
- if self.changed(job)]
- logging.debug("Filtered for changed jobs in %ss",
- (time.time() - step))
+ jobs = [job for job in xml_jobs if self.changed(job)]
+ logging.debug("Filtered for changed jobs in %ss", (time.time() - step))
if existing_only:
# Filter out the jobs not already in the cache
- logging.debug('Filtering %d jobs for existing jobs',
- len(jobs))
+ logging.debug("Filtering %d jobs for existing jobs", len(jobs))
step = time.time()
- jobs = [job for job in jobs
- if self.exists(job)]
- logging.debug("Filtered for existing jobs in %ss",
- (time.time() - step))
+ jobs = [job for job in jobs if self.exists(job)]
+ logging.debug("Filtered for existing jobs in %ss", (time.time() - step))
if not jobs:
return [], 0
# Update the jobs
- logging.debug('Updating jobs')
+ logging.debug("Updating jobs")
step = time.time()
- p_params = [{'job': job} for job in jobs]
- results = self.parallel_update_job(
- n_workers=n_workers,
- concurrent=p_params)
+ p_params = [{"job": job} for job in jobs]
+ results = self.parallel_update_job(n_workers=n_workers, concurrent=p_params)
logging.debug("Parsing results")
# generalize the result parsing, as a concurrent job always returns a
# list
@@ -336,15 +343,13 @@ class JenkinsManager(object):
self.cache.set(j_name, j_md5)
# write cache to disk
self.cache.save()
- logging.debug("Updated %d jobs in %ss",
- len(jobs),
- time.time() - step)
+ logging.debug("Updated %d jobs in %ss", len(jobs), time.time() - step)
logging.debug("Total run took %ss", (time.time() - orig))
return jobs, len(jobs)
@concurrent
def parallel_update_job(self, job):
- self.update_job(job.name, job.output().decode('utf-8'))
+ self.update_job(job.name, job.output().decode("utf-8"))
return (job.name, job.md5())
################
@@ -361,7 +366,7 @@ class JenkinsManager(object):
@property
def view_list(self):
if self._view_list is None:
- self._view_list = set(view['name'] for view in self.views)
+ self._view_list = set(view["name"] for view in self.views)
return self._view_list
def get_views(self, cache=True):
@@ -389,7 +394,7 @@ class JenkinsManager(object):
for view in views:
self.delete_view(view)
if self.cache.is_cached(view):
- self.cache.set(view, '')
+ self.cache.set(view, "")
self.cache.save()
def delete_all_views(self):
@@ -399,22 +404,30 @@ class JenkinsManager(object):
views.pop(0)
logger.info("Number of views to delete: %d", len(views))
for view in views:
- self.delete_view(view['name'])
+ self.delete_view(view["name"])
# Need to clear the JJB cache after deletion
self.cache.clear()
def update_view(self, view_name, xml):
if self.is_view(view_name):
- logger.info("Reconfiguring jenkins view {0}".format(
- self._view_format(view_name)))
+ logger.info(
+ "Reconfiguring jenkins view {0}".format(self._view_format(view_name))
+ )
self.jenkins.reconfig_view(view_name, xml)
else:
- logger.info("Creating jenkins view {0}".format(
- self._view_format(view_name)))
+ logger.info(
+ "Creating jenkins view {0}".format(self._view_format(view_name))
+ )
self.jenkins.create_view(view_name, xml)
- def update_views(self, xml_views, output=None, n_workers=None,
- existing_only=None, config_xml=False):
+ def update_views(
+ self,
+ xml_views,
+ output=None,
+ n_workers=None,
+ existing_only=None,
+ config_xml=False,
+ ):
orig = time.time()
logger.info("Number of views generated: %d", len(xml_views))
@@ -422,11 +435,11 @@ class JenkinsManager(object):
if output:
# ensure only wrapped once
- if hasattr(output, 'write'):
+ if hasattr(output, "write"):
output = utils.wrap_stream(output)
for view in xml_views:
- if hasattr(output, 'write'):
+ if hasattr(output, "write"):
# `output` is a file-like object
logger.info("View name: %s", view.name)
logger.debug("Writing XML to '{0}'".format(output))
@@ -444,39 +457,31 @@ class JenkinsManager(object):
output_fn = self._setup_output(output, view.name, config_xml)
logger.debug("Writing XML to '{0}'".format(output_fn))
- with io.open(output_fn, 'w', encoding='utf-8') as f:
- f.write(view.output().decode('utf-8'))
+ with io.open(output_fn, "w", encoding="utf-8") as f:
+ f.write(view.output().decode("utf-8"))
return xml_views, len(xml_views)
# Filter out the views that did not change
- logging.debug('Filtering %d views for changed views',
- len(xml_views))
+ logging.debug("Filtering %d views for changed views", len(xml_views))
step = time.time()
- views = [view for view in xml_views
- if self.changed(view)]
- logging.debug("Filtered for changed views in %ss",
- (time.time() - step))
+ views = [view for view in xml_views if self.changed(view)]
+ logging.debug("Filtered for changed views in %ss", (time.time() - step))
if existing_only:
# Filter out the jobs not already in the cache
- logging.debug('Filtering %d views for existing jobs',
- len(views))
+ logging.debug("Filtering %d views for existing jobs", len(views))
step = time.time()
- views = [view for view in views
- if self.exists(view)]
- logging.debug("Filtered for existing views in %ss",
- (time.time() - step))
+ views = [view for view in views if self.exists(view)]
+ logging.debug("Filtered for existing views in %ss", (time.time() - step))
if not views:
return [], 0
# Update the views
- logging.debug('Updating views')
+ logging.debug("Updating views")
step = time.time()
- p_params = [{'view': view} for view in views]
- results = self.parallel_update_view(
- n_workers=n_workers,
- concurrent=p_params)
+ p_params = [{"view": view} for view in views]
+ results = self.parallel_update_view(n_workers=n_workers, concurrent=p_params)
logging.debug("Parsing results")
# generalize the result parsing, as a concurrent view always returns a
# list
@@ -491,13 +496,11 @@ class JenkinsManager(object):
self.cache.set(v_name, v_md5)
# write cache to disk
self.cache.save()
- logging.debug("Updated %d views in %ss",
- len(views),
- time.time() - step)
+ logging.debug("Updated %d views in %ss", len(views), time.time() - step)
logging.debug("Total run took %ss", (time.time() - orig))
return views, len(views)
@concurrent
def parallel_update_view(self, view):
- self.update_view(view.name, view.output().decode('utf-8'))
+ self.update_view(view.name, view.output().decode("utf-8"))
return (view.name, view.md5())
diff --git a/jenkins_jobs/cache.py b/jenkins_jobs/cache.py
index d64d6d9f..01769295 100644
--- a/jenkins_jobs/cache.py
+++ b/jenkins_jobs/cache.py
@@ -43,43 +43,45 @@ class JobCache(object):
def __init__(self, jenkins_url, flush=False):
cache_dir = self.get_cache_dir()
# One cache per remote Jenkins URL:
- host_vary = re.sub(r'[^A-Za-z0-9\-\~]', '_', jenkins_url)
+ host_vary = re.sub(r"[^A-Za-z0-9\-\~]", "_", jenkins_url)
self.cachefilename = os.path.join(
- cache_dir, 'cache-host-jobs-' + host_vary + '.yml')
+ cache_dir, "cache-host-jobs-" + host_vary + ".yml"
+ )
# generate named lockfile if none exists, and lock it
self._locked = self._lock()
if not self._locked:
raise errors.JenkinsJobsException(
- "Unable to lock cache for '%s'" % jenkins_url)
+ "Unable to lock cache for '%s'" % jenkins_url
+ )
if flush or not os.path.isfile(self.cachefilename):
self.data = {}
else:
- with io.open(self.cachefilename, 'r', encoding='utf-8') as yfile:
+ with io.open(self.cachefilename, "r", encoding="utf-8") as yfile:
self.data = yaml.load(yfile)
logger.debug("Using cache: '{0}'".format(self.cachefilename))
def _lock(self):
- self._fastener = fasteners.InterProcessLock("%s.lock" %
- self.cachefilename)
+ self._fastener = fasteners.InterProcessLock("%s.lock" % self.cachefilename)
return self._fastener.acquire(delay=1, max_delay=2, timeout=60)
def _unlock(self):
- if getattr(self, '_locked', False):
- if getattr(self, '_fastener', None) is not None:
+ if getattr(self, "_locked", False):
+ if getattr(self, "_fastener", None) is not None:
self._fastener.release()
self._locked = None
@staticmethod
def get_cache_dir():
- home = os.path.expanduser('~')
- if home == '~':
- raise OSError('Could not locate home folder')
- xdg_cache_home = os.environ.get('XDG_CACHE_HOME') or \
- os.path.join(home, '.cache')
- path = os.path.join(xdg_cache_home, 'jenkins_jobs')
+ home = os.path.expanduser("~")
+ if home == "~":
+ raise OSError("Could not locate home folder")
+ xdg_cache_home = os.environ.get("XDG_CACHE_HOME") or os.path.join(
+ home, ".cache"
+ )
+ path = os.path.join(xdg_cache_home, "jenkins_jobs")
if not os.path.isdir(path):
try:
os.makedirs(path)
@@ -111,9 +113,10 @@ class JobCache(object):
# use self references to required modules in case called via __del__
# write to tempfile under same directory and then replace to avoid
# issues around corruption such the process be killed
- tfile = self._tempfile.NamedTemporaryFile(dir=self.get_cache_dir(),
- delete=False)
- tfile.write(self._yaml.dump(self.data).encode('utf-8'))
+ tfile = self._tempfile.NamedTemporaryFile(
+ dir=self.get_cache_dir(), delete=False
+ )
+ tfile.write(self._yaml.dump(self.data).encode("utf-8"))
# force contents to be synced on disk before overwriting cachefile
tfile.flush()
self._os.fsync(tfile.fileno())
@@ -131,10 +134,12 @@ class JobCache(object):
def __del__(self):
# check we initialized sufficiently in case called
# due to an exception occurring in the __init__
- if getattr(self, 'data', None) is not None:
+ if getattr(self, "data", None) is not None:
try:
self.save()
except Exception as e:
- self._logger.error("Failed to write to cache file '%s' on "
- "exit: %s" % (self.cachefilename, e))
+ self._logger.error(
+ "Failed to write to cache file '%s' on "
+ "exit: %s" % (self.cachefilename, e)
+ )
self._unlock()
diff --git a/jenkins_jobs/cli/entry.py b/jenkins_jobs/cli/entry.py
index 77669b0d..e67ecb24 100644
--- a/jenkins_jobs/cli/entry.py
+++ b/jenkins_jobs/cli/entry.py
@@ -31,8 +31,7 @@ logger = logging.getLogger()
def __version__():
- return "Jenkins Job Builder version: %s" % \
- version.version_info.version_string()
+ return "Jenkins Job Builder version: %s" % version.version_info.version_string()
class JenkinsJobs(object):
@@ -58,17 +57,17 @@ class JenkinsJobs(object):
self.parser = create_parser()
self.options = self.parser.parse_args(args)
- self.jjb_config = JJBConfig(self.options.conf,
- config_section=self.options.section,
- **kwargs)
+ self.jjb_config = JJBConfig(
+ self.options.conf, config_section=self.options.section, **kwargs
+ )
if not self.options.command:
self.parser.error("Must specify a 'command' to be performed")
- if (self.options.log_level is not None):
- self.options.log_level = getattr(logging,
- self.options.log_level.upper(),
- logger.getEffectiveLevel())
+ if self.options.log_level is not None:
+ self.options.log_level = getattr(
+ logging, self.options.log_level.upper(), logger.getEffectiveLevel()
+ )
logger.setLevel(self.options.log_level)
self._parse_additional()
@@ -84,50 +83,58 @@ class JenkinsJobs(object):
def _parse_additional(self):
- self._set_config(self.jjb_config.builder, 'ignore_cache')
- self._set_config(self.jjb_config.builder, 'flush_cache')
- self._set_config(self.jjb_config.builder, 'update')
- self._set_config(self.jjb_config.yamlparser, 'allow_empty_variables')
- self._set_config(self.jjb_config.jenkins, 'section')
- self._set_config(self.jjb_config.jenkins, 'user')
- self._set_config(self.jjb_config.jenkins, 'password')
+ self._set_config(self.jjb_config.builder, "ignore_cache")
+ self._set_config(self.jjb_config.builder, "flush_cache")
+ self._set_config(self.jjb_config.builder, "update")
+ self._set_config(self.jjb_config.yamlparser, "allow_empty_variables")
+ self._set_config(self.jjb_config.jenkins, "section")
+ self._set_config(self.jjb_config.jenkins, "user")
+ self._set_config(self.jjb_config.jenkins, "password")
# Note: CLI options override config file options.
- if getattr(self.options, 'update', None) is None:
- self.options.update = self.jjb_config.builder.get('update')
+ if getattr(self.options, "update", None) is None:
+ self.options.update = self.jjb_config.builder.get("update")
if self.options.update is None:
- self.options.update = 'all'
+ self.options.update = "all"
- if getattr(self.options, 'plugins_info_path', None) is not None:
- with io.open(self.options.plugins_info_path, 'r',
- encoding='utf-8') as yaml_file:
+ if getattr(self.options, "plugins_info_path", None) is not None:
+ with io.open(
+ self.options.plugins_info_path, "r", encoding="utf-8"
+ ) as yaml_file:
plugins_info = yaml.load(yaml_file)
if not isinstance(plugins_info, list):
- self.parser.error("{0} must contain a Yaml list!".format(
- self.options.plugins_info_path))
- self.jjb_config.builder['plugins_info'] = plugins_info
-
- if getattr(self.options, 'path', None):
- if hasattr(self.options.path, 'read'):
+ self.parser.error(
+ "{0} must contain a Yaml list!".format(
+ self.options.plugins_info_path
+ )
+ )
+ self.jjb_config.builder["plugins_info"] = plugins_info
+
+ if getattr(self.options, "path", None):
+ if hasattr(self.options.path, "read"):
logger.debug("Input file is stdin")
if self.options.path.isatty():
- if platform.system() == 'Windows':
- key = 'CTRL+Z'
+ if platform.system() == "Windows":
+ key = "CTRL+Z"
else:
- key = 'CTRL+D'
- logger.warning("Reading configuration from STDIN. "
- "Press %s to end input.", key)
+ key = "CTRL+D"
+ logger.warning(
+ "Reading configuration from STDIN. " "Press %s to end input.",
+ key,
+ )
self.options.path = [self.options.path]
else:
# take list of paths
self.options.path = self.options.path.split(os.pathsep)
- do_recurse = (getattr(self.options, 'recursive', False) or
- self.jjb_config.recursive)
+ do_recurse = (
+ getattr(self.options, "recursive", False)
+ or self.jjb_config.recursive
+ )
- excludes = ([e for elist in self.options.exclude
- for e in elist.split(os.pathsep)] or
- self.jjb_config.excludes)
+ excludes = [
+ e for elist in self.options.exclude for e in elist.split(os.pathsep)
+ ] or self.jjb_config.excludes
paths = []
for path in self.options.path:
if do_recurse and os.path.isdir(path):
@@ -139,8 +146,8 @@ class JenkinsJobs(object):
def execute(self):
extension_manager = extension.ExtensionManager(
- namespace='jjb.cli.subcommands',
- invoke_on_load=True,)
+ namespace="jjb.cli.subcommands", invoke_on_load=True
+ )
ext = extension_manager[self.options.command]
ext.obj.execute(self.options, self.jjb_config)
@@ -154,10 +161,11 @@ def main():
if sys.version_info[0] == 2:
import codecs
+
reload(sys) # noqa
- sys.setdefaultencoding('utf-8')
- sys.stdout = codecs.getwriter('utf8')(sys.stdout)
- sys.stderr = codecs.getwriter('utf8')(sys.stderr)
+ sys.setdefaultencoding("utf-8")
+ sys.stdout = codecs.getwriter("utf8")(sys.stdout)
+ sys.stderr = codecs.getwriter("utf8")(sys.stderr)
# end of workaround
argv = sys.argv[1:]
diff --git a/jenkins_jobs/cli/parser.py b/jenkins_jobs/cli/parser.py
index 768daa45..37942654 100644
--- a/jenkins_jobs/cli/parser.py
+++ b/jenkins_jobs/cli/parser.py
@@ -22,8 +22,10 @@ from stevedore import extension
def __version__():
- return "Jenkins Job Builder version: %s" % \
- jenkins_jobs.version.version_info.version_string()
+ return (
+ "Jenkins Job Builder version: %s"
+ % jenkins_jobs.version.version_info.version_string()
+ )
def create_parser():
@@ -31,67 +33,78 @@ def create_parser():
"""
parser = argparse.ArgumentParser()
parser.add_argument(
- '--conf',
- dest='conf',
- default=os.environ.get('JJB_CONF', None),
- help="configuration file [JJB_CONF]")
+ "--conf",
+ dest="conf",
+ default=os.environ.get("JJB_CONF", None),
+ help="configuration file [JJB_CONF]",
+ )
parser.add_argument(
- '-l',
- '--log_level',
- dest='log_level',
- default=os.environ.get('JJB_LOG_LEVEL', 'info'),
- help="log level (default: %(default)s) [JJB_LOG_LEVEL]")
+ "-l",
+ "--log_level",
+ dest="log_level",
+ default=os.environ.get("JJB_LOG_LEVEL", "info"),
+ help="log level (default: %(default)s) [JJB_LOG_LEVEL]",
+ )
parser.add_argument(
- '--ignore-cache',
- action='store_true',
- dest='ignore_cache',
+ "--ignore-cache",
+ action="store_true",
+ dest="ignore_cache",
default=None,
help="ignore the cache and update the jobs anyhow (that will "
- "only flush the specified jobs cache)")
+ "only flush the specified jobs cache)",
+ )
parser.add_argument(
- '--flush-cache',
- action='store_true',
- dest='flush_cache',
+ "--flush-cache",
+ action="store_true",
+ dest="flush_cache",
default=None,
- help="flush all the cache entries before updating")
+ help="flush all the cache entries before updating",
+ )
parser.add_argument(
- '--version',
- dest='version',
- action='version',
+ "--version",
+ dest="version",
+ action="version",
version=__version__(),
- help="show version")
+ help="show version",
+ )
parser.add_argument(
- '--allow-empty-variables',
- action='store_true',
- dest='allow_empty_variables',
+ "--allow-empty-variables",
+ action="store_true",
+ dest="allow_empty_variables",
default=None,
- help="Don\'t fail if any of the variables inside any string are "
- "not defined, replace with empty string instead.")
+ help="Don't fail if any of the variables inside any string are "
+ "not defined, replace with empty string instead.",
+ )
parser.add_argument(
- '--server', '-s',
- dest='section',
- default=os.environ.get('JJB_SECTION', 'jenkins'),
+ "--server",
+ "-s",
+ dest="section",
+ default=os.environ.get("JJB_SECTION", "jenkins"),
help="The Jenkins server ini section to use. Defaults to 'jenkins' "
- "[JJB_SECTION]")
+ "[JJB_SECTION]",
+ )
parser.add_argument(
- '--user', '-u',
- default=os.environ.get('JJB_USER', None),
+ "--user",
+ "-u",
+ default=os.environ.get("JJB_USER", None),
help="The Jenkins user to use for authentication. This overrides "
- "the user specified in the configuration file. [JJB_USER]")
+ "the user specified in the configuration file. [JJB_USER]",
+ )
parser.add_argument(
- '--password', '-p',
- default=os.environ.get('JJB_PASSWORD', None),
+ "--password",
+ "-p",
+ default=os.environ.get("JJB_PASSWORD", None),
help="Password or API token to use for authenticating towards Jenkins."
" This overrides the password specified in the configuration file."
- " [JJB_PASSWORD]")
+ " [JJB_PASSWORD]",
+ )
subparser = parser.add_subparsers(
- dest='command',
- help="update, test, list or delete job")
+ dest="command", help="update, test, list or delete job"
+ )
extension_manager = extension.ExtensionManager(
- namespace='jjb.cli.subcommands',
- invoke_on_load=True,
+ namespace="jjb.cli.subcommands", invoke_on_load=True
)
def parse_subcommand_args(ext, subparser):
diff --git a/jenkins_jobs/cli/subcommand/base.py b/jenkins_jobs/cli/subcommand/base.py
index 5c214f68..0e5c7bfe 100644
--- a/jenkins_jobs/cli/subcommand/base.py
+++ b/jenkins_jobs/cli/subcommand/base.py
@@ -22,6 +22,7 @@ class BaseSubCommand(object):
"""Base class for Jenkins Job Builder subcommands, intended to allow
subcommands to be loaded as stevedore extensions by third party users.
"""
+
def __init__(self):
pass
@@ -52,16 +53,20 @@ class BaseSubCommand(object):
"""Add '--recursive' and '--exclude' arguments to given parser.
"""
parser.add_argument(
- '-r', '--recursive',
- action='store_true',
- dest='recursive',
+ "-r",
+ "--recursive",
+ action="store_true",
+ dest="recursive",
default=False,
- help="look for yaml files recursively")
+ help="look for yaml files recursively",
+ )
parser.add_argument(
- '-x', '--exclude',
- dest='exclude',
- action='append',
+ "-x",
+ "--exclude",
+ dest="exclude",
+ action="append",
default=[],
help="paths to exclude when using recursive search, "
- "uses standard globbing.")
+ "uses standard globbing.",
+ )
diff --git a/jenkins_jobs/cli/subcommand/delete.py b/jenkins_jobs/cli/subcommand/delete.py
index b589d88c..ab0cf63c 100644
--- a/jenkins_jobs/cli/subcommand/delete.py
+++ b/jenkins_jobs/cli/subcommand/delete.py
@@ -22,32 +22,33 @@ import jenkins_jobs.cli.subcommand.base as base
class DeleteSubCommand(base.BaseSubCommand):
-
def parse_args(self, subparser):
- delete = subparser.add_parser('delete')
+ delete = subparser.add_parser("delete")
self.parse_option_recursive_exclude(delete)
+ delete.add_argument("name", help="name of job", nargs="+")
delete.add_argument(
- 'name',
- help='name of job',
- nargs='+')
- delete.add_argument(
- '-p', '--path',
+ "-p",
+ "--path",
default=None,
- help="colon-separated list of paths to YAML files "
- "or directories")
+ help="colon-separated list of paths to YAML files " "or directories",
+ )
delete.add_argument(
- '-j', '--jobs-only',
- action='store_true', dest='del_jobs',
+ "-j",
+ "--jobs-only",
+ action="store_true",
+ dest="del_jobs",
default=False,
- help='delete only jobs'
+ help="delete only jobs",
)
delete.add_argument(
- '-v', '--views-only',
- action='store_true', dest='del_views',
+ "-v",
+ "--views-only",
+ action="store_true",
+ dest="del_views",
default=False,
- help='delete only views'
+ help="delete only views",
)
def execute(self, options, jjb_config):
@@ -55,7 +56,8 @@ class DeleteSubCommand(base.BaseSubCommand):
if options.del_jobs and options.del_views:
raise JenkinsJobsException(
- '"--views-only" and "--jobs-only" cannot be used together.')
+ '"--views-only" and "--jobs-only" cannot be used together.'
+ )
fn = options.path
registry = ModuleRegistry(jjb_config, builder.plugins_list)
@@ -64,8 +66,8 @@ class DeleteSubCommand(base.BaseSubCommand):
if fn:
parser.load_files(fn)
parser.expandYaml(registry, options.name)
- jobs = [j['name'] for j in parser.jobs]
- views = [v['name'] for v in parser.views]
+ jobs = [j["name"] for j in parser.jobs]
+ views = [v["name"] for v in parser.views]
else:
jobs = options.name
views = options.name
diff --git a/jenkins_jobs/cli/subcommand/delete_all.py b/jenkins_jobs/cli/subcommand/delete_all.py
index af9ff228..bee23cf8 100644
--- a/jenkins_jobs/cli/subcommand/delete_all.py
+++ b/jenkins_jobs/cli/subcommand/delete_all.py
@@ -27,26 +27,30 @@ logger = logging.getLogger(__name__)
class DeleteAllSubCommand(base.BaseSubCommand):
-
def parse_args(self, subparser):
delete_all = subparser.add_parser(
- 'delete-all',
+ "delete-all",
help="delete *ALL* jobs from Jenkins server, including "
- "those not managed by Jenkins Job Builder.")
+ "those not managed by Jenkins Job Builder.",
+ )
self.parse_option_recursive_exclude(delete_all)
delete_all.add_argument(
- '-j', '--jobs-only',
- action='store_true', dest='del_jobs',
+ "-j",
+ "--jobs-only",
+ action="store_true",
+ dest="del_jobs",
default=False,
- help='delete only jobs'
+ help="delete only jobs",
)
delete_all.add_argument(
- '-v', '--views-only',
- action='store_true', dest='del_views',
+ "-v",
+ "--views-only",
+ action="store_true",
+ dest="del_views",
default=False,
- help='delete only views'
+ help="delete only views",
)
def execute(self, options, jjb_config):
@@ -55,24 +59,26 @@ class DeleteAllSubCommand(base.BaseSubCommand):
reach = set()
if options.del_jobs and options.del_views:
raise JenkinsJobsException(
- '"--views-only" and "--jobs-only" cannot be used together.')
+ '"--views-only" and "--jobs-only" cannot be used together.'
+ )
elif options.del_jobs and not options.del_views:
- reach.add('jobs')
+ reach.add("jobs")
elif options.del_views and not options.del_jobs:
- reach.add('views')
+ reach.add("views")
else:
- reach.update(('jobs', 'views'))
+ reach.update(("jobs", "views"))
if not utils.confirm(
- 'Sure you want to delete *ALL* {} from Jenkins '
- 'server?\n(including those not managed by Jenkins '
- 'Job Builder)'.format(" AND ".join(reach))):
- sys.exit('Aborted')
+ "Sure you want to delete *ALL* {} from Jenkins "
+ "server?\n(including those not managed by Jenkins "
+ "Job Builder)".format(" AND ".join(reach))
+ ):
+ sys.exit("Aborted")
- if 'jobs' in reach:
+ if "jobs" in reach:
logger.info("Deleting all jobs")
builder.delete_all_jobs()
- if 'views' in reach:
+ if "views" in reach:
logger.info("Deleting all views")
builder.delete_all_views()
diff --git a/jenkins_jobs/cli/subcommand/get_plugins_info.py b/jenkins_jobs/cli/subcommand/get_plugins_info.py
index 748cbf6c..8c76722f 100644
--- a/jenkins_jobs/cli/subcommand/get_plugins_info.py
+++ b/jenkins_jobs/cli/subcommand/get_plugins_info.py
@@ -25,17 +25,18 @@ logger = logging.getLogger(__name__)
class GetPluginsInfoSubCommand(base.BaseSubCommand):
-
def parse_args(self, subparser):
plugins_info = subparser.add_parser(
- 'get-plugins-info',
- help='get plugins info yaml by querying Jenkins server.')
+ "get-plugins-info", help="get plugins info yaml by querying Jenkins server."
+ )
plugins_info.add_argument(
- '-o', '--output-file',
- default='plugins_info.yaml',
- dest='plugins_info_file',
- help='file to save output to.')
+ "-o",
+ "--output-file",
+ default="plugins_info.yaml",
+ dest="plugins_info_file",
+ help="file to save output to.",
+ )
def execute(self, options, jjb_config):
builder = JenkinsManager(jjb_config)
@@ -43,14 +44,14 @@ class GetPluginsInfoSubCommand(base.BaseSubCommand):
plugins_info = []
for plugin in plugin_data:
info = {
- 'longName': str(plugin['longName']),
- 'shortName': str(plugin['shortName']),
- 'version': str(plugin['version']),
+ "longName": str(plugin["longName"]),
+ "shortName": str(plugin["shortName"]),
+ "version": str(plugin["version"]),
}
plugins_info.append(info)
if options.plugins_info_file:
- with open(options.plugins_info_file, 'w') as outfile:
+ with open(options.plugins_info_file, "w") as outfile:
outfile.write(yaml.dump(plugins_info))
logger.info("Generated {} file".format(options.plugins_info_file))
else:
diff --git a/jenkins_jobs/cli/subcommand/list.py b/jenkins_jobs/cli/subcommand/list.py
index df2fd35f..d00d958d 100644
--- a/jenkins_jobs/cli/subcommand/list.py
+++ b/jenkins_jobs/cli/subcommand/list.py
@@ -27,18 +27,15 @@ def list_duplicates(seq):
class ListSubCommand(base.BaseSubCommand):
-
def parse_args(self, subparser):
- list = subparser.add_parser('list', help="List jobs")
+ list = subparser.add_parser("list", help="List jobs")
self.parse_option_recursive_exclude(list)
- list.add_argument('names',
- help='name(s) of job(s)',
- nargs='*',
- default=None)
- list.add_argument('-p', '--path', default=None,
- help='path to YAML file or directory')
+ list.add_argument("names", help="name(s) of job(s)", nargs="*", default=None)
+ list.add_argument(
+ "-p", "--path", default=None, help="path to YAML file or directory"
+ )
def execute(self, options, jjb_config):
self.jjb_config = jjb_config
@@ -50,24 +47,25 @@ class ListSubCommand(base.BaseSubCommand):
stdout = utils.wrap_stream(sys.stdout)
for job in jobs:
- stdout.write((job + '\n').encode('utf-8'))
+ stdout.write((job + "\n").encode("utf-8"))
def get_jobs(self, jobs_glob=None, fn=None):
if fn:
- r = registry.ModuleRegistry(self.jjb_config,
- self.jenkins.plugins_list)
+ r = registry.ModuleRegistry(self.jjb_config, self.jenkins.plugins_list)
p = parser.YamlParser(self.jjb_config)
p.load_files(fn)
p.expandYaml(r, jobs_glob)
- jobs = [j['name'] for j in p.jobs]
+ jobs = [j["name"] for j in p.jobs]
else:
- jobs = [j['name'] for j in self.jenkins.get_jobs()
- if not jobs_glob or parser.matches(j['name'], jobs_glob)]
+ jobs = [
+ j["name"]
+ for j in self.jenkins.get_jobs()
+ if not jobs_glob or parser.matches(j["name"], jobs_glob)
+ ]
jobs = sorted(jobs)
for duplicate in list_duplicates(jobs):
- logging.warning("Found duplicate job name '%s', likely bug.",
- duplicate)
+ logging.warning("Found duplicate job name '%s', likely bug.", duplicate)
logging.debug("Builder.get_jobs: returning %r", jobs)
diff --git a/jenkins_jobs/cli/subcommand/test.py b/jenkins_jobs/cli/subcommand/test.py
index a185a3d8..e6822224 100644
--- a/jenkins_jobs/cli/subcommand/test.py
+++ b/jenkins_jobs/cli/subcommand/test.py
@@ -23,9 +23,8 @@ logger = logging.getLogger(__name__)
class TestSubCommand(update.UpdateSubCommand):
-
def parse_args(self, subparser):
- test = subparser.add_parser('test')
+ test = subparser.add_parser("test")
self.parse_option_recursive_exclude(test)
@@ -33,36 +32,46 @@ class TestSubCommand(update.UpdateSubCommand):
self.parse_arg_names(test)
test.add_argument(
- '--config-xml',
- action='store_true',
- dest='config_xml',
+ "--config-xml",
+ action="store_true",
+ dest="config_xml",
default=False,
- help='use alternative output file layout using config.xml files')
+ help="use alternative output file layout using config.xml files",
+ )
test.add_argument(
- '-p', '--plugin-info',
- dest='plugins_info_path',
+ "-p",
+ "--plugin-info",
+ dest="plugins_info_path",
default=None,
- help='path to plugin info YAML file')
+ help="path to plugin info YAML file",
+ )
test.add_argument(
- '-o',
- dest='output_dir',
- default=sys.stdout,
- help='path to output XML')
+ "-o", dest="output_dir", default=sys.stdout, help="path to output XML"
+ )
def execute(self, options, jjb_config):
if not options.config_xml:
- logger.warn('(Deprecated) The default output behavior of'
- ' `jenkins-jobs test` when given the --output'
- ' flag will change in JJB 3.0.'
- ' Instead of writing jobs to OUTPUT/jobname;'
- ' they will be written to OUTPUT/jobname/config.xml.'
- ' The new behavior can be enabled by the passing'
- ' `--config-xml` parameter.')
+ logger.warn(
+ "(Deprecated) The default output behavior of"
+ " `jenkins-jobs test` when given the --output"
+ " flag will change in JJB 3.0."
+ " Instead of writing jobs to OUTPUT/jobname;"
+ " they will be written to OUTPUT/jobname/config.xml."
+ " The new behavior can be enabled by the passing"
+ " `--config-xml` parameter."
+ )
- builder, xml_jobs, xml_views = self._generate_xmljobs(
- options, jjb_config)
+ builder, xml_jobs, xml_views = self._generate_xmljobs(options, jjb_config)
- builder.update_jobs(xml_jobs, output=options.output_dir, n_workers=1,
- config_xml=options.config_xml)
- builder.update_views(xml_views, output=options.output_dir, n_workers=1,
- config_xml=options.config_xml)
+ builder.update_jobs(
+ xml_jobs,
+ output=options.output_dir,
+ n_workers=1,
+ config_xml=options.config_xml,
+ )
+ builder.update_views(
+ xml_views,
+ output=options.output_dir,
+ n_workers=1,
+ config_xml=options.config_xml,
+ )
diff --git a/jenkins_jobs/cli/subcommand/update.py b/jenkins_jobs/cli/subcommand/update.py
index 5884648e..374089dc 100644
--- a/jenkins_jobs/cli/subcommand/update.py
+++ b/jenkins_jobs/cli/subcommand/update.py
@@ -30,22 +30,19 @@ logger = logging.getLogger(__name__)
class UpdateSubCommand(base.BaseSubCommand):
-
def parse_arg_path(self, parser):
parser.add_argument(
- 'path',
- nargs='?',
+ "path",
+ nargs="?",
default=sys.stdin,
- help="colon-separated list of paths to YAML files "
- "or directories")
+ help="colon-separated list of paths to YAML files " "or directories",
+ )
def parse_arg_names(self, parser):
- parser.add_argument(
- 'names',
- help='name(s) of job(s)', nargs='*')
+ parser.add_argument("names", help="name(s) of job(s)", nargs="*")
def parse_args(self, subparser):
- update = subparser.add_parser('update')
+ update = subparser.add_parser("update")
self.parse_option_recursive_exclude(update)
@@ -53,51 +50,59 @@ class UpdateSubCommand(base.BaseSubCommand):
self.parse_arg_names(update)
update.add_argument(
- '--delete-old',
- action='store_true',
- dest='delete_old',
+ "--delete-old",
+ action="store_true",
+ dest="delete_old",
default=False,
- help='delete obsolete jobs')
+ help="delete obsolete jobs",
+ )
update.add_argument(
- '-p', '--plugin-info',
- dest='plugins_info_path',
+ "-p",
+ "--plugin-info",
+ dest="plugins_info_path",
default=None,
- help='path to plugin info YAML file. Can be used to provide '
- 'previously retrieved plugins info when connecting credentials '
- 'don\'t have permissions to query.')
+ help="path to plugin info YAML file. Can be used to provide "
+ "previously retrieved plugins info when connecting credentials "
+ "don't have permissions to query.",
+ )
update.add_argument(
- '--workers',
+ "--workers",
type=int,
default=1,
- dest='n_workers',
+ dest="n_workers",
help="number of workers to use, 0 for autodetection and 1 "
- "for just one worker.")
+ "for just one worker.",
+ )
update.add_argument(
- '--existing-only',
- action='store_true',
+ "--existing-only",
+ action="store_true",
default=False,
- dest='existing_only',
- help='update existing jobs only')
+ dest="existing_only",
+ help="update existing jobs only",
+ )
update_type = update.add_mutually_exclusive_group()
update_type.add_argument(
- '-j', '--jobs-only',
- action='store_const',
- dest='update',
- const='jobs',
- help='update only jobs')
+ "-j",
+ "--jobs-only",
+ action="store_const",
+ dest="update",
+ const="jobs",
+ help="update only jobs",
+ )
update_type.add_argument(
- '-v', '--views-only',
- action='store_const',
- dest='update',
- const='views',
- help='update only views')
+ "-v",
+ "--views-only",
+ action="store_const",
+ dest="update",
+ const="views",
+ help="update only views",
+ )
def _generate_xmljobs(self, options, jjb_config=None):
builder = JenkinsManager(jjb_config)
- logger.info("Updating jobs in {0} ({1})".format(
- options.path, options.names))
+ logger.info("Updating jobs in {0} ({1})".format(options.path, options.names))
orig = time.time()
# Generate XML
@@ -109,45 +114,51 @@ class UpdateSubCommand(base.BaseSubCommand):
parser.load_files(options.path)
registry.set_parser_data(parser.data)
- job_data_list, view_data_list = parser.expandYaml(
- registry, options.names)
+ job_data_list, view_data_list = parser.expandYaml(registry, options.names)
xml_jobs = xml_job_generator.generateXML(job_data_list)
xml_views = xml_view_generator.generateXML(view_data_list)
jobs = parser.jobs
step = time.time()
- logging.debug('%d XML files generated in %ss',
- len(jobs), str(step - orig))
+ logging.debug("%d XML files generated in %ss", len(jobs), str(step - orig))
return builder, xml_jobs, xml_views
def execute(self, options, jjb_config):
if options.n_workers < 0:
raise JenkinsJobsException(
- 'Number of workers must be equal or greater than 0')
+ "Number of workers must be equal or greater than 0"
+ )
- builder, xml_jobs, xml_views = self._generate_xmljobs(
- options, jjb_config)
+ builder, xml_jobs, xml_views = self._generate_xmljobs(options, jjb_config)
- if options.update == 'jobs':
+ if options.update == "jobs":
jobs, num_updated_jobs = builder.update_jobs(
- xml_jobs, n_workers=options.n_workers,
- existing_only=options.existing_only)
+ xml_jobs,
+ n_workers=options.n_workers,
+ existing_only=options.existing_only,
+ )
logger.info("Number of jobs updated: %d", num_updated_jobs)
- elif options.update == 'views':
+ elif options.update == "views":
views, num_updated_views = builder.update_views(
- xml_views, n_workers=options.n_workers,
- existing_only=options.existing_only)
+ xml_views,
+ n_workers=options.n_workers,
+ existing_only=options.existing_only,
+ )
logger.info("Number of views updated: %d", num_updated_views)
else:
jobs, num_updated_jobs = builder.update_jobs(
- xml_jobs, n_workers=options.n_workers,
- existing_only=options.existing_only)
+ xml_jobs,
+ n_workers=options.n_workers,
+ existing_only=options.existing_only,
+ )
logger.info("Number of jobs updated: %d", num_updated_jobs)
views, num_updated_views = builder.update_views(
- xml_views, n_workers=options.n_workers,
- existing_only=options.existing_only)
+ xml_views,
+ n_workers=options.n_workers,
+ existing_only=options.existing_only,
+ )
logger.info("Number of views updated: %d", num_updated_views)
keep_jobs = [job.name for job in xml_jobs]
diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py
index 2252392b..5b630c92 100644
--- a/jenkins_jobs/config.py
+++ b/jenkins_jobs/config.py
@@ -27,9 +27,7 @@ from jenkins_jobs import builder
from jenkins_jobs.errors import JJBConfigException
from jenkins_jobs.errors import JenkinsJobsException
-__all__ = [
- "JJBConfig"
-]
+__all__ = ["JJBConfig"]
logger = logging.getLogger(__name__)
@@ -50,21 +48,21 @@ url=http://localhost:8080/
query_plugins_info=False
"""
-CONFIG_REQUIRED_MESSAGE = ("A valid configuration file is required. "
- "No configuration file passed.")
+CONFIG_REQUIRED_MESSAGE = (
+ "A valid configuration file is required. " "No configuration file passed."
+)
DEPRECATED_PLUGIN_CONFIG_SECTION_MESSAGE = (
"Defining plugin configuration using a [{plugin}] section in your config"
" file is deprecated. The recommended way to define plugins now is by"
- " using a [plugin \"{plugin}\"] section"
+ ' using a [plugin "{plugin}"] section'
)
_NOTSET = object()
class JJBConfig(object):
-
- def __init__(self, config_filename=None,
- config_file_required=False,
- config_section='jenkins'):
+ def __init__(
+ self, config_filename=None, config_file_required=False, config_section="jenkins"
+ ):
"""
The JJBConfig class is intended to encapsulate and resolve priority
@@ -93,11 +91,11 @@ class JJBConfig(object):
config_parser = self._init_defaults()
- global_conf = '/etc/jenkins_jobs/jenkins_jobs.ini'
- user_conf = os.path.join(os.path.expanduser('~'), '.config',
- 'jenkins_jobs', 'jenkins_jobs.ini')
- local_conf = os.path.join(os.path.dirname(__file__),
- 'jenkins_jobs.ini')
+ global_conf = "/etc/jenkins_jobs/jenkins_jobs.ini"
+ user_conf = os.path.join(
+ os.path.expanduser("~"), ".config", "jenkins_jobs", "jenkins_jobs.ini"
+ )
+ local_conf = os.path.join(os.path.dirname(__file__), "jenkins_jobs.ini")
conf = None
if config_filename is not None:
conf = config_filename
@@ -120,8 +118,10 @@ class JJBConfig(object):
if config_file_required:
raise JJBConfigException(CONFIG_REQUIRED_MESSAGE)
else:
- logger.warning("Config file, {0}, not found. Using "
- "default config values.".format(conf))
+ logger.warning(
+ "Config file, {0}, not found. Using "
+ "default config values.".format(conf)
+ )
if config_fp is not None:
if PY2:
@@ -162,33 +162,35 @@ class JJBConfig(object):
if os.path.isfile(config_filename):
self.__config_file = config_filename # remember file we read from
logger.debug("Reading config from {0}".format(config_filename))
- config_fp = io.open(config_filename, 'r', encoding='utf-8')
+ config_fp = io.open(config_filename, "r", encoding="utf-8")
else:
raise JJBConfigException(
"A valid configuration file is required. "
- "\n{0} is not valid.".format(config_filename))
+ "\n{0} is not valid.".format(config_filename)
+ )
return config_fp
def _handle_deprecated_hipchat_config(self):
config = self.config_parser
- if config.has_section('hipchat'):
+ if config.has_section("hipchat"):
if config.has_section('plugin "hipchat"'):
logger.warning(
- "Both [hipchat] and [plugin \"hipchat\"] sections "
+ 'Both [hipchat] and [plugin "hipchat"] sections '
"defined, legacy [hipchat] section will be ignored."
)
else:
logger.warning(
"[hipchat] section is deprecated and should be moved to a "
- "[plugins \"hipchat\"] section instead as the [hipchat] "
+ '[plugins "hipchat"] section instead as the [hipchat] '
"section will be ignored in the future."
)
config.add_section('plugin "hipchat"')
for option in config.options("hipchat"):
- config.set('plugin "hipchat"', option,
- config.get("hipchat", option))
+ config.set(
+ 'plugin "hipchat"', option, config.get("hipchat", option)
+ )
config.remove_section("hipchat")
@@ -197,9 +199,10 @@ class JJBConfig(object):
# interpolation to remove the need for plugins to need information
# directly from the jenkins section within code and allow variables
# in the config file to refer instead.
- if (config.has_section('plugin "hipchat"') and
- not config.has_option('plugin "hipchat"', 'url')):
- config.set('plugin "hipchat"', "url", config.get('jenkins', 'url'))
+ if config.has_section('plugin "hipchat"') and not config.has_option(
+ 'plugin "hipchat"', "url"
+ ):
+ config.set('plugin "hipchat"', "url", config.get("jenkins", "url"))
def _setup(self):
config = self.config_parser
@@ -208,26 +211,27 @@ class JJBConfig(object):
# check the ignore_cache setting
ignore_cache = False
- if config.has_option(self._section, 'ignore_cache'):
- logger.warning("ignore_cache option should be moved to the "
- "[job_builder] section in the config file, the "
- "one specified in the [jenkins] section will be "
- "ignored in the future")
- ignore_cache = config.getboolean(self._section, 'ignore_cache')
- elif config.has_option('job_builder', 'ignore_cache'):
- ignore_cache = config.getboolean('job_builder', 'ignore_cache')
- self.builder['ignore_cache'] = ignore_cache
+ if config.has_option(self._section, "ignore_cache"):
+ logger.warning(
+ "ignore_cache option should be moved to the "
+ "[job_builder] section in the config file, the "
+ "one specified in the [jenkins] section will be "
+ "ignored in the future"
+ )
+ ignore_cache = config.getboolean(self._section, "ignore_cache")
+ elif config.has_option("job_builder", "ignore_cache"):
+ ignore_cache = config.getboolean("job_builder", "ignore_cache")
+ self.builder["ignore_cache"] = ignore_cache
# check the flush_cache setting
flush_cache = False
- if config.has_option('job_builder', 'flush_cache'):
- flush_cache = config.getboolean('job_builder', 'flush_cache')
- self.builder['flush_cache'] = flush_cache
+ if config.has_option("job_builder", "flush_cache"):
+ flush_cache = config.getboolean("job_builder", "flush_cache")
+ self.builder["flush_cache"] = flush_cache
# check the print_job_urls setting
- if config.has_option('job_builder', 'print_job_urls'):
- self.print_job_urls = config.getboolean('job_builder',
- 'print_job_urls')
+ if config.has_option("job_builder", "print_job_urls"):
+ self.print_job_urls = config.getboolean("job_builder", "print_job_urls")
# Jenkins supports access as an anonymous user, which can be used to
# ensure read-only behaviour when querying the version of plugins
@@ -240,16 +244,16 @@ class JJBConfig(object):
# https://bugs.launchpad.net/openstack-ci/+bug/1259631
try:
- user = config.get(self._section, 'user')
+ user = config.get(self._section, "user")
except (TypeError, configparser.NoOptionError):
user = None
- self.jenkins['user'] = user
+ self.jenkins["user"] = user
try:
- password = config.get(self._section, 'password')
+ password = config.get(self._section, "password")
except (TypeError, configparser.NoOptionError):
password = None
- self.jenkins['password'] = password
+ self.jenkins["password"] = password
# None -- no timeout, blocking mode; same as setblocking(True)
# 0.0 -- non-blocking mode; same as setblocking(False) <--- default
@@ -259,86 +263,94 @@ class JJBConfig(object):
# "timeout=jenkins_jobs.builder._DEFAULT_TIMEOUT" or not set timeout at
# all.
try:
- timeout = config.getfloat(self._section, 'timeout')
+ timeout = config.getfloat(self._section, "timeout")
except (ValueError):
raise JenkinsJobsException("Jenkins timeout config is invalid")
except (TypeError, configparser.NoOptionError):
timeout = builder._DEFAULT_TIMEOUT
- self.jenkins['timeout'] = timeout
+ self.jenkins["timeout"] = timeout
plugins_info = None
- if (config.has_option(self._section, 'query_plugins_info') and
- not config.getboolean(self._section, "query_plugins_info")):
+ if config.has_option(
+ self._section, "query_plugins_info"
+ ) and not config.getboolean(self._section, "query_plugins_info"):
logger.debug("Skipping plugin info retrieval")
plugins_info = []
- self.builder['plugins_info'] = plugins_info
+ self.builder["plugins_info"] = plugins_info
- self.recursive = config.getboolean('job_builder', 'recursive')
- self.excludes = config.get('job_builder', 'exclude').split(os.pathsep)
+ self.recursive = config.getboolean("job_builder", "recursive")
+ self.excludes = config.get("job_builder", "exclude").split(os.pathsep)
# The way we want to do things moving forward:
- self.jenkins['url'] = config.get(self._section, 'url')
- self.builder['print_job_urls'] = self.print_job_urls
+ self.jenkins["url"] = config.get(self._section, "url")
+ self.builder["print_job_urls"] = self.print_job_urls
# keep descriptions ? (used by yamlparser)
keep_desc = False
- if (config and config.has_section('job_builder') and
- config.has_option('job_builder', 'keep_descriptions')):
- keep_desc = config.getboolean('job_builder',
- 'keep_descriptions')
- self.yamlparser['keep_descriptions'] = keep_desc
+ if (
+ config
+ and config.has_section("job_builder")
+ and config.has_option("job_builder", "keep_descriptions")
+ ):
+ keep_desc = config.getboolean("job_builder", "keep_descriptions")
+ self.yamlparser["keep_descriptions"] = keep_desc
# figure out the include path (used by yamlparser)
path = ["."]
- if (config and config.has_section('job_builder') and
- config.has_option('job_builder', 'include_path')):
- path = config.get('job_builder',
- 'include_path').split(':')
- self.yamlparser['include_path'] = path
+ if (
+ config
+ and config.has_section("job_builder")
+ and config.has_option("job_builder", "include_path")
+ ):
+ path = config.get("job_builder", "include_path").split(":")
+ self.yamlparser["include_path"] = path
# allow duplicates?
allow_duplicates = False
- if config and config.has_option('job_builder', 'allow_duplicates'):
- allow_duplicates = config.getboolean('job_builder',
- 'allow_duplicates')
- self.yamlparser['allow_duplicates'] = allow_duplicates
+ if config and config.has_option("job_builder", "allow_duplicates"):
+ allow_duplicates = config.getboolean("job_builder", "allow_duplicates")
+ self.yamlparser["allow_duplicates"] = allow_duplicates
# allow empty variables?
- self.yamlparser['allow_empty_variables'] = (
- config and config.has_section('job_builder') and
- config.has_option('job_builder', 'allow_empty_variables') and
- config.getboolean('job_builder', 'allow_empty_variables'))
+ self.yamlparser["allow_empty_variables"] = (
+ config
+ and config.has_section("job_builder")
+ and config.has_option("job_builder", "allow_empty_variables")
+ and config.getboolean("job_builder", "allow_empty_variables")
+ )
# retain anchors across files?
retain_anchors = False
- if config and config.has_option('job_builder', 'retain_anchors'):
- retain_anchors = config.getboolean('job_builder',
- 'retain_anchors')
- self.yamlparser['retain_anchors'] = retain_anchors
+ if config and config.has_option("job_builder", "retain_anchors"):
+ retain_anchors = config.getboolean("job_builder", "retain_anchors")
+ self.yamlparser["retain_anchors"] = retain_anchors
update = None
- if (config and config.has_section('job_builder') and
- config.has_option('job_builder', 'update')):
- update = config.get('job_builder', 'update')
- self.builder['update'] = update
+ if (
+ config
+ and config.has_section("job_builder")
+ and config.has_option("job_builder", "update")
+ ):
+ update = config.get("job_builder", "update")
+ self.builder["update"] = update
def validate(self):
# Inform the user as to what is likely to happen, as they may specify
# a real jenkins instance in test mode to get the plugin info to check
# the XML generated.
- if self.jenkins['user'] is None and self.jenkins['password'] is None:
+ if self.jenkins["user"] is None and self.jenkins["password"] is None:
logger.info("Will use anonymous access to Jenkins if needed.")
- elif ((self.jenkins['user'] is not None and
- self.jenkins['password'] is None) or
- (self.jenkins['user'] is None and
- self.jenkins['password'] is not None)):
+ elif (
+ self.jenkins["user"] is not None and self.jenkins["password"] is None
+ ) or (self.jenkins["user"] is None and self.jenkins["password"] is not None):
raise JenkinsJobsException(
"Cannot authenticate to Jenkins with only one of User and "
"Password provided, please check your configuration."
)
- if (self.builder['plugins_info'] is not None and
- not isinstance(self.builder['plugins_info'], list)):
+ if self.builder["plugins_info"] is not None and not isinstance(
+ self.builder["plugins_info"], list
+ ):
raise JenkinsJobsException("plugins_info must contain a list!")
def get_module_config(self, section, key, default=None):
@@ -349,19 +361,23 @@ class JJBConfig(object):
"""
result = default
try:
- result = self.config_parser.get(
- section, key
- )
- except (configparser.NoSectionError, configparser.NoOptionError,
- JenkinsJobsException) as e:
+ result = self.config_parser.get(section, key)
+ except (
+ configparser.NoSectionError,
+ configparser.NoOptionError,
+ JenkinsJobsException,
+ ) as e:
# use of default ignores missing sections/options
if result is None:
logger.warning(
"You didn't set a %s neither in the yaml job definition "
"nor in the %s section, blank default value will be "
- "applied:\n%s", key, section, e)
+ "applied:\n%s",
+ key,
+ section,
+ e,
+ )
return result
def get_plugin_config(self, plugin, key, default=None):
- return self.get_module_config('plugin "{}"'.format(plugin), key,
- default)
+ return self.get_module_config('plugin "{}"'.format(plugin), key, default)
diff --git a/jenkins_jobs/errors.py b/jenkins_jobs/errors.py
index 09258ceb..489c08a4 100644
--- a/jenkins_jobs/errors.py
+++ b/jenkins_jobs/errors.py
@@ -4,9 +4,9 @@ import inspect
def is_sequence(arg):
- return (not hasattr(arg, "strip") and
- (hasattr(arg, "__getitem__") or
- hasattr(arg, "__iter__")))
+ return not hasattr(arg, "strip") and (
+ hasattr(arg, "__getitem__") or hasattr(arg, "__iter__")
+ )
class JenkinsJobsException(Exception):
@@ -14,20 +14,19 @@ class JenkinsJobsException(Exception):
class ModuleError(JenkinsJobsException):
-
def get_module_name(self):
frame = inspect.currentframe()
co_name = frame.f_code.co_name
- module_name = '<unresolved>'
- while frame and co_name != 'run':
+ module_name = "<unresolved>"
+ while frame and co_name != "run":
# XML generation called via dispatch
- if co_name == 'dispatch':
+ if co_name == "dispatch":
data = frame.f_locals
- module_name = "%s.%s" % (data['component_type'], data['name'])
+ module_name = "%s.%s" % (data["component_type"], data["name"])
break
# XML generation done directly by class using gen_xml or root_xml
- if co_name == 'gen_xml' or co_name == 'root_xml':
- data = frame.f_locals['data']
+ if co_name == "gen_xml" or co_name == "root_xml":
+ data = frame.f_locals["data"]
module_name = next(iter(data.keys()))
break
frame = frame.f_back
@@ -37,47 +36,41 @@ class ModuleError(JenkinsJobsException):
class InvalidAttributeError(ModuleError):
-
def __init__(self, attribute_name, value, valid_values=None):
message = "'{0}' is an invalid value for attribute {1}.{2}".format(
- value, self.get_module_name(), attribute_name)
+ value, self.get_module_name(), attribute_name
+ )
if is_sequence(valid_values):
message += "\nValid values include: {0}".format(
- ', '.join("'{0}'".format(value)
- for value in valid_values))
+ ", ".join("'{0}'".format(value) for value in valid_values)
+ )
super(InvalidAttributeError, self).__init__(message)
class MissingAttributeError(ModuleError):
-
def __init__(self, missing_attribute, module_name=None):
module = module_name or self.get_module_name()
if is_sequence(missing_attribute):
message = "One of {0} must be present in '{1}'".format(
- ', '.join("'{0}'".format(value)
- for value in missing_attribute), module)
+ ", ".join("'{0}'".format(value) for value in missing_attribute), module
+ )
else:
message = "Missing {0} from an instance of '{1}'".format(
- missing_attribute, module)
+ missing_attribute, module
+ )
super(MissingAttributeError, self).__init__(message)
class AttributeConflictError(ModuleError):
-
- def __init__(
- self, attribute_name, attributes_in_conflict, module_name=None
- ):
+ def __init__(self, attribute_name, attributes_in_conflict, module_name=None):
module = module_name or self.get_module_name()
- message = (
- "Attribute '{0}' can not be used together with {1} in {2}".format(
- attribute_name,
- ', '.join(
- "'{0}'".format(value) for value in attributes_in_conflict
- ), module
- )
+ message = "Attribute '{0}' can not be used together with {1} in {2}".format(
+ attribute_name,
+ ", ".join("'{0}'".format(value) for value in attributes_in_conflict),
+ module,
)
super(AttributeConflictError, self).__init__(message)
diff --git a/jenkins_jobs/formatter.py b/jenkins_jobs/formatter.py
index bd2576b9..61596780 100644
--- a/jenkins_jobs/formatter.py
+++ b/jenkins_jobs/formatter.py
@@ -33,18 +33,22 @@ def deep_format(obj, paramdict, allow_empty=False):
# limitations on the values in paramdict - the post-format result must
# still be valid YAML (so substituting-in a string containing quotes, for
# example, is problematic).
- if hasattr(obj, 'format'):
+ if hasattr(obj, "format"):
try:
ret = CustomFormatter(allow_empty).format(obj, **paramdict)
except KeyError as exc:
missing_key = exc.args[0]
desc = "%s parameter missing to format %s\nGiven:\n%s" % (
- missing_key, obj, pformat(paramdict))
+ missing_key,
+ obj,
+ pformat(paramdict),
+ )
raise JenkinsJobsException(desc)
except Exception:
- logging.error("Problem formatting with args:\nallow_empty:"
- "%s\nobj: %s\nparamdict: %s" %
- (allow_empty, obj, paramdict))
+ logging.error(
+ "Problem formatting with args:\nallow_empty:"
+ "%s\nobj: %s\nparamdict: %s" % (allow_empty, obj, paramdict)
+ )
raise
elif isinstance(obj, list):
@@ -55,17 +59,22 @@ def deep_format(obj, paramdict, allow_empty=False):
ret = type(obj)()
for item in obj:
try:
- ret[CustomFormatter(allow_empty).format(item, **paramdict)] = \
- deep_format(obj[item], paramdict, allow_empty)
+ ret[
+ CustomFormatter(allow_empty).format(item, **paramdict)
+ ] = deep_format(obj[item], paramdict, allow_empty)
except KeyError as exc:
missing_key = exc.args[0]
desc = "%s parameter missing to format %s\nGiven:\n%s" % (
- missing_key, obj, pformat(paramdict))
+ missing_key,
+ obj,
+ pformat(paramdict),
+ )
raise JenkinsJobsException(desc)
except Exception:
- logging.error("Problem formatting with args:\nallow_empty:"
- "%s\nobj: %s\nparamdict: %s" %
- (allow_empty, obj, paramdict))
+ logging.error(
+ "Problem formatting with args:\nallow_empty:"
+ "%s\nobj: %s\nparamdict: %s" % (allow_empty, obj, paramdict)
+ )
raise
else:
ret = obj
@@ -81,6 +90,7 @@ class CustomFormatter(Formatter):
Custom formatter to allow non-existing key references when formatting a
string
"""
+
_expr = r"""
(?<!{){({{)* # non-pair opening {
(?:obj:)? # obj:
@@ -99,7 +109,7 @@ class CustomFormatter(Formatter):
# special case of returning the object if the entire string
# matches a single parameter
try:
- result = re.match('^%s$' % self._expr, format_string, re.VERBOSE)
+ result = re.match("^%s$" % self._expr, format_string, re.VERBOSE)
except TypeError:
return format_string.format(**kwargs)
if result is not None:
@@ -130,8 +140,7 @@ class CustomFormatter(Formatter):
except KeyError:
if self.allow_empty:
logger.debug(
- 'Found uninitialized key %s, replaced with empty string',
- key
+ "Found uninitialized key %s, replaced with empty string", key
)
- return ''
+ return ""
raise
diff --git a/jenkins_jobs/local_yaml.py b/jenkins_jobs/local_yaml.py
index 213d8a7a..256e6ef5 100644
--- a/jenkins_jobs/local_yaml.py
+++ b/jenkins_jobs/local_yaml.py
@@ -235,9 +235,11 @@ class OrderedConstructor(BaseConstructor):
self.flatten_mapping(node)
else:
raise yaml.constructor.ConstructorError(
- None, None,
- 'expected a mapping node, but found %s' % node.id,
- node.start_mark)
+ None,
+ None,
+ "expected a mapping node, but found %s" % node.id,
+ node.start_mark,
+ )
mapping = OrderedDict()
for key_node, value_node in node.value:
@@ -246,23 +248,26 @@ class OrderedConstructor(BaseConstructor):
hash(key)
except TypeError as exc:
raise yaml.constructor.ConstructorError(
- 'while constructing a mapping', node.start_mark,
- 'found unacceptable key (%s)' % exc, key_node.start_mark)
+ "while constructing a mapping",
+ node.start_mark,
+ "found unacceptable key (%s)" % exc,
+ key_node.start_mark,
+ )
value = self.construct_object(value_node, deep=False)
mapping[key] = value
data.update(mapping)
class OrderedRepresenter(BaseRepresenter):
-
def represent_yaml_mapping(self, mapping, flow_style=None):
- tag = u'tag:yaml.org,2002:map'
+ tag = u"tag:yaml.org,2002:map"
node = self.represent_mapping(tag, mapping, flow_style=flow_style)
return node
class LocalAnchorLoader(yaml.Loader):
"""Subclass for yaml.Loader which keeps Alias between calls"""
+
anchors = {}
def __init__(self, *args, **kwargs):
@@ -319,14 +324,13 @@ class LocalLoader(OrderedConstructor, LocalAnchorLoader):
# make sure to pop off any local settings before passing to
# the parent constructor as any unknown args may cause errors.
self.search_path = list()
- if 'search_path' in kwargs:
- for p in kwargs.pop('search_path'):
- logger.debug("Adding '{0}' to search path for include tags"
- .format(p))
+ if "search_path" in kwargs:
+ for p in kwargs.pop("search_path"):
+ logger.debug("Adding '{0}' to search path for include tags".format(p))
self.search_path.append(os.path.normpath(p))
- if 'escape_callback' in kwargs:
- self.escape_callback = kwargs.pop('escape_callback')
+ if "escape_callback" in kwargs:
+ self.escape_callback = kwargs.pop("escape_callback")
else:
self.escape_callback = self._escape
@@ -334,16 +338,17 @@ class LocalLoader(OrderedConstructor, LocalAnchorLoader):
# constructor to preserve order of maps and ensure that the order of
# keys returned is consistent across multiple python versions
- self.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
- type(self).construct_yaml_map)
+ self.add_constructor(
+ yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
+ type(self).construct_yaml_map,
+ )
- if hasattr(self.stream, 'name'):
- self.search_path.append(os.path.normpath(
- os.path.dirname(self.stream.name)))
+ if hasattr(self.stream, "name"):
+ self.search_path.append(os.path.normpath(os.path.dirname(self.stream.name)))
self.search_path.append(os.path.normpath(os.path.curdir))
def _escape(self, data):
- return re.sub(r'({|})', r'\1\1', data)
+ return re.sub(r"({|})", r"\1\1", data)
class LocalDumper(OrderedRepresenter, yaml.Dumper):
@@ -352,12 +357,10 @@ class LocalDumper(OrderedRepresenter, yaml.Dumper):
# representer to ensure conversion back looks like normal
# mapping and hides that we use OrderedDict internally
- self.add_representer(OrderedDict,
- type(self).represent_yaml_mapping)
+ self.add_representer(OrderedDict, type(self).represent_yaml_mapping)
# convert any tuples to lists as the JJB input is generally
# in list format
- self.add_representer(tuple,
- type(self).represent_list)
+ self.add_representer(tuple, type(self).represent_list)
class BaseYAMLObject(YAMLObject):
@@ -366,7 +369,7 @@ class BaseYAMLObject(YAMLObject):
class J2String(BaseYAMLObject):
- yaml_tag = u'!j2:'
+ yaml_tag = u"!j2:"
@classmethod
def from_yaml(cls, loader, node):
@@ -374,7 +377,7 @@ class J2String(BaseYAMLObject):
class YamlListJoin(BaseYAMLObject):
- yaml_tag = u'!join:'
+ yaml_tag = u"!join:"
@classmethod
def from_yaml(cls, loader, node):
@@ -382,26 +385,34 @@ class YamlListJoin(BaseYAMLObject):
delimiter = node.value[0].value
if not isinstance(node.value[1], yaml.SequenceNode):
raise yaml.constructor.ConstructorError(
- None, None, "expected sequence node for join data, but "
- "found %s" % node.value[1].id, node.start_mark)
+ None,
+ None,
+ "expected sequence node for join data, but "
+ "found %s" % node.value[1].id,
+ node.start_mark,
+ )
return delimiter.join((v.value for v in node.value[1].value))
else:
raise yaml.constructor.ConstructorError(
- None, None, "expected sequence node, but found %s" % node.id,
- node.start_mark)
+ None,
+ None,
+ "expected sequence node, but found %s" % node.id,
+ node.start_mark,
+ )
class YamlInclude(BaseYAMLObject):
- yaml_tag = u'!include:'
+ yaml_tag = u"!include:"
@classmethod
def _find_file(cls, filename, search_path):
for dirname in search_path:
candidate = os.path.expanduser(os.path.join(dirname, filename))
if os.path.isfile(candidate):
- logger.debug("Including file '{0}' from path '{1}'"
- .format(filename, dirname))
+ logger.debug(
+ "Including file '{0}' from path '{1}'".format(filename, dirname)
+ )
return candidate
return filename
@@ -415,11 +426,14 @@ class YamlInclude(BaseYAMLObject):
filename = cls._find_file(node_str, loader.search_path)
try:
- with io.open(filename, 'r', encoding='utf-8') as f:
+ with io.open(filename, "r", encoding="utf-8") as f:
return f.read()
except Exception:
- logger.error("Failed to include file using search path: '{0}'"
- .format(':'.join(loader.search_path)))
+ logger.error(
+ "Failed to include file using search path: '{0}'".format(
+ ":".join(loader.search_path)
+ )
+ )
raise
@classmethod
@@ -428,15 +442,14 @@ class YamlInclude(BaseYAMLObject):
if isinstance(contents, LazyLoader):
return contents
- data = yaml.load(contents,
- functools.partial(cls.yaml_loader,
- search_path=loader.search_path))
+ data = yaml.load(
+ contents, functools.partial(cls.yaml_loader, search_path=loader.search_path)
+ )
return data
@classmethod
def _lazy_load(cls, loader, tag, node_str):
- logger.info("Lazy loading of file template '{0}' enabled"
- .format(node_str))
+ logger.info("Lazy loading of file template '{0}' enabled".format(node_str))
return LazyLoader((cls, loader, node_str))
@classmethod
@@ -444,20 +457,24 @@ class YamlInclude(BaseYAMLObject):
if isinstance(node, yaml.ScalarNode):
return cls._from_file(loader, node)
elif isinstance(node, yaml.SequenceNode):
- contents = [cls._from_file(loader, scalar_node)
- for scalar_node in node.value]
+ contents = [
+ cls._from_file(loader, scalar_node) for scalar_node in node.value
+ ]
if any(isinstance(s, CustomLoader) for s in contents):
return CustomLoaderCollection(contents)
- return u'\n'.join(contents)
+ return u"\n".join(contents)
else:
raise yaml.constructor.ConstructorError(
- None, None, "expected either a sequence or scalar node, but "
- "found %s" % node.id, node.start_mark)
+ None,
+ None,
+ "expected either a sequence or scalar node, but " "found %s" % node.id,
+ node.start_mark,
+ )
class YamlIncludeRaw(YamlInclude):
- yaml_tag = u'!include-raw:'
+ yaml_tag = u"!include-raw:"
@classmethod
def _from_file(cls, loader, node):
@@ -465,23 +482,26 @@ class YamlIncludeRaw(YamlInclude):
class YamlIncludeRawEscape(YamlIncludeRaw):
- yaml_tag = u'!include-raw-escape:'
+ yaml_tag = u"!include-raw-escape:"
@classmethod
def from_yaml(cls, loader, node):
data = YamlIncludeRaw.from_yaml(loader, node)
if isinstance(data, LazyLoader):
- logger.warning("Replacing %s tag with %s since lazy loading means "
- "file contents will not be deep formatted for "
- "variable substitution.", cls.yaml_tag,
- YamlIncludeRaw.yaml_tag)
+ logger.warning(
+ "Replacing %s tag with %s since lazy loading means "
+ "file contents will not be deep formatted for "
+ "variable substitution.",
+ cls.yaml_tag,
+ YamlIncludeRaw.yaml_tag,
+ )
return data
else:
return loader.escape_callback(data)
class YamlIncludeJinja2(YamlIncludeRaw):
- yaml_tag = u'!include-jinja2:'
+ yaml_tag = u"!include-jinja2:"
@classmethod
def _from_file(cls, loader, node):
@@ -492,26 +512,28 @@ class YamlIncludeJinja2(YamlIncludeRaw):
class DeprecatedTag(BaseYAMLObject):
-
@classmethod
def from_yaml(cls, loader, node):
- logger.warning("tag '%s' is deprecated, switch to using '%s'",
- cls.yaml_tag, cls._new.yaml_tag)
+ logger.warning(
+ "tag '%s' is deprecated, switch to using '%s'",
+ cls.yaml_tag,
+ cls._new.yaml_tag,
+ )
return cls._new.from_yaml(loader, node)
class YamlIncludeDeprecated(DeprecatedTag):
- yaml_tag = u'!include'
+ yaml_tag = u"!include"
_new = YamlInclude
class YamlIncludeRawDeprecated(DeprecatedTag):
- yaml_tag = u'!include-raw'
+ yaml_tag = u"!include-raw"
_new = YamlIncludeRaw
class YamlIncludeRawEscapeDeprecated(DeprecatedTag):
- yaml_tag = u'!include-raw-escape'
+ yaml_tag = u"!include-raw-escape"
_new = YamlIncludeRawEscape
@@ -525,8 +547,7 @@ class Jinja2Loader(CustomLoader):
def __init__(self, contents, search_path):
self._template = jinja2.Template(contents)
self._template.environment.undefined = jinja2.StrictUndefined
- self._template.environment.loader = jinja2.FileSystemLoader(
- search_path)
+ self._template.environment.loader = jinja2.FileSystemLoader(search_path)
self._loader = self._template.environment.loader
def format(self, **kwargs):
@@ -539,11 +560,12 @@ class Jinja2Loader(CustomLoader):
class CustomLoaderCollection(object):
"""Helper class to format a collection of CustomLoader objects"""
+
def __init__(self, sequence):
self._data = sequence
def format(self, *args, **kwargs):
- return u'\n'.join(item.format(*args, **kwargs) for item in self._data)
+ return u"\n".join(item.format(*args, **kwargs) for item in self._data)
class LazyLoader(CustomLoader):
@@ -564,8 +586,8 @@ class LazyLoader(CustomLoader):
def format(self, *args, **kwargs):
node = yaml.ScalarNode(
- tag=self._node.tag,
- value=self._node.value.format(*args, **kwargs))
+ tag=self._node.tag, value=self._node.value.format(*args, **kwargs)
+ )
return self._cls.from_yaml(self._loader, node)
diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py
index 57199cdc..ab70023e 100644
--- a/jenkins_jobs/modules/builders.py
+++ b/jenkins_jobs/modules/builders.py
@@ -80,16 +80,15 @@ def shell(registry, xml_parent, data):
/../../tests/builders/fixtures/shell-unstable-return.yaml
:language: yaml
"""
- shell = XML.SubElement(xml_parent, 'hudson.tasks.Shell')
+ shell = XML.SubElement(xml_parent, "hudson.tasks.Shell")
if isinstance(data, six.string_types):
- XML.SubElement(shell, 'command').text = data
+ XML.SubElement(shell, "command").text = data
else:
mappings = [
- ('command', 'command', None),
- ('unstable-return', 'unstableReturn', 0),
+ ("command", "command", None),
+ ("unstable-return", "unstableReturn", 0),
]
- helpers.convert_mapping_to_xml(
- shell, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(shell, data, mappings, fail_required=True)
def python(registry, xml_parent, data):
@@ -105,8 +104,8 @@ def python(registry, xml_parent, data):
:language: yaml
"""
- python = XML.SubElement(xml_parent, 'hudson.plugins.python.Python')
- XML.SubElement(python, 'command').text = data
+ python = XML.SubElement(xml_parent, "hudson.plugins.python.Python")
+ XML.SubElement(python, "command").text = data
def copyartifact(registry, xml_parent, data):
@@ -185,20 +184,20 @@ def copyartifact(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/copy-artifact004.yaml
:language: yaml
"""
- t = XML.SubElement(xml_parent, 'hudson.plugins.copyartifact.CopyArtifact')
+ t = XML.SubElement(xml_parent, "hudson.plugins.copyartifact.CopyArtifact")
mappings = [
# Warning: this only works with copy artifact version 1.26+,
# for copy artifact version 1.25- the 'projectName' element needs
# to be used instead of 'project'
- ('project', 'project', None),
- ('filter', 'filter', ''),
- ('target', 'target', ''),
- ('flatten', 'flatten', False),
- ('optional', 'optional', False),
- ('do-not-fingerprint', 'doNotFingerprintArtifacts', False),
- ('parameter-filters', 'parameters', ''),
- ('exclude', 'exclude', ''),
- ('result-var-suffix', 'resultVariableSuffix', ''),
+ ("project", "project", None),
+ ("filter", "filter", ""),
+ ("target", "target", ""),
+ ("flatten", "flatten", False),
+ ("optional", "optional", False),
+ ("do-not-fingerprint", "doNotFingerprintArtifacts", False),
+ ("parameter-filters", "parameters", ""),
+ ("exclude", "exclude", ""),
+ ("result-var-suffix", "resultVariableSuffix", ""),
]
helpers.convert_mapping_to_xml(t, data, mappings, fail_required=True)
helpers.copyartifact_build_selector(t, data)
@@ -226,12 +225,13 @@ def change_assembly_version(registry, xml_parent, data):
:language: yaml
"""
- cav_builder_tag = ('org.jenkinsci.plugins.changeassemblyversion.'
- 'ChangeAssemblyVersion')
+ cav_builder_tag = (
+ "org.jenkinsci.plugins.changeassemblyversion." "ChangeAssemblyVersion"
+ )
cav = XML.SubElement(xml_parent, cav_builder_tag)
mappings = [
- ('version', 'task', '1.0.0'),
- ('assembly-file', 'assemblyFile', 'AssemblyInfo.cs'),
+ ("version", "task", "1.0.0"),
+ ("assembly-file", "assemblyFile", "AssemblyInfo.cs"),
]
helpers.convert_mapping_to_xml(cav, data, mappings, fail_required=True)
@@ -258,14 +258,12 @@ def fingerprint(registry, xml_parent, data):
"""
fingerprint = XML.SubElement(
- xml_parent, 'hudson.plugins.createfingerprint.CreateFingerprint')
- fingerprint.set('plugin', 'create-fingerprint')
+ xml_parent, "hudson.plugins.createfingerprint.CreateFingerprint"
+ )
+ fingerprint.set("plugin", "create-fingerprint")
- mapping = [
- ('targets', 'targets', ''),
- ]
- helpers.convert_mapping_to_xml(
- fingerprint, data, mapping, fail_required=True)
+ mapping = [("targets", "targets", "")]
+ helpers.convert_mapping_to_xml(fingerprint, data, mapping, fail_required=True)
def ant(registry, xml_parent, data):
@@ -307,30 +305,30 @@ def ant(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/ant002.yaml
:language: yaml
"""
- ant = XML.SubElement(xml_parent, 'hudson.tasks.Ant')
+ ant = XML.SubElement(xml_parent, "hudson.tasks.Ant")
if type(data) is str:
# Support for short form: -ant: "target"
- data = {'targets': data}
+ data = {"targets": data}
mapping = [
- ('targets', 'targets', None),
- ('buildfile', 'buildFile', None),
- ('ant-name', 'antName', 'default'),
+ ("targets", "targets", None),
+ ("buildfile", "buildFile", None),
+ ("ant-name", "antName", "default"),
]
helpers.convert_mapping_to_xml(ant, data, mapping, fail_required=False)
mapping = []
for setting, value in sorted(data.items()):
- if setting == 'properties':
+ if setting == "properties":
properties = value
- prop_string = ''
+ prop_string = ""
for prop, val in properties.items():
prop_string += "%s=%s\n" % (prop, val)
- mapping.append(('', 'properties', prop_string))
- if setting == 'java-opts':
- jopt_string = '\n'.join(value)
- mapping.append(('', 'antOpts', jopt_string))
+ mapping.append(("", "properties", prop_string))
+ if setting == "java-opts":
+ jopt_string = "\n".join(value)
+ mapping.append(("", "antOpts", jopt_string))
helpers.convert_mapping_to_xml(ant, data, mapping, fail_required=True)
@@ -375,48 +373,48 @@ def trigger_remote(registry, xml_parent, data):
/../../tests/builders/fixtures/trigger-remote/trigger-remote001.yaml
:language: yaml
"""
- triggerr = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.'
- 'ParameterizedRemoteTrigger.'
- 'RemoteBuildConfiguration')
+ triggerr = XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins."
+ "ParameterizedRemoteTrigger."
+ "RemoteBuildConfiguration",
+ )
mappings = [
- ('remote-jenkins-name', 'remoteJenkinsName', None),
- ('token', 'token', ''),
- ('job', 'job', None),
- ('should-not-fail-build', 'shouldNotFailBuild', False),
- ('poll-interval', 'pollInterval', 10),
- ('connection-retry-limit', 'connectionRetryLimit', 5),
- ('enhanced-logging', 'enhancedLogging', False),
- ('prevent-remote-build-queue', 'preventRemoteBuildQueue', False),
- ('block', 'blockBuildUntilComplete', True),
+ ("remote-jenkins-name", "remoteJenkinsName", None),
+ ("token", "token", ""),
+ ("job", "job", None),
+ ("should-not-fail-build", "shouldNotFailBuild", False),
+ ("poll-interval", "pollInterval", 10),
+ ("connection-retry-limit", "connectionRetryLimit", 5),
+ ("enhanced-logging", "enhancedLogging", False),
+ ("prevent-remote-build-queue", "preventRemoteBuildQueue", False),
+ ("block", "blockBuildUntilComplete", True),
]
- helpers.convert_mapping_to_xml(
- triggerr, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(triggerr, data, mappings, fail_required=True)
mappings = []
- if 'predefined-parameters' in data:
- parameters = data.get('predefined-parameters', '')
- XML.SubElement(triggerr, 'parameters').text = parameters
+ if "predefined-parameters" in data:
+ parameters = data.get("predefined-parameters", "")
+ XML.SubElement(triggerr, "parameters").text = parameters
params_list = parameters.split("\n")
- parameter_list = XML.SubElement(triggerr, 'parameterList')
+ parameter_list = XML.SubElement(triggerr, "parameterList")
for param in params_list:
- if param == '':
+ if param == "":
continue
- tmp = XML.SubElement(parameter_list, 'string')
+ tmp = XML.SubElement(parameter_list, "string")
tmp.text = param
- if 'property-file' in data and data['property-file'] != '':
- mappings.append(('', 'loadParamsFromFile', 'true'))
- mappings.append(('property-file', 'parameterFile', None))
+ if "property-file" in data and data["property-file"] != "":
+ mappings.append(("", "loadParamsFromFile", "true"))
+ mappings.append(("property-file", "parameterFile", None))
else:
- mappings.append(('', 'loadParamsFromFile', 'false'))
+ mappings.append(("", "loadParamsFromFile", "false"))
- mappings.append(('', 'overrideAuth', 'false'))
+ mappings.append(("", "overrideAuth", "false"))
- helpers.convert_mapping_to_xml(
- triggerr, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(triggerr, data, mappings, fail_required=True)
def trigger_builds(registry, xml_parent, data):
@@ -540,231 +538,259 @@ def trigger_builds(registry, xml_parent, data):
/../../tests/builders/fixtures/trigger-builds-configfactory-multi.yaml
:language: yaml
"""
- tbuilder = XML.SubElement(xml_parent,
- 'hudson.plugins.parameterizedtrigger.'
- 'TriggerBuilder')
- configs = XML.SubElement(tbuilder, 'configs')
+ tbuilder = XML.SubElement(
+ xml_parent, "hudson.plugins.parameterizedtrigger." "TriggerBuilder"
+ )
+ configs = XML.SubElement(tbuilder, "configs")
for project_def in data:
- if 'project' not in project_def or project_def['project'] == '':
+ if "project" not in project_def or project_def["project"] == "":
logger.debug("No project specified - skipping trigger-build")
continue
- tconfig = XML.SubElement(configs,
- 'hudson.plugins.parameterizedtrigger.'
- 'BlockableBuildTriggerConfig')
- tconfigs = XML.SubElement(tconfig, 'configs')
- if(project_def.get('current-parameters')):
- XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'CurrentBuildParameters')
- if(project_def.get('svn-revision')):
- XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'SubversionRevisionBuildParameters')
-
- if(project_def.get('git-revision')):
- helpers.append_git_revision_config(
- tconfigs, project_def['git-revision'])
-
- if(project_def.get('same-node')):
- XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'NodeParameters')
- if 'property-file' in project_def:
- params = XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'FileBuildParameters')
- mapping = [
- ('property-file', 'propertiesFile', None),
- ('property-file-fail-on-missing',
- 'failTriggerOnMissing', True),
- ]
- helpers.convert_mapping_to_xml(params,
- project_def, mapping, fail_required=True)
-
- if 'predefined-parameters' in project_def:
- params = XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'PredefinedBuildParameters')
+ tconfig = XML.SubElement(
+ configs,
+ "hudson.plugins.parameterizedtrigger." "BlockableBuildTriggerConfig",
+ )
+ tconfigs = XML.SubElement(tconfig, "configs")
+ if project_def.get("current-parameters"):
+ XML.SubElement(
+ tconfigs,
+ "hudson.plugins.parameterizedtrigger." "CurrentBuildParameters",
+ )
+ if project_def.get("svn-revision"):
+ XML.SubElement(
+ tconfigs,
+ "hudson.plugins.parameterizedtrigger."
+ "SubversionRevisionBuildParameters",
+ )
+
+ if project_def.get("git-revision"):
+ helpers.append_git_revision_config(tconfigs, project_def["git-revision"])
+
+ if project_def.get("same-node"):
+ XML.SubElement(
+ tconfigs, "hudson.plugins.parameterizedtrigger." "NodeParameters"
+ )
+ if "property-file" in project_def:
+ params = XML.SubElement(
+ tconfigs, "hudson.plugins.parameterizedtrigger." "FileBuildParameters"
+ )
mapping = [
- ('predefined-parameters', 'properties', None),
+ ("property-file", "propertiesFile", None),
+ ("property-file-fail-on-missing", "failTriggerOnMissing", True),
]
- helpers.convert_mapping_to_xml(params,
- project_def, mapping, fail_required=True)
-
- if 'bool-parameters' in project_def:
- params = XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'BooleanParameters')
- configs = XML.SubElement(params, 'configs')
- for bool_param in project_def['bool-parameters']:
- param = XML.SubElement(configs,
- 'hudson.plugins.parameterizedtrigger.'
- 'BooleanParameterConfig')
- mapping = [
- ('name', 'name', None),
- ('value', 'value', False),
- ]
- helpers.convert_mapping_to_xml(param,
- bool_param, mapping, fail_required=True)
-
- if 'node-label-name' in project_def and 'node-label' in project_def:
- node = XML.SubElement(tconfigs, 'org.jvnet.jenkins.plugins.'
- 'nodelabelparameter.parameterizedtrigger.'
- 'NodeLabelBuildParameter')
- mapping = [
- ('node-label-name', 'name', None),
- ('node-label', 'nodeLabel', None),
- ]
- helpers.convert_mapping_to_xml(node,
- project_def, mapping, fail_required=True)
-
- if 'restrict-matrix-project' in project_def:
- params = XML.SubElement(tconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'matrix.MatrixSubsetBuildParameters')
+ helpers.convert_mapping_to_xml(
+ params, project_def, mapping, fail_required=True
+ )
+
+ if "predefined-parameters" in project_def:
+ params = XML.SubElement(
+ tconfigs,
+ "hudson.plugins.parameterizedtrigger." "PredefinedBuildParameters",
+ )
+ mapping = [("predefined-parameters", "properties", None)]
+ helpers.convert_mapping_to_xml(
+ params, project_def, mapping, fail_required=True
+ )
+
+ if "bool-parameters" in project_def:
+ params = XML.SubElement(
+ tconfigs, "hudson.plugins.parameterizedtrigger." "BooleanParameters"
+ )
+ configs = XML.SubElement(params, "configs")
+ for bool_param in project_def["bool-parameters"]:
+ param = XML.SubElement(
+ configs,
+ "hudson.plugins.parameterizedtrigger." "BooleanParameterConfig",
+ )
+ mapping = [("name", "name", None), ("value", "value", False)]
+ helpers.convert_mapping_to_xml(
+ param, bool_param, mapping, fail_required=True
+ )
+
+ if "node-label-name" in project_def and "node-label" in project_def:
+ node = XML.SubElement(
+ tconfigs,
+ "org.jvnet.jenkins.plugins."
+ "nodelabelparameter.parameterizedtrigger."
+ "NodeLabelBuildParameter",
+ )
mapping = [
- ('restrict-matrix-project', 'filter', None),
+ ("node-label-name", "name", None),
+ ("node-label", "nodeLabel", None),
]
- helpers.convert_mapping_to_xml(params,
- project_def, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ node, project_def, mapping, fail_required=True
+ )
+
+ if "restrict-matrix-project" in project_def:
+ params = XML.SubElement(
+ tconfigs,
+ "hudson.plugins.parameterizedtrigger."
+ "matrix.MatrixSubsetBuildParameters",
+ )
+ mapping = [("restrict-matrix-project", "filter", None)]
+ helpers.convert_mapping_to_xml(
+ params, project_def, mapping, fail_required=True
+ )
- if(len(list(tconfigs)) == 0):
- tconfigs.set('class', 'java.util.Collections$EmptyList')
+ if len(list(tconfigs)) == 0:
+ tconfigs.set("class", "java.util.Collections$EmptyList")
- if 'parameter-factories' in project_def:
- fconfigs = XML.SubElement(tconfig, 'configFactories')
+ if "parameter-factories" in project_def:
+ fconfigs = XML.SubElement(tconfig, "configFactories")
- supported_factories = ['filebuild',
- 'binaryfile',
- 'counterbuild',
- 'allnodesforlabel',
- 'allonlinenodes']
- supported_actions = ['SKIP', 'NOPARMS', 'FAIL']
- for factory in project_def['parameter-factories']:
+ supported_factories = [
+ "filebuild",
+ "binaryfile",
+ "counterbuild",
+ "allnodesforlabel",
+ "allonlinenodes",
+ ]
+ supported_actions = ["SKIP", "NOPARMS", "FAIL"]
+ for factory in project_def["parameter-factories"]:
- if factory['factory'] not in supported_factories:
- raise InvalidAttributeError('factory',
- factory['factory'],
- supported_factories)
+ if factory["factory"] not in supported_factories:
+ raise InvalidAttributeError(
+ "factory", factory["factory"], supported_factories
+ )
- if factory['factory'] == 'filebuild':
+ if factory["factory"] == "filebuild":
params = XML.SubElement(
fconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'FileBuildParameterFactory')
- if factory['factory'] == 'binaryfile':
+ "hudson.plugins.parameterizedtrigger."
+ "FileBuildParameterFactory",
+ )
+ if factory["factory"] == "binaryfile":
params = XML.SubElement(
fconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'BinaryFileParameterFactory')
- mapping = [
- ('parameter-name', 'parameterName', None),
- ]
- helpers.convert_mapping_to_xml(params,
- factory, mapping, fail_required=True)
-
- if (factory['factory'] == 'filebuild' or
- factory['factory'] == 'binaryfile'):
+ "hudson.plugins.parameterizedtrigger."
+ "BinaryFileParameterFactory",
+ )
+ mapping = [("parameter-name", "parameterName", None)]
+ helpers.convert_mapping_to_xml(
+ params, factory, mapping, fail_required=True
+ )
+
+ if (
+ factory["factory"] == "filebuild"
+ or factory["factory"] == "binaryfile"
+ ):
mapping = [
- ('file-pattern', 'filePattern', None),
- ('no-files-found-action',
- 'noFilesFoundAction', 'SKIP', supported_actions),
+ ("file-pattern", "filePattern", None),
+ (
+ "no-files-found-action",
+ "noFilesFoundAction",
+ "SKIP",
+ supported_actions,
+ ),
]
- helpers.convert_mapping_to_xml(params,
- factory, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ params, factory, mapping, fail_required=True
+ )
- if factory['factory'] == 'counterbuild':
+ if factory["factory"] == "counterbuild":
params = XML.SubElement(
fconfigs,
- 'hudson.plugins.parameterizedtrigger.'
- 'CounterBuildParameterFactory')
+ "hudson.plugins.parameterizedtrigger."
+ "CounterBuildParameterFactory",
+ )
mapping = [
- ('from', 'from', None),
- ('to', 'to', None),
- ('step', 'step', None),
- ('parameters', 'paramExpr', ''),
- ('validation-fail',
- 'validationFail',
- 'FAIL', supported_actions),
+ ("from", "from", None),
+ ("to", "to", None),
+ ("step", "step", None),
+ ("parameters", "paramExpr", ""),
+ (
+ "validation-fail",
+ "validationFail",
+ "FAIL",
+ supported_actions,
+ ),
]
- helpers.convert_mapping_to_xml(params,
- factory, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ params, factory, mapping, fail_required=True
+ )
- if factory['factory'] == 'allnodesforlabel':
+ if factory["factory"] == "allnodesforlabel":
params = XML.SubElement(
fconfigs,
- 'org.jvnet.jenkins.plugins.nodelabelparameter.'
- 'parameterizedtrigger.'
- 'AllNodesForLabelBuildParameterFactory')
+ "org.jvnet.jenkins.plugins.nodelabelparameter."
+ "parameterizedtrigger."
+ "AllNodesForLabelBuildParameterFactory",
+ )
mapping = [
- ('name', 'name', ''),
- ('node-label', 'nodeLabel', None),
- ('ignore-offline-nodes',
- 'ignoreOfflineNodes', True),
+ ("name", "name", ""),
+ ("node-label", "nodeLabel", None),
+ ("ignore-offline-nodes", "ignoreOfflineNodes", True),
]
- helpers.convert_mapping_to_xml(params,
- factory, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ params, factory, mapping, fail_required=True
+ )
- if factory['factory'] == 'allonlinenodes':
+ if factory["factory"] == "allonlinenodes":
params = XML.SubElement(
fconfigs,
- 'org.jvnet.jenkins.plugins.nodelabelparameter.'
- 'parameterizedtrigger.'
- 'AllNodesBuildParameterFactory')
-
- projects = XML.SubElement(tconfig, 'projects')
- if isinstance(project_def['project'], list):
- projects.text = ",".join(project_def['project'])
+ "org.jvnet.jenkins.plugins.nodelabelparameter."
+ "parameterizedtrigger."
+ "AllNodesBuildParameterFactory",
+ )
+
+ projects = XML.SubElement(tconfig, "projects")
+ if isinstance(project_def["project"], list):
+ projects.text = ",".join(project_def["project"])
else:
- projects.text = project_def['project']
+ projects.text = project_def["project"]
mapping = [
- ('', 'condition', 'ALWAYS'),
- ('', 'triggerWithNoParameters', False),
- ('', 'buildAllNodesWithLabel', False),
+ ("", "condition", "ALWAYS"),
+ ("", "triggerWithNoParameters", False),
+ ("", "buildAllNodesWithLabel", False),
]
- helpers.convert_mapping_to_xml(
- tconfig, {}, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(tconfig, {}, mapping, fail_required=True)
- block = project_def.get('block', False)
+ block = project_def.get("block", False)
if block:
- block = XML.SubElement(tconfig, 'block')
- supported_thresholds = [['build-step-failure-threshold',
- 'buildStepFailureThreshold',
- 'FAILURE'],
- ['unstable-threshold',
- 'unstableThreshold',
- 'UNSTABLE'],
- ['failure-threshold',
- 'failureThreshold',
- 'FAILURE']]
- supported_threshold_values = ['never',
- hudson_model.SUCCESS['name'],
- hudson_model.UNSTABLE['name'],
- hudson_model.FAILURE['name']]
- thrsh = project_def.get('block-thresholds', False)
+ block = XML.SubElement(tconfig, "block")
+ supported_thresholds = [
+ [
+ "build-step-failure-threshold",
+ "buildStepFailureThreshold",
+ "FAILURE",
+ ],
+ ["unstable-threshold", "unstableThreshold", "UNSTABLE"],
+ ["failure-threshold", "failureThreshold", "FAILURE"],
+ ]
+ supported_threshold_values = [
+ "never",
+ hudson_model.SUCCESS["name"],
+ hudson_model.UNSTABLE["name"],
+ hudson_model.FAILURE["name"],
+ ]
+ thrsh = project_def.get("block-thresholds", False)
for toptname, txmltag, tvalue in supported_thresholds:
if thrsh:
tvalue = thrsh.get(toptname, tvalue)
if tvalue.lower() == supported_threshold_values[0]:
continue
if tvalue.upper() not in supported_threshold_values:
- raise InvalidAttributeError(toptname,
- tvalue,
- supported_threshold_values)
+ raise InvalidAttributeError(
+ toptname, tvalue, supported_threshold_values
+ )
th = XML.SubElement(block, txmltag)
mapping = [
- ('name', 'name', None),
- ('ordinal', 'ordinal', None),
- ('color', 'color', None),
- ('', 'completeBuild', True),
+ ("name", "name", None),
+ ("ordinal", "ordinal", None),
+ ("color", "color", None),
+ ("", "completeBuild", True),
]
- helpers.convert_mapping_to_xml(th,
- hudson_model.THRESHOLDS[tvalue.upper()],
- mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ th,
+ hudson_model.THRESHOLDS[tvalue.upper()],
+ mapping,
+ fail_required=True,
+ )
# If configs is empty, remove the entire tbuilder tree.
- if(len(configs) == 0):
+ if len(configs) == 0:
logger.debug("Pruning empty TriggerBuilder tree.")
xml_parent.remove(tbuilder)
@@ -782,11 +808,8 @@ def builders_from(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/builders-from.yaml
:language: yaml
"""
- pbs = XML.SubElement(xml_parent,
- 'hudson.plugins.templateproject.ProxyBuilder')
- mapping = [
- ('', 'projectName', data),
- ]
+ pbs = XML.SubElement(xml_parent, "hudson.plugins.templateproject.ProxyBuilder")
+ mapping = [("", "projectName", data)]
helpers.convert_mapping_to_xml(pbs, {}, mapping, fail_required=True)
@@ -853,46 +876,46 @@ def http_request(registry, xml_parent, data):
:language: yaml
"""
- http_request = XML.SubElement(xml_parent,
- 'jenkins.plugins.http__request.HttpRequest')
- http_request.set('plugin', 'http_request')
-
- valid_modes = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD']
- valid_types = ['NOT_SET', 'TEXT_HTML', 'APPLICATION_JSON',
- 'APPLICATION_TAR', 'APPLICATION_ZIP',
- 'APPLICATION_OCTETSTREAM']
+ http_request = XML.SubElement(
+ xml_parent, "jenkins.plugins.http__request.HttpRequest"
+ )
+ http_request.set("plugin", "http_request")
+
+ valid_modes = ["GET", "POST", "PUT", "DELETE", "HEAD"]
+ valid_types = [
+ "NOT_SET",
+ "TEXT_HTML",
+ "APPLICATION_JSON",
+ "APPLICATION_TAR",
+ "APPLICATION_ZIP",
+ "APPLICATION_OCTETSTREAM",
+ ]
mappings = [
- ('url', 'url', None),
- ('mode', 'httpMode', 'GET', valid_modes),
- ('content-type', 'contentType', 'NOT_SET', valid_types),
- ('accept-type', 'acceptType', 'NOT_SET', valid_types),
- ('output-file', 'outputFile', ''),
- ('console-log', 'consoleLogResponseBody', False),
- ('pass-build', 'passBuildParameters', False),
- ('time-out', 'timeout', 0),
- ('valid-response-codes', 'validResponseCodes', ''),
- ('valid-response-content', 'validResponseContent', ''),
+ ("url", "url", None),
+ ("mode", "httpMode", "GET", valid_modes),
+ ("content-type", "contentType", "NOT_SET", valid_types),
+ ("accept-type", "acceptType", "NOT_SET", valid_types),
+ ("output-file", "outputFile", ""),
+ ("console-log", "consoleLogResponseBody", False),
+ ("pass-build", "passBuildParameters", False),
+ ("time-out", "timeout", 0),
+ ("valid-response-codes", "validResponseCodes", ""),
+ ("valid-response-content", "validResponseContent", ""),
]
- helpers.convert_mapping_to_xml(
- http_request, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(http_request, data, mappings, fail_required=True)
- if 'authentication-key' in data:
- XML.SubElement(
- http_request, 'authentication').text = data['authentication-key']
+ if "authentication-key" in data:
+ XML.SubElement(http_request, "authentication").text = data["authentication-key"]
- if 'custom-headers' in data:
- customHeader = XML.SubElement(http_request, 'customHeaders')
- header_mappings = [
- ('name', 'name', None),
- ('value', 'value', None),
- ]
- for customhead in data['custom-headers']:
- pair = XML.SubElement(customHeader, 'pair')
- helpers.convert_mapping_to_xml(pair,
- customhead,
- header_mappings,
- fail_required=True)
+ if "custom-headers" in data:
+ customHeader = XML.SubElement(http_request, "customHeaders")
+ header_mappings = [("name", "name", None), ("value", "value", None)]
+ for customhead in data["custom-headers"]:
+ pair = XML.SubElement(customHeader, "pair")
+ helpers.convert_mapping_to_xml(
+ pair, customhead, header_mappings, fail_required=True
+ )
def inject(registry, xml_parent, data):
@@ -911,13 +934,13 @@ def inject(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/inject.yaml
:language: yaml
"""
- eib = XML.SubElement(xml_parent, 'EnvInjectBuilder')
- info = XML.SubElement(eib, 'info')
+ eib = XML.SubElement(xml_parent, "EnvInjectBuilder")
+ info = XML.SubElement(eib, "info")
mapping = [
- ('properties-file', 'propertiesFilePath', None),
- ('properties-content', 'propertiesContent', None),
- ('script-file', 'scriptFilePath', None),
- ('script-content', 'scriptContent', None),
+ ("properties-file", "propertiesFilePath", None),
+ ("properties-content", "propertiesContent", None),
+ ("script-file", "scriptFilePath", None),
+ ("script-content", "scriptContent", None),
]
helpers.convert_mapping_to_xml(info, data, mapping, fail_required=False)
@@ -964,35 +987,35 @@ def kmap(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/kmap-full.yaml
:language: yaml
"""
- kmap = XML.SubElement(
- xml_parent, 'org.jenkinsci.plugins.KmapJenkinsBuilder')
+ kmap = XML.SubElement(xml_parent, "org.jenkinsci.plugins.KmapJenkinsBuilder")
- kmap.set('plugin', 'kmap-jenkins')
- publish = data.get('publish-optional', False)
+ kmap.set("plugin", "kmap-jenkins")
+ publish = data.get("publish-optional", False)
mapping = [
- ('username', 'username', None),
- ('password', 'password', None),
- ('url', 'kmapClient', None),
- ('categories', 'categories', None),
- ('file-path', 'filePath', None),
- ('app-name', 'appName', None),
- ('bundle', 'bundle', ''),
- ('version', 'version', None),
- ('description', 'description', ''),
- ('icon-path', 'iconPath', ''),
+ ("username", "username", None),
+ ("password", "password", None),
+ ("url", "kmapClient", None),
+ ("categories", "categories", None),
+ ("file-path", "filePath", None),
+ ("app-name", "appName", None),
+ ("bundle", "bundle", ""),
+ ("version", "version", None),
+ ("description", "description", ""),
+ ("icon-path", "iconPath", ""),
]
helpers.convert_mapping_to_xml(kmap, data, mapping, fail_required=True)
if publish is True:
- publish_optional = XML.SubElement(kmap, 'publishOptional')
+ publish_optional = XML.SubElement(kmap, "publishOptional")
publish_mapping = [
- ('groups', 'teams', ''),
- ('users', 'users', ''),
- ('notify-users', 'sendNotifications', False),
+ ("groups", "teams", ""),
+ ("users", "users", ""),
+ ("notify-users", "sendNotifications", False),
]
helpers.convert_mapping_to_xml(
- publish_optional, data, publish_mapping, fail_required=True)
+ publish_optional, data, publish_mapping, fail_required=True
+ )
def artifact_resolver(registry, xml_parent, data):
@@ -1030,35 +1053,36 @@ def artifact_resolver(registry, xml_parent, data):
:language: yaml
"""
ar = XML.SubElement(
- xml_parent,
- 'org.jvnet.hudson.plugins.repositoryconnector.ArtifactResolver')
+ xml_parent, "org.jvnet.hudson.plugins.repositoryconnector.ArtifactResolver"
+ )
mapping = [
- ('target-directory', 'targetDirectory', None),
- ('fail-on-error', 'failOnError', False),
- ('repository-logging', 'enableRepoLogging', False),
- ('', 'snapshotUpdatePolicy', 'never'),
- ('', 'releaseUpdatePolicy', 'never'),
- ('', 'snapshotChecksumPolicy', 'warn'),
- ('', 'releaseChecksumPolicy', 'warn'),
+ ("target-directory", "targetDirectory", None),
+ ("fail-on-error", "failOnError", False),
+ ("repository-logging", "enableRepoLogging", False),
+ ("", "snapshotUpdatePolicy", "never"),
+ ("", "releaseUpdatePolicy", "never"),
+ ("", "snapshotChecksumPolicy", "warn"),
+ ("", "releaseChecksumPolicy", "warn"),
]
helpers.convert_mapping_to_xml(ar, data, mapping, fail_required=True)
- artifact_top = XML.SubElement(ar, 'artifacts')
- artifacts = data['artifacts']
+ artifact_top = XML.SubElement(ar, "artifacts")
+ artifacts = data["artifacts"]
artifacts_mapping = [
- ('group-id', 'groupId', None),
- ('artifact-id', 'artifactId', None),
- ('version', 'version', None),
- ('classifier', 'classifier', ''),
- ('extension', 'extension', 'jar'),
- ('target-file-name', 'targetFileName', ''),
+ ("group-id", "groupId", None),
+ ("artifact-id", "artifactId", None),
+ ("version", "version", None),
+ ("classifier", "classifier", ""),
+ ("extension", "extension", "jar"),
+ ("target-file-name", "targetFileName", ""),
]
for artifact in artifacts:
rcartifact = XML.SubElement(
- artifact_top,
- 'org.jvnet.hudson.plugins.repositoryconnector.Artifact')
+ artifact_top, "org.jvnet.hudson.plugins.repositoryconnector.Artifact"
+ )
helpers.convert_mapping_to_xml(
- rcartifact, artifact, artifacts_mapping, fail_required=True)
+ rcartifact, artifact, artifacts_mapping, fail_required=True
+ )
def doxygen(registry, xml_parent, data):
@@ -1079,13 +1103,12 @@ def doxygen(registry, xml_parent, data):
:language: yaml
"""
- doxygen = XML.SubElement(xml_parent,
- 'hudson.plugins.doxygen.DoxygenBuilder')
+ doxygen = XML.SubElement(xml_parent, "hudson.plugins.doxygen.DoxygenBuilder")
mappings = [
- ('doxyfile', 'doxyfilePath', None),
- ('install', 'installationName', None),
- ('ignore-failure', 'continueOnBuildFailure', False),
- ('unstable-warning', 'unstableIfWarnings', False),
+ ("doxyfile", "doxyfilePath", None),
+ ("install", "installationName", None),
+ ("ignore-failure", "continueOnBuildFailure", False),
+ ("unstable-warning", "unstableIfWarnings", False),
]
helpers.convert_mapping_to_xml(doxygen, data, mappings, fail_required=True)
@@ -1114,23 +1137,22 @@ def gradle(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/gradle.yaml
:language: yaml
"""
- gradle = XML.SubElement(xml_parent, 'hudson.plugins.gradle.Gradle')
+ gradle = XML.SubElement(xml_parent, "hudson.plugins.gradle.Gradle")
- XML.SubElement(gradle, 'description').text = ''
+ XML.SubElement(gradle, "description").text = ""
mappings = [
- ('build-file', 'buildFile', 'build.gradle'),
- ('tasks', 'tasks', None),
- ('root-build-script-dir', 'rootBuildScriptDir', ''),
- ('gradle-name', 'gradleName', ''),
- ('wrapper', 'useWrapper', False),
- ('executable', 'makeExecutable', False),
- ('use-root-dir', 'fromRootBuildScriptDir', False),
+ ("build-file", "buildFile", "build.gradle"),
+ ("tasks", "tasks", None),
+ ("root-build-script-dir", "rootBuildScriptDir", ""),
+ ("gradle-name", "gradleName", ""),
+ ("wrapper", "useWrapper", False),
+ ("executable", "makeExecutable", False),
+ ("use-root-dir", "fromRootBuildScriptDir", False),
]
helpers.convert_mapping_to_xml(gradle, data, mappings, fail_required=True)
- XML.SubElement(gradle, 'switches').text = '\n'.join(
- data.get('switches', []))
+ XML.SubElement(gradle, "switches").text = "\n".join(data.get("switches", []))
def _groovy_common_scriptSource(data):
@@ -1138,23 +1160,17 @@ def _groovy_common_scriptSource(data):
"""
scriptSource = XML.Element("scriptSource")
- if 'command' in data and 'file' in data:
+ if "command" in data and "file" in data:
raise JenkinsJobsException("Use just one of 'command' or 'file'")
- if 'command' in data:
- mapping = [
- ('command', 'command', None),
- ]
- helpers.convert_mapping_to_xml(
- scriptSource, data, mapping, fail_required=True)
- scriptSource.set('class', 'hudson.plugins.groovy.StringScriptSource')
- elif 'file' in data:
- mapping = [
- ('file', 'scriptFile', None),
- ]
- helpers.convert_mapping_to_xml(
- scriptSource, data, mapping, fail_required=True)
- scriptSource.set('class', 'hudson.plugins.groovy.FileScriptSource')
+ if "command" in data:
+ mapping = [("command", "command", None)]
+ helpers.convert_mapping_to_xml(scriptSource, data, mapping, fail_required=True)
+ scriptSource.set("class", "hudson.plugins.groovy.StringScriptSource")
+ elif "file" in data:
+ mapping = [("file", "scriptFile", None)]
+ helpers.convert_mapping_to_xml(scriptSource, data, mapping, fail_required=True)
+ scriptSource.set("class", "hudson.plugins.groovy.FileScriptSource")
else:
raise JenkinsJobsException("A groovy command or file is required")
@@ -1195,17 +1211,17 @@ def groovy(registry, xml_parent, data):
:language: yaml
"""
- root_tag = 'hudson.plugins.groovy.Groovy'
+ root_tag = "hudson.plugins.groovy.Groovy"
groovy = XML.SubElement(xml_parent, root_tag)
groovy.append(_groovy_common_scriptSource(data))
mappings = [
- ('version', 'groovyName', '(Default)'),
- ('parameters', 'parameters', ''),
- ('script-parameters', 'scriptParameters', ''),
- ('properties', 'properties', ''),
- ('java-opts', 'javaOpts', ''),
- ('class-path', 'classPath', ''),
+ ("version", "groovyName", "(Default)"),
+ ("parameters", "parameters", ""),
+ ("script-parameters", "scriptParameters", ""),
+ ("properties", "properties", ""),
+ ("java-opts", "javaOpts", ""),
+ ("class-path", "classPath", ""),
]
helpers.convert_mapping_to_xml(groovy, data, mappings, fail_required=True)
@@ -1233,16 +1249,12 @@ def system_groovy(registry, xml_parent, data):
:language: yaml
"""
- root_tag = 'hudson.plugins.groovy.SystemGroovy'
+ root_tag = "hudson.plugins.groovy.SystemGroovy"
sysgroovy = XML.SubElement(xml_parent, root_tag)
sysgroovy.append(_groovy_common_scriptSource(data))
- mapping = [
- ('bindings', 'bindings', ''),
- ('class-path', 'classpath', ''),
- ]
- helpers.convert_mapping_to_xml(
- sysgroovy, data, mapping, fail_required=True)
+ mapping = [("bindings", "bindings", ""), ("class-path", "classpath", "")]
+ helpers.convert_mapping_to_xml(sysgroovy, data, mapping, fail_required=True)
def batch(registry, xml_parent, data):
@@ -1256,8 +1268,8 @@ def batch(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/batch.yaml
:language: yaml
"""
- batch = XML.SubElement(xml_parent, 'hudson.tasks.BatchFile')
- XML.SubElement(batch, 'command').text = data
+ batch = XML.SubElement(xml_parent, "hudson.tasks.BatchFile")
+ XML.SubElement(batch, "command").text = data
def powershell(registry, xml_parent, data):
@@ -1272,8 +1284,8 @@ def powershell(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/powershell.yaml
:language: yaml
"""
- ps = XML.SubElement(xml_parent, 'hudson.plugins.powershell.PowerShell')
- XML.SubElement(ps, 'command').text = data
+ ps = XML.SubElement(xml_parent, "hudson.plugins.powershell.PowerShell")
+ XML.SubElement(ps, "command").text = data
def msbuild(registry, xml_parent, data):
@@ -1302,25 +1314,23 @@ def msbuild(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/msbuild-minimal.yaml
:language: yaml
"""
- msbuilder = XML.SubElement(xml_parent,
- 'hudson.plugins.msbuild.MsBuildBuilder')
- msbuilder.set('plugin', 'msbuild')
+ msbuilder = XML.SubElement(xml_parent, "hudson.plugins.msbuild.MsBuildBuilder")
+ msbuilder.set("plugin", "msbuild")
mapping = [
- ('msbuild-version', 'msBuildName', '(Default)'),
- ('solution-file', 'msBuildFile', None),
- ('extra-parameters', 'cmdLineArgs', ''),
- ('pass-build-variables', 'buildVariablesAsProperties', True),
- ('continue-on-build-failure', 'continueOnBuildFailure', False),
- ('unstable-if-warnings', 'unstableIfWarnings', False),
+ ("msbuild-version", "msBuildName", "(Default)"),
+ ("solution-file", "msBuildFile", None),
+ ("extra-parameters", "cmdLineArgs", ""),
+ ("pass-build-variables", "buildVariablesAsProperties", True),
+ ("continue-on-build-failure", "continueOnBuildFailure", False),
+ ("unstable-if-warnings", "unstableIfWarnings", False),
]
- helpers.convert_mapping_to_xml(
- msbuilder, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(msbuilder, data, mapping, fail_required=True)
def create_builders(registry, step):
dummy_parent = XML.Element("dummy")
- registry.dispatch('builder', dummy_parent, step)
+ registry.dispatch("builder", dummy_parent, step)
return list(dummy_parent)
@@ -1532,239 +1542,234 @@ def conditional_step(registry, xml_parent, data):
/../../tests/builders/fixtures/conditional-step-and.yaml
:language: yaml
"""
+
def build_condition(cdata, cond_root_tag, condition_tag):
- kind = cdata['condition-kind']
+ kind = cdata["condition-kind"]
ctag = XML.SubElement(cond_root_tag, condition_tag)
- core_prefix = 'org.jenkins_ci.plugins.run_condition.core.'
- logic_prefix = 'org.jenkins_ci.plugins.run_condition.logic.'
+ core_prefix = "org.jenkins_ci.plugins.run_condition.core."
+ logic_prefix = "org.jenkins_ci.plugins.run_condition.logic."
if kind == "always":
- ctag.set('class', core_prefix + 'AlwaysRun')
+ ctag.set("class", core_prefix + "AlwaysRun")
elif kind == "never":
- ctag.set('class', core_prefix + 'NeverRun')
+ ctag.set("class", core_prefix + "NeverRun")
elif kind == "boolean-expression":
- ctag.set('class', core_prefix + 'BooleanCondition')
- mapping = [
- ('condition-expression', 'token', None),
- ]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ ctag.set("class", core_prefix + "BooleanCondition")
+ mapping = [("condition-expression", "token", None)]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "build-cause":
- ctag.set('class', core_prefix + 'CauseCondition')
- cause_list = ('USER_CAUSE', 'SCM_CAUSE', 'TIMER_CAUSE',
- 'CLI_CAUSE', 'REMOTE_CAUSE', 'UPSTREAM_CAUSE',
- 'FS_CAUSE', 'URL_CAUSE', 'IVY_CAUSE',
- 'SCRIPT_CAUSE', 'BUILDRESULT_CAUSE')
+ ctag.set("class", core_prefix + "CauseCondition")
+ cause_list = (
+ "USER_CAUSE",
+ "SCM_CAUSE",
+ "TIMER_CAUSE",
+ "CLI_CAUSE",
+ "REMOTE_CAUSE",
+ "UPSTREAM_CAUSE",
+ "FS_CAUSE",
+ "URL_CAUSE",
+ "IVY_CAUSE",
+ "SCRIPT_CAUSE",
+ "BUILDRESULT_CAUSE",
+ )
mapping = [
- ('cause', 'buildCause', 'USER_CAUSE', cause_list),
- ('exclusive-cause', "exclusiveCause", False),
+ ("cause", "buildCause", "USER_CAUSE", cause_list),
+ ("exclusive-cause", "exclusiveCause", False),
]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "day-of-week":
- ctag.set('class', core_prefix + 'DayCondition')
- day_selector_class_prefix = core_prefix + 'DayCondition$'
+ ctag.set("class", core_prefix + "DayCondition")
+ day_selector_class_prefix = core_prefix + "DayCondition$"
day_selector_classes = {
- 'weekend': day_selector_class_prefix + 'Weekend',
- 'weekday': day_selector_class_prefix + 'Weekday',
- 'select-days': day_selector_class_prefix + 'SelectDays',
+ "weekend": day_selector_class_prefix + "Weekend",
+ "weekday": day_selector_class_prefix + "Weekday",
+ "select-days": day_selector_class_prefix + "SelectDays",
}
- day_selector = cdata.get('day-selector', 'weekend')
+ day_selector = cdata.get("day-selector", "weekend")
if day_selector not in day_selector_classes:
- raise InvalidAttributeError('day-selector', day_selector,
- day_selector_classes)
+ raise InvalidAttributeError(
+ "day-selector", day_selector, day_selector_classes
+ )
day_selector_tag = XML.SubElement(ctag, "daySelector")
- day_selector_tag.set('class', day_selector_classes[day_selector])
+ day_selector_tag.set("class", day_selector_classes[day_selector])
if day_selector == "select-days":
days_tag = XML.SubElement(day_selector_tag, "days")
- day_tag_text = ('org.jenkins__ci.plugins.run__condition.'
- 'core.DayCondition_-Day')
- inp_days = cdata.get('days') if cdata.get('days') else {}
- days = ['SUN', 'MON', 'TUES', 'WED', 'THURS', 'FRI', 'SAT']
+ day_tag_text = (
+ "org.jenkins__ci.plugins.run__condition." "core.DayCondition_-Day"
+ )
+ inp_days = cdata.get("days") if cdata.get("days") else {}
+ days = ["SUN", "MON", "TUES", "WED", "THURS", "FRI", "SAT"]
for day_no, day in enumerate(days, 1):
day_tag = XML.SubElement(days_tag, day_tag_text)
- mapping = [
- ('', 'day', day_no),
- (day, "selected", False),
- ]
- helpers.convert_mapping_to_xml(day_tag,
- inp_days, mapping, fail_required=True)
- mapping = [
- ('use-build-time', "useBuildTime", False),
- ]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ mapping = [("", "day", day_no), (day, "selected", False)]
+ helpers.convert_mapping_to_xml(
+ day_tag, inp_days, mapping, fail_required=True
+ )
+ mapping = [("use-build-time", "useBuildTime", False)]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "execution-node":
- ctag.set('class', core_prefix + 'NodeCondition')
+ ctag.set("class", core_prefix + "NodeCondition")
allowed_nodes_tag = XML.SubElement(ctag, "allowedNodes")
- for node in cdata['nodes']:
- mapping = [
- ('', "string", node),
- ]
- helpers.convert_mapping_to_xml(allowed_nodes_tag,
- cdata, mapping, fail_required=True)
+ for node in cdata["nodes"]:
+ mapping = [("", "string", node)]
+ helpers.convert_mapping_to_xml(
+ allowed_nodes_tag, cdata, mapping, fail_required=True
+ )
elif kind == "strings-match":
- ctag.set('class', core_prefix + 'StringsMatchCondition')
+ ctag.set("class", core_prefix + "StringsMatchCondition")
mapping = [
- ('condition-string1', "arg1", ''),
- ('condition-string2', "arg2", ''),
- ('condition-case-insensitive', "ignoreCase", False),
+ ("condition-string1", "arg1", ""),
+ ("condition-string2", "arg2", ""),
+ ("condition-case-insensitive", "ignoreCase", False),
]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "current-status":
- ctag.set('class', core_prefix + 'StatusCondition')
- wr = XML.SubElement(ctag, 'worstResult')
- wr_name = cdata.get('condition-worst', 'SUCCESS')
+ ctag.set("class", core_prefix + "StatusCondition")
+ wr = XML.SubElement(ctag, "worstResult")
+ wr_name = cdata.get("condition-worst", "SUCCESS")
if wr_name not in hudson_model.THRESHOLDS:
- raise InvalidAttributeError('condition-worst', wr_name,
- hudson_model.THRESHOLDS.keys())
+ raise InvalidAttributeError(
+ "condition-worst", wr_name, hudson_model.THRESHOLDS.keys()
+ )
wr_threshold = hudson_model.THRESHOLDS[wr_name]
mapping = [
- ('name', 'name', None),
- ('ordinal', 'ordinal', None),
- ('color', 'color', 'color'),
- ('complete', 'completeBuild', None),
+ ("name", "name", None),
+ ("ordinal", "ordinal", None),
+ ("color", "color", "color"),
+ ("complete", "completeBuild", None),
]
- helpers.convert_mapping_to_xml(wr,
- wr_threshold, mapping, fail_required=True)
- br = XML.SubElement(ctag, 'bestResult')
- br_name = cdata.get('condition-best', 'SUCCESS')
+ helpers.convert_mapping_to_xml(
+ wr, wr_threshold, mapping, fail_required=True
+ )
+ br = XML.SubElement(ctag, "bestResult")
+ br_name = cdata.get("condition-best", "SUCCESS")
if br_name not in hudson_model.THRESHOLDS:
- raise InvalidAttributeError('condition-best', br_name,
- hudson_model.THRESHOLDS.keys())
+ raise InvalidAttributeError(
+ "condition-best", br_name, hudson_model.THRESHOLDS.keys()
+ )
br_threshold = hudson_model.THRESHOLDS[br_name]
mapping = [
- ('name', 'name', None),
- ('ordinal', 'ordinal', None),
- ('color', 'color', 'color'),
- ('complete', 'completeBuild', None),
- ]
- helpers.convert_mapping_to_xml(br,
- br_threshold, mapping, fail_required=True)
- elif kind == "shell":
- ctag.set('class',
- 'org.jenkins_ci.plugins.run_condition.contributed.'
- 'ShellCondition')
- mapping = [
- ('condition-command', 'command', ''),
+ ("name", "name", None),
+ ("ordinal", "ordinal", None),
+ ("color", "color", "color"),
+ ("complete", "completeBuild", None),
]
helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ br, br_threshold, mapping, fail_required=True
+ )
+ elif kind == "shell":
+ ctag.set(
+ "class",
+ "org.jenkins_ci.plugins.run_condition.contributed." "ShellCondition",
+ )
+ mapping = [("condition-command", "command", "")]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "windows-shell":
- ctag.set('class',
- 'org.jenkins_ci.plugins.run_condition.contributed.'
- 'BatchFileCondition')
- mapping = [
- ('condition-command', 'command', ''),
- ]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ ctag.set(
+ "class",
+ "org.jenkins_ci.plugins.run_condition.contributed."
+ "BatchFileCondition",
+ )
+ mapping = [("condition-command", "command", "")]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "file-exists" or kind == "files-match":
if kind == "file-exists":
- ctag.set('class', core_prefix + 'FileExistsCondition')
- mapping = [
- ('condition-filename', 'file', None),
- ]
- helpers.convert_mapping_to_xml(ctag, cdata, mapping,
- fail_required=True)
+ ctag.set("class", core_prefix + "FileExistsCondition")
+ mapping = [("condition-filename", "file", None)]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
else:
- ctag.set('class', core_prefix + 'FilesMatchCondition')
- XML.SubElement(ctag, "includes").text = ",".join(cdata.get(
- 'include-pattern', ''))
- XML.SubElement(ctag, "excludes").text = ",".join(cdata.get(
- 'exclude-pattern', ''))
- basedir_class_prefix = ('org.jenkins_ci.plugins.run_condition.'
- 'common.BaseDirectory$')
+ ctag.set("class", core_prefix + "FilesMatchCondition")
+ XML.SubElement(ctag, "includes").text = ",".join(
+ cdata.get("include-pattern", "")
+ )
+ XML.SubElement(ctag, "excludes").text = ",".join(
+ cdata.get("exclude-pattern", "")
+ )
+ basedir_class_prefix = (
+ "org.jenkins_ci.plugins.run_condition." "common.BaseDirectory$"
+ )
basedir_classes = {
- 'workspace': basedir_class_prefix + 'Workspace',
- 'artifact-directory': basedir_class_prefix + 'ArtifactsDir',
- 'jenkins-home': basedir_class_prefix + 'JenkinsHome'
+ "workspace": basedir_class_prefix + "Workspace",
+ "artifact-directory": basedir_class_prefix + "ArtifactsDir",
+ "jenkins-home": basedir_class_prefix + "JenkinsHome",
}
- basedir = cdata.get('condition-basedir', 'workspace')
+ basedir = cdata.get("condition-basedir", "workspace")
if basedir not in basedir_classes:
- raise InvalidAttributeError('condition-basedir', basedir,
- basedir_classes)
- XML.SubElement(ctag, "baseDir").set('class',
- basedir_classes[basedir])
+ raise InvalidAttributeError(
+ "condition-basedir", basedir, basedir_classes
+ )
+ XML.SubElement(ctag, "baseDir").set("class", basedir_classes[basedir])
elif kind == "num-comp":
- ctag.set('class', core_prefix + 'NumericalComparisonCondition')
- mapping = [
- ('lhs', 'lhs', None),
- ('rhs', 'rhs', None),
- ]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
- comp_class_prefix = core_prefix + 'NumericalComparisonCondition$'
+ ctag.set("class", core_prefix + "NumericalComparisonCondition")
+ mapping = [("lhs", "lhs", None), ("rhs", "rhs", None)]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
+ comp_class_prefix = core_prefix + "NumericalComparisonCondition$"
comp_classes = {
- 'less-than': comp_class_prefix + 'LessThan',
- 'greater-than': comp_class_prefix + 'GreaterThan',
- 'equal': comp_class_prefix + 'EqualTo',
- 'not-equal': comp_class_prefix + 'NotEqualTo',
- 'less-than-equal': comp_class_prefix + 'LessThanOrEqualTo',
- 'greater-than-equal': comp_class_prefix +
- 'GreaterThanOrEqualTo'
+ "less-than": comp_class_prefix + "LessThan",
+ "greater-than": comp_class_prefix + "GreaterThan",
+ "equal": comp_class_prefix + "EqualTo",
+ "not-equal": comp_class_prefix + "NotEqualTo",
+ "less-than-equal": comp_class_prefix + "LessThanOrEqualTo",
+ "greater-than-equal": comp_class_prefix + "GreaterThanOrEqualTo",
}
- comp = cdata.get('comparator', 'less-than')
+ comp = cdata.get("comparator", "less-than")
if comp not in comp_classes:
- raise InvalidAttributeError('comparator', comp, comp_classes)
- XML.SubElement(ctag, "comparator").set('class',
- comp_classes[comp])
+ raise InvalidAttributeError("comparator", comp, comp_classes)
+ XML.SubElement(ctag, "comparator").set("class", comp_classes[comp])
elif kind == "regex-match":
- ctag.set('class', core_prefix + 'ExpressionCondition')
- mapping = [
- ('regex', 'expression', ''),
- ('label', 'label', ''),
- ]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ ctag.set("class", core_prefix + "ExpressionCondition")
+ mapping = [("regex", "expression", ""), ("label", "label", "")]
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "time":
- ctag.set('class', core_prefix + 'TimeCondition')
+ ctag.set("class", core_prefix + "TimeCondition")
mapping = [
- ('earliest-hour', 'earliestHours', '09'),
- ('earliest-min', 'earliestMinutes', '00'),
- ('latest-hour', 'latestHours', '17'),
- ('latest-min', 'latestMinutes', '30'),
- ('use-build-time', 'useBuildTime', False),
+ ("earliest-hour", "earliestHours", "09"),
+ ("earliest-min", "earliestMinutes", "00"),
+ ("latest-hour", "latestHours", "17"),
+ ("latest-min", "latestMinutes", "30"),
+ ("use-build-time", "useBuildTime", False),
]
- helpers.convert_mapping_to_xml(
- ctag, cdata, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(ctag, cdata, mapping, fail_required=True)
elif kind == "not":
- ctag.set('class', logic_prefix + 'Not')
+ ctag.set("class", logic_prefix + "Not")
try:
- notcondition = cdata['condition-operand']
+ notcondition = cdata["condition-operand"]
except KeyError:
- raise MissingAttributeError('condition-operand')
+ raise MissingAttributeError("condition-operand")
build_condition(notcondition, ctag, "condition")
elif kind == "and" or "or":
if kind == "and":
- ctag.set('class', logic_prefix + 'And')
+ ctag.set("class", logic_prefix + "And")
else:
- ctag.set('class', logic_prefix + 'Or')
+ ctag.set("class", logic_prefix + "Or")
conditions_tag = XML.SubElement(ctag, "conditions")
- container_tag_text = ('org.jenkins__ci.plugins.run__condition.'
- 'logic.ConditionContainer')
+ container_tag_text = (
+ "org.jenkins__ci.plugins.run__condition." "logic.ConditionContainer"
+ )
try:
- conditions_list = cdata['condition-operands']
+ conditions_list = cdata["condition-operands"]
except KeyError:
- raise MissingAttributeError('condition-operands')
+ raise MissingAttributeError("condition-operands")
for condition in conditions_list:
- conditions_container_tag = XML.SubElement(conditions_tag,
- container_tag_text)
- build_condition(condition, conditions_container_tag,
- "condition")
+ conditions_container_tag = XML.SubElement(
+ conditions_tag, container_tag_text
+ )
+ build_condition(condition, conditions_container_tag, "condition")
def build_step(parent, step):
for edited_node in create_builders(registry, step):
if not has_multiple_steps:
- edited_node.set('class', edited_node.tag)
- edited_node.tag = 'buildStep'
+ edited_node.set("class", edited_node.tag)
+ edited_node.tag = "buildStep"
parent.append(edited_node)
- cond_builder_tag = ('org.jenkinsci.plugins.conditionalbuildstep.'
- 'singlestep.SingleConditionalBuilder')
- cond_builders_tag = ('org.jenkinsci.plugins.conditionalbuildstep.'
- 'ConditionalBuilder')
- steps = data['steps']
+ cond_builder_tag = (
+ "org.jenkinsci.plugins.conditionalbuildstep."
+ "singlestep.SingleConditionalBuilder"
+ )
+ cond_builders_tag = (
+ "org.jenkinsci.plugins.conditionalbuildstep." "ConditionalBuilder"
+ )
+ steps = data["steps"]
has_multiple_steps = len(steps) > 1
if has_multiple_steps:
@@ -1777,19 +1782,17 @@ def conditional_step(registry, xml_parent, data):
condition_tag = "condition"
build_condition(data, root_tag, condition_tag)
- evaluation_classes_pkg = 'org.jenkins_ci.plugins.run_condition'
+ evaluation_classes_pkg = "org.jenkins_ci.plugins.run_condition"
evaluation_classes = {
- 'fail': evaluation_classes_pkg + '.BuildStepRunner$Fail',
- 'mark-unstable': evaluation_classes_pkg + '.BuildStepRunner$Unstable',
- 'run-and-mark-unstable': evaluation_classes_pkg +
- '.BuildStepRunner$RunUnstable',
- 'run': evaluation_classes_pkg + '.BuildStepRunner$Run',
- 'dont-run': evaluation_classes_pkg + '.BuildStepRunner$DontRun',
+ "fail": evaluation_classes_pkg + ".BuildStepRunner$Fail",
+ "mark-unstable": evaluation_classes_pkg + ".BuildStepRunner$Unstable",
+ "run-and-mark-unstable": evaluation_classes_pkg
+ + ".BuildStepRunner$RunUnstable",
+ "run": evaluation_classes_pkg + ".BuildStepRunner$Run",
+ "dont-run": evaluation_classes_pkg + ".BuildStepRunner$DontRun",
}
- evaluation_class = evaluation_classes[data.get('on-evaluation-failure',
- 'fail')]
- XML.SubElement(root_tag, "runner").set('class',
- evaluation_class)
+ evaluation_class = evaluation_classes[data.get("on-evaluation-failure", "fail")]
+ XML.SubElement(root_tag, "runner").set("class", evaluation_class)
for step in steps:
build_step(steps_parent, step)
@@ -1813,13 +1816,13 @@ def maven_builder(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/maven-builder001.yaml
:language: yaml
"""
- maven = XML.SubElement(xml_parent, 'org.jfrog.hudson.maven3.Maven3Builder')
+ maven = XML.SubElement(xml_parent, "org.jfrog.hudson.maven3.Maven3Builder")
mapping = [
- ('name', 'mavenName', None),
- ('goals', 'goals', None),
- ('pom', 'rootPom', 'pom.xml'),
- ('maven-opts', 'mavenOpts', ''),
+ ("name", "mavenName", None),
+ ("goals", "goals", None),
+ ("pom", "rootPom", "pom.xml"),
+ ("maven-opts", "mavenOpts", ""),
]
helpers.convert_mapping_to_xml(maven, data, mapping, fail_required=True)
@@ -1859,25 +1862,25 @@ def jira_issue_updater(registry, xml_parent, data):
/../../tests/builders/fixtures/jenkins-jira-issue-updater-full.yaml
:language: yaml
"""
- issue_updater = XML.SubElement(xml_parent, 'info.bluefloyd.jenkins.'
- 'IssueUpdatesBuilder')
- issue_updater.set('plugin', 'jenkins-jira-issue-updater')
+ issue_updater = XML.SubElement(
+ xml_parent, "info.bluefloyd.jenkins." "IssueUpdatesBuilder"
+ )
+ issue_updater.set("plugin", "jenkins-jira-issue-updater")
mapping = [
- ('base-url', 'restAPIUrl', ''),
- ('username', 'userName', None),
- ('password', 'password', None),
- ('jql', 'jql', None),
- ('workflow', 'workflowActionName', ''),
- ('comment', 'comment', ''),
- ('custom-Id', 'customFieldId', ''),
- ('custom-value', 'customFieldValue', ''),
- ('fail-if-error', 'failIfJqlFails', False),
- ('fail-if-no-match', 'failIfNoIssuesReturned', False),
- ('fail-if-no-connection', 'failIfNoJiraConnection', False),
+ ("base-url", "restAPIUrl", ""),
+ ("username", "userName", None),
+ ("password", "password", None),
+ ("jql", "jql", None),
+ ("workflow", "workflowActionName", ""),
+ ("comment", "comment", ""),
+ ("custom-Id", "customFieldId", ""),
+ ("custom-value", "customFieldValue", ""),
+ ("fail-if-error", "failIfJqlFails", False),
+ ("fail-if-no-match", "failIfNoIssuesReturned", False),
+ ("fail-if-no-connection", "failIfNoJiraConnection", False),
]
- helpers.convert_mapping_to_xml(
- issue_updater, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(issue_updater, data, mapping, fail_required=True)
def maven_target(registry, xml_parent, data):
@@ -1917,20 +1920,20 @@ def maven_target(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/maven-target002.yaml
:language: yaml
"""
- maven = XML.SubElement(xml_parent, 'hudson.tasks.Maven')
- XML.SubElement(maven, 'targets').text = data['goals']
- prop_string = '\n'.join(data.get('properties', []))
- XML.SubElement(maven, 'properties').text = prop_string
+ maven = XML.SubElement(xml_parent, "hudson.tasks.Maven")
+ XML.SubElement(maven, "targets").text = data["goals"]
+ prop_string = "\n".join(data.get("properties", []))
+ XML.SubElement(maven, "properties").text = prop_string
mapping = [
- ('maven-version', 'mavenName', None),
- ('pom', 'pom', None),
- ('private-repository', 'usePrivateRepository', False),
+ ("maven-version", "mavenName", None),
+ ("pom", "pom", None),
+ ("private-repository", "usePrivateRepository", False),
]
helpers.convert_mapping_to_xml(maven, data, mapping, fail_required=False)
- if 'java-opts' in data:
- javaoptions = ' '.join(data.get('java-opts', []))
- XML.SubElement(maven, 'jvmOptions').text = javaoptions
+ if "java-opts" in data:
+ javaoptions = " ".join(data.get("java-opts", []))
+ XML.SubElement(maven, "jvmOptions").text = javaoptions
helpers.config_file_provider_settings(maven, data)
@@ -1995,143 +1998,132 @@ def multijob(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/multibuild.yaml
:language: yaml
"""
- builder = XML.SubElement(xml_parent, 'com.tikal.jenkins.plugins.multijob.'
- 'MultiJobBuilder')
- conditions_available = ('SUCCESSFUL', 'UNSTABLE', 'COMPLETED', 'FAILURE',
- 'ALWAYS')
- job_execution_type_available = ('PARALLEL', 'SEQUENTIALLY')
+ builder = XML.SubElement(
+ xml_parent, "com.tikal.jenkins.plugins.multijob." "MultiJobBuilder"
+ )
+ conditions_available = ("SUCCESSFUL", "UNSTABLE", "COMPLETED", "FAILURE", "ALWAYS")
+ job_execution_type_available = ("PARALLEL", "SEQUENTIALLY")
mapping = [
- ('name', 'phaseName', None),
- ('condition', 'continuationCondition',
- 'SUCCESSFUL', conditions_available),
- ('execution-type', 'executionType',
- 'PARALLEL', job_execution_type_available),
+ ("name", "phaseName", None),
+ ("condition", "continuationCondition", "SUCCESSFUL", conditions_available),
+ ("execution-type", "executionType", "PARALLEL", job_execution_type_available),
]
helpers.convert_mapping_to_xml(builder, data, mapping, fail_required=True)
- phaseJobs = XML.SubElement(builder, 'phaseJobs')
+ phaseJobs = XML.SubElement(builder, "phaseJobs")
- kill_status_list = ('FAILURE', 'UNSTABLE', 'NEVER')
+ kill_status_list = ("FAILURE", "UNSTABLE", "NEVER")
- for project in data.get('projects', []):
- phaseJob = XML.SubElement(phaseJobs, 'com.tikal.jenkins.plugins.'
- 'multijob.PhaseJobsConfig')
+ for project in data.get("projects", []):
+ phaseJob = XML.SubElement(
+ phaseJobs, "com.tikal.jenkins.plugins." "multijob.PhaseJobsConfig"
+ )
mapping = [
- ('name', 'jobName', None),
+ ("name", "jobName", None),
# Pass through the current build params
- ('current-parameters', 'currParams', False),
+ ("current-parameters", "currParams", False),
]
- helpers.convert_mapping_to_xml(
- phaseJob, project, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(phaseJob, project, mapping, fail_required=True)
# Pass through other params
- configs = XML.SubElement(phaseJob, 'configs')
+ configs = XML.SubElement(phaseJob, "configs")
- nodeLabelName = project.get('node-label-name')
- nodeLabel = project.get('node-label')
+ nodeLabelName = project.get("node-label-name")
+ nodeLabel = project.get("node-label")
if nodeLabelName and nodeLabel:
node = XML.SubElement(
- configs, 'org.jvnet.jenkins.plugins.nodelabelparameter.'
- 'parameterizedtrigger.NodeLabelBuildParameter')
- mapping = [
- ('', 'name', nodeLabelName),
- ('', 'nodeLabel', nodeLabel),
- ]
- helpers.convert_mapping_to_xml(
- node, project, mapping, fail_required=True)
+ configs,
+ "org.jvnet.jenkins.plugins.nodelabelparameter."
+ "parameterizedtrigger.NodeLabelBuildParameter",
+ )
+ mapping = [("", "name", nodeLabelName), ("", "nodeLabel", nodeLabel)]
+ helpers.convert_mapping_to_xml(node, project, mapping, fail_required=True)
# Node parameter
- if project.get('node-parameters', False):
- XML.SubElement(configs, 'hudson.plugins.parameterizedtrigger.'
- 'NodeParameters')
+ if project.get("node-parameters", False):
+ XML.SubElement(
+ configs, "hudson.plugins.parameterizedtrigger." "NodeParameters"
+ )
# Git Revision
- if project.get('git-revision', False):
- param = XML.SubElement(configs,
- 'hudson.plugins.git.'
- 'GitRevisionBuildParameters')
- mapping = [
- ('', 'combineQueuedCommits', False),
- ]
- helpers.convert_mapping_to_xml(
- param, project, mapping, fail_required=True)
+ if project.get("git-revision", False):
+ param = XML.SubElement(
+ configs, "hudson.plugins.git." "GitRevisionBuildParameters"
+ )
+ mapping = [("", "combineQueuedCommits", False)]
+ helpers.convert_mapping_to_xml(param, project, mapping, fail_required=True)
# Properties File
- properties_file = project.get('property-file', False)
+ properties_file = project.get("property-file", False)
if properties_file:
- param = XML.SubElement(configs,
- 'hudson.plugins.parameterizedtrigger.'
- 'FileBuildParameters')
+ param = XML.SubElement(
+ configs, "hudson.plugins.parameterizedtrigger." "FileBuildParameters"
+ )
mapping = [
- ('', 'propertiesFile', properties_file),
- ('', 'failTriggerOnMissing', True),
+ ("", "propertiesFile", properties_file),
+ ("", "failTriggerOnMissing", True),
]
- helpers.convert_mapping_to_xml(
- param, project, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(param, project, mapping, fail_required=True)
# Predefined Parameters
- predefined_parameters = project.get('predefined-parameters', False)
+ predefined_parameters = project.get("predefined-parameters", False)
if predefined_parameters:
- param = XML.SubElement(configs,
- 'hudson.plugins.parameterizedtrigger.'
- 'PredefinedBuildParameters')
- mapping = [
- ('', 'properties', predefined_parameters),
- ]
- helpers.convert_mapping_to_xml(
- param, project, mapping, fail_required=True)
+ param = XML.SubElement(
+ configs,
+ "hudson.plugins.parameterizedtrigger." "PredefinedBuildParameters",
+ )
+ mapping = [("", "properties", predefined_parameters)]
+ helpers.convert_mapping_to_xml(param, project, mapping, fail_required=True)
mapping = [
- ('abort-all-job', 'abortAllJob', False),
- ('aggregate-results', 'aggregatedTestResults', False),
+ ("abort-all-job", "abortAllJob", False),
+ ("aggregate-results", "aggregatedTestResults", False),
]
- helpers.convert_mapping_to_xml(
- phaseJob, project, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(phaseJob, project, mapping, fail_required=True)
# Retry job
- retry = project.get('retry', False)
+ retry = project.get("retry", False)
if retry:
- max_retry = retry.get('max-retry', 0)
+ max_retry = retry.get("max-retry", 0)
mapping = [
- ('strategy-path', 'parsingRulesPath', None),
- ('', 'maxRetries', int(max_retry)),
- ('', 'enableRetryStrategy', True),
+ ("strategy-path", "parsingRulesPath", None),
+ ("", "maxRetries", int(max_retry)),
+ ("", "enableRetryStrategy", True),
]
- helpers.convert_mapping_to_xml(phaseJob,
- retry, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(phaseJob, retry, mapping, fail_required=True)
else:
- XML.SubElement(phaseJob, 'enableRetryStrategy').text = 'false'
+ XML.SubElement(phaseJob, "enableRetryStrategy").text = "false"
# Restrict matrix jobs to a subset
- if project.get('restrict-matrix-project') is not None:
+ if project.get("restrict-matrix-project") is not None:
subset = XML.SubElement(
- configs, 'hudson.plugins.parameterizedtrigger.'
- 'matrix.MatrixSubsetBuildParameters')
- mapping = [
- ('restrict-matrix-project', 'filter', None),
- ]
- helpers.convert_mapping_to_xml(subset,
- project, mapping, fail_required=True)
+ configs,
+ "hudson.plugins.parameterizedtrigger."
+ "matrix.MatrixSubsetBuildParameters",
+ )
+ mapping = [("restrict-matrix-project", "filter", None)]
+ helpers.convert_mapping_to_xml(subset, project, mapping, fail_required=True)
# Enable Condition
- enable_condition = project.get('enable-condition')
+ enable_condition = project.get("enable-condition")
if enable_condition is not None:
mapping = [
- ('', 'enableCondition', True),
- ('', 'condition', enable_condition),
+ ("", "enableCondition", True),
+ ("", "condition", enable_condition),
]
- helpers.convert_mapping_to_xml(phaseJob,
- project, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ phaseJob, project, mapping, fail_required=True
+ )
# Kill phase on job status
- kill_status = project.get('kill-phase-on')
+ kill_status = project.get("kill-phase-on")
if kill_status is not None:
kill_status = kill_status.upper()
mapping = [
- ('', 'killPhaseOnJobResultCondition',
- kill_status, kill_status_list),
+ ("", "killPhaseOnJobResultCondition", kill_status, kill_status_list)
]
- helpers.convert_mapping_to_xml(phaseJob,
- project, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ phaseJob, project, mapping, fail_required=True
+ )
def config_file_provider(registry, xml_parent, data):
@@ -2167,10 +2159,10 @@ def config_file_provider(registry, xml_parent, data):
../../tests/builders/fixtures/config-file-provider-minimal.yaml
:language: yaml
"""
- cfp = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.configfiles.builder.'
- 'ConfigFileBuildStep')
- cfp.set('plugin', 'config-file-provider')
+ cfp = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.configfiles.builder." "ConfigFileBuildStep"
+ )
+ cfp.set("plugin", "config-file-provider")
helpers.config_file_provider_builder(cfp, data)
@@ -2214,25 +2206,24 @@ def grails(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/grails-minimal.yaml
:language: yaml
"""
- grails = XML.SubElement(xml_parent, 'com.g2one.hudson.grails.'
- 'GrailsBuilder')
- grails.set('plugin', 'grails')
+ grails = XML.SubElement(xml_parent, "com.g2one.hudson.grails." "GrailsBuilder")
+ grails.set("plugin", "grails")
mappings = [
- ('targets', 'targets', None),
- ('name', 'name', '(Default)'),
- ('work-dir', 'grailsWorkDir', ''),
- ('project-dir', 'projectWorkDir', ''),
- ('base-dir', 'projectBaseDir', ''),
- ('server-port', 'serverPort', ''),
- ('properties', 'properties', ''),
- ('force-upgrade', 'forceUpgrade', False),
- ('non-interactive', 'nonInteractive', False),
- ('use-wrapper', 'useWrapper', False),
- ('plain-output', 'plainOutput', False),
- ('stack-trace', 'stackTrace', False),
- ('verbose', 'verbose', False),
- ('refresh-dependencies', 'refreshDependencies', False),
+ ("targets", "targets", None),
+ ("name", "name", "(Default)"),
+ ("work-dir", "grailsWorkDir", ""),
+ ("project-dir", "projectWorkDir", ""),
+ ("base-dir", "projectBaseDir", ""),
+ ("server-port", "serverPort", ""),
+ ("properties", "properties", ""),
+ ("force-upgrade", "forceUpgrade", False),
+ ("non-interactive", "nonInteractive", False),
+ ("use-wrapper", "useWrapper", False),
+ ("plain-output", "plainOutput", False),
+ ("stack-trace", "stackTrace", False),
+ ("verbose", "verbose", False),
+ ("refresh-dependencies", "refreshDependencies", False),
]
helpers.convert_mapping_to_xml(grails, data, mappings, fail_required=True)
@@ -2257,14 +2248,13 @@ def sbt(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/sbt.yaml
:language: yaml
"""
- sbt = XML.SubElement(xml_parent, 'org.jvnet.hudson.plugins.'
- 'SbtPluginBuilder')
+ sbt = XML.SubElement(xml_parent, "org.jvnet.hudson.plugins." "SbtPluginBuilder")
mappings = [
- ('name', 'name', ''),
- ('jvm-flags', 'jvmFlags', ''),
- ('sbt-flags', 'sbtFlags', '-Dsbt.log.noformat=true'),
- ('actions', 'actions', ''),
- ('subdir-path', 'subdirPath', ''),
+ ("name", "name", ""),
+ ("jvm-flags", "jvmFlags", ""),
+ ("sbt-flags", "sbtFlags", "-Dsbt.log.noformat=true"),
+ ("actions", "actions", ""),
+ ("subdir-path", "subdirPath", ""),
]
helpers.convert_mapping_to_xml(sbt, data, mappings, fail_required=True)
@@ -2286,8 +2276,9 @@ def critical_block_start(registry, xml_parent, data):
:language: yaml
"""
cbs = XML.SubElement(
- xml_parent, 'org.jvnet.hudson.plugins.exclusion.CriticalBlockStart')
- cbs.set('plugin', 'Exclusion')
+ xml_parent, "org.jvnet.hudson.plugins.exclusion.CriticalBlockStart"
+ )
+ cbs.set("plugin", "Exclusion")
def critical_block_end(registry, xml_parent, data):
@@ -2307,8 +2298,9 @@ def critical_block_end(registry, xml_parent, data):
:language: yaml
"""
cbs = XML.SubElement(
- xml_parent, 'org.jvnet.hudson.plugins.exclusion.CriticalBlockEnd')
- cbs.set('plugin', 'Exclusion')
+ xml_parent, "org.jvnet.hudson.plugins.exclusion.CriticalBlockEnd"
+ )
+ cbs.set("plugin", "Exclusion")
def publish_over_ssh(registry, xml_parent, data):
@@ -2407,139 +2399,139 @@ def saltstack(parser, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/saltstack-full.yaml
:language: yaml
"""
- saltstack = XML.SubElement(xml_parent, 'com.waytta.SaltAPIBuilder')
-
- supported_auth_types = ['pam', 'ldap']
- supported_target_types = ['glob', 'pcre', 'list', 'grain', 'pillar',
- 'nodegroup', 'range', 'compound']
- supported_client_interfaces = ['local', 'local-batch', 'runner']
+ saltstack = XML.SubElement(xml_parent, "com.waytta.SaltAPIBuilder")
+
+ supported_auth_types = ["pam", "ldap"]
+ supported_target_types = [
+ "glob",
+ "pcre",
+ "list",
+ "grain",
+ "pillar",
+ "nodegroup",
+ "range",
+ "compound",
+ ]
+ supported_client_interfaces = ["local", "local-batch", "runner"]
mapping = [
- ('servername', 'servername', None),
- ('credentials', 'credentialsId', None),
- ('authtype', 'authtype', 'pam', supported_auth_types),
- ('target', 'target', ''),
- ('targettype', 'targettype', 'glob', supported_target_types),
- ('clientinterface', 'clientInterface', 'local',
- supported_client_interfaces),
- ('function', 'function', ''),
- ('arguments', 'arguments', ''),
- ('kwarguments', 'kwarguments', ''),
- ('setpillardata', 'usePillar', False),
- ('pillarkey', 'pillarkey', ''),
- ('pillarvalue', 'pillarvalue', ''),
- ('wait', 'blockbuild', False),
- ('polltime', 'jobPollTime', ''),
- ('batchsize', 'batchSize', '100%'),
- ('mods', 'mods', ''),
- ('saveoutput', 'saveEnvVar', False),
+ ("servername", "servername", None),
+ ("credentials", "credentialsId", None),
+ ("authtype", "authtype", "pam", supported_auth_types),
+ ("target", "target", ""),
+ ("targettype", "targettype", "glob", supported_target_types),
+ ("clientinterface", "clientInterface", "local", supported_client_interfaces),
+ ("function", "function", ""),
+ ("arguments", "arguments", ""),
+ ("kwarguments", "kwarguments", ""),
+ ("setpillardata", "usePillar", False),
+ ("pillarkey", "pillarkey", ""),
+ ("pillarvalue", "pillarvalue", ""),
+ ("wait", "blockbuild", False),
+ ("polltime", "jobPollTime", ""),
+ ("batchsize", "batchSize", "100%"),
+ ("mods", "mods", ""),
+ ("saveoutput", "saveEnvVar", False),
]
- helpers.convert_mapping_to_xml(saltstack, data, mapping,
- fail_required=True)
+ helpers.convert_mapping_to_xml(saltstack, data, mapping, fail_required=True)
- clientInterface = data.get('clientinterface', 'local')
- blockbuild = str(data.get('wait', False)).lower()
- jobPollTime = str(data.get('polltime', ''))
- batchSize = data.get('batchsize', '100%')
- mods = data.get('mods', '')
- usePillar = str(data.get('setpillardata', False)).lower()
+ clientInterface = data.get("clientinterface", "local")
+ blockbuild = str(data.get("wait", False)).lower()
+ jobPollTime = str(data.get("polltime", ""))
+ batchSize = data.get("batchsize", "100%")
+ mods = data.get("mods", "")
+ usePillar = str(data.get("setpillardata", False)).lower()
# Build the clientInterfaces structure, based on the
# clientinterface setting
- clientInterfaces = XML.SubElement(saltstack, 'clientInterfaces')
- XML.SubElement(clientInterfaces, 'nullObject').text = 'false'
+ clientInterfaces = XML.SubElement(saltstack, "clientInterfaces")
+ XML.SubElement(clientInterfaces, "nullObject").text = "false"
ci_attrib = {
- 'class': 'org.apache.commons.collections.map.ListOrderedMap',
- 'serialization': 'custom'
+ "class": "org.apache.commons.collections.map.ListOrderedMap",
+ "serialization": "custom",
}
- properties = XML.SubElement(clientInterfaces, 'properties', ci_attrib)
+ properties = XML.SubElement(clientInterfaces, "properties", ci_attrib)
- lomElement = 'org.apache.commons.collections.map.ListOrderedMap'
+ lomElement = "org.apache.commons.collections.map.ListOrderedMap"
listOrderedMap = XML.SubElement(properties, lomElement)
- default = XML.SubElement(listOrderedMap, 'default')
- ordered_map = XML.SubElement(listOrderedMap, 'map')
+ default = XML.SubElement(listOrderedMap, "default")
+ ordered_map = XML.SubElement(listOrderedMap, "map")
- insertOrder = XML.SubElement(default, 'insertOrder')
+ insertOrder = XML.SubElement(default, "insertOrder")
ci_config = []
- if clientInterface == 'local':
+ if clientInterface == "local":
ci_config = [
- ('blockbuild', blockbuild),
- ('jobPollTime', jobPollTime),
- ('clientInterface', clientInterface)
+ ("blockbuild", blockbuild),
+ ("jobPollTime", jobPollTime),
+ ("clientInterface", clientInterface),
]
- elif clientInterface == 'local-batch':
- ci_config = [
- ('batchSize', batchSize),
- ('clientInterface', clientInterface)
- ]
+ elif clientInterface == "local-batch":
+ ci_config = [("batchSize", batchSize), ("clientInterface", clientInterface)]
- elif clientInterface == 'runner':
- ci_config = [
- ('mods', mods),
- ('clientInterface', clientInterface)
- ]
+ elif clientInterface == "runner":
+ ci_config = [("mods", mods), ("clientInterface", clientInterface)]
- if usePillar == 'true':
- ci_config.append(('usePillar', usePillar))
+ if usePillar == "true":
+ ci_config.append(("usePillar", usePillar))
pillar_cfg = [
- ('pillarkey', data.get('pillarkey')),
- ('pillarvalue', data.get('pillarvalue'))
+ ("pillarkey", data.get("pillarkey")),
+ ("pillarvalue", data.get("pillarvalue")),
]
for emt, value in ci_config:
- XML.SubElement(insertOrder, 'string').text = emt
- entry = XML.SubElement(ordered_map, 'entry')
- XML.SubElement(entry, 'string').text = emt
+ XML.SubElement(insertOrder, "string").text = emt
+ entry = XML.SubElement(ordered_map, "entry")
+ XML.SubElement(entry, "string").text = emt
# Special handling when usePillar == true, requires additional
# structure in the builder XML
- if emt != 'usePillar':
- XML.SubElement(entry, 'string').text = value
+ if emt != "usePillar":
+ XML.SubElement(entry, "string").text = value
else:
- jsonobj = XML.SubElement(entry, 'net.sf.json.JSONObject')
- XML.SubElement(jsonobj, 'nullObject').text = 'false'
+ jsonobj = XML.SubElement(entry, "net.sf.json.JSONObject")
+ XML.SubElement(jsonobj, "nullObject").text = "false"
- pillarProps = XML.SubElement(jsonobj, 'properties', ci_attrib)
- XML.SubElement(pillarProps, 'unserializable-parents')
+ pillarProps = XML.SubElement(jsonobj, "properties", ci_attrib)
+ XML.SubElement(pillarProps, "unserializable-parents")
pillarLom = XML.SubElement(pillarProps, lomElement)
- pillarDefault = XML.SubElement(pillarLom, 'default')
- pillarMap = XML.SubElement(pillarLom, 'map')
- pillarInsertOrder = XML.SubElement(pillarDefault, 'insertOrder')
+ pillarDefault = XML.SubElement(pillarLom, "default")
+ pillarMap = XML.SubElement(pillarLom, "map")
+ pillarInsertOrder = XML.SubElement(pillarDefault, "insertOrder")
for pemt, value in pillar_cfg:
- XML.SubElement(pillarInsertOrder, 'string').text = pemt
- pillarEntry = XML.SubElement(pillarMap, 'entry')
- XML.SubElement(pillarEntry, 'string').text = pemt
- XML.SubElement(pillarEntry, 'string').text = value
+ XML.SubElement(pillarInsertOrder, "string").text = pemt
+ pillarEntry = XML.SubElement(pillarMap, "entry")
+ XML.SubElement(pillarEntry, "string").text = pemt
+ XML.SubElement(pillarEntry, "string").text = value
class Builders(jenkins_jobs.modules.base.Base):
sequence = 60
- component_type = 'builder'
- component_list_type = 'builders'
+ component_type = "builder"
+ component_list_type = "builders"
def gen_xml(self, xml_parent, data):
- for alias in ['prebuilders', 'builders', 'postbuilders']:
+ for alias in ["prebuilders", "builders", "postbuilders"]:
if alias in data:
builders = XML.SubElement(xml_parent, alias)
for builder in data[alias]:
- self.registry.dispatch('builder', builders, builder)
+ self.registry.dispatch("builder", builders, builder)
# Make sure freestyle projects always have a <builders> entry
# or Jenkins v1.472 (at least) will NPE.
- project_type = data.get('project-type', 'freestyle')
- if project_type in ('freestyle', 'matrix') and 'builders' not in data:
- XML.SubElement(xml_parent, 'builders')
+ project_type = data.get("project-type", "freestyle")
+ if project_type in ("freestyle", "matrix") and "builders" not in data:
+ XML.SubElement(xml_parent, "builders")
def shining_panda(registry, xml_parent, data):
@@ -2609,52 +2601,46 @@ def shining_panda(registry, xml_parent, data):
:language: yaml
"""
- pluginelementpart = 'jenkins.plugins.shiningpanda.builders.'
- buildenvdict = {'custom': 'CustomPythonBuilder',
- 'virtualenv': 'VirtualenvBuilder',
- 'python': 'PythonBuilder'}
- envs = (buildenvdict.keys())
+ pluginelementpart = "jenkins.plugins.shiningpanda.builders."
+ buildenvdict = {
+ "custom": "CustomPythonBuilder",
+ "virtualenv": "VirtualenvBuilder",
+ "python": "PythonBuilder",
+ }
+ envs = buildenvdict.keys()
try:
- buildenv = data['build-environment']
+ buildenv = data["build-environment"]
except KeyError:
- raise MissingAttributeError('build-environment')
+ raise MissingAttributeError("build-environment")
if buildenv not in envs:
- raise InvalidAttributeError('build-environment', buildenv, envs)
+ raise InvalidAttributeError("build-environment", buildenv, envs)
- t = XML.SubElement(xml_parent, '%s%s' %
- (pluginelementpart, buildenvdict[buildenv]))
+ t = XML.SubElement(xml_parent, "%s%s" % (pluginelementpart, buildenvdict[buildenv]))
- if buildenv in ('python', 'virtualenv'):
- python_mapping = [
- ('python-version', 'pythonName', 'System-CPython-2.7'),
- ]
- helpers.convert_mapping_to_xml(
- t, data, python_mapping, fail_required=True)
+ if buildenv in ("python", "virtualenv"):
+ python_mapping = [("python-version", "pythonName", "System-CPython-2.7")]
+ helpers.convert_mapping_to_xml(t, data, python_mapping, fail_required=True)
- if buildenv in 'custom':
- custom_mapping = [
- ('home', 'home', None),
- ]
- helpers.convert_mapping_to_xml(
- t, data, custom_mapping, fail_required=True)
- if buildenv in 'virtualenv':
+ if buildenv in "custom":
+ custom_mapping = [("home", "home", None)]
+ helpers.convert_mapping_to_xml(t, data, custom_mapping, fail_required=True)
+ if buildenv in "virtualenv":
virtualenv_mapping = [
- ('name', 'home', ''),
- ('clear', 'clear', False),
- ('use-distribute', 'useDistribute', False),
- ('system-site-packages', 'systemSitePackages', False),
+ ("name", "home", ""),
+ ("clear", "clear", False),
+ ("use-distribute", "useDistribute", False),
+ ("system-site-packages", "systemSitePackages", False),
]
- helpers.convert_mapping_to_xml(
- t, data, virtualenv_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(t, data, virtualenv_mapping, fail_required=True)
# Common arguments
- naturelist = ['shell', 'xshell', 'python']
+ naturelist = ["shell", "xshell", "python"]
mapping = [
- ('nature', 'nature', 'shell', naturelist),
- ('command', 'command', ""),
- ('ignore-exit-code', 'ignoreExitCode', False),
+ ("nature", "nature", "shell", naturelist),
+ ("command", "command", ""),
+ ("ignore-exit-code", "ignoreExitCode", False),
]
helpers.convert_mapping_to_xml(t, data, mapping, fail_required=True)
@@ -2675,16 +2661,13 @@ def tox(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/tox001.yaml
:language: yaml
"""
- pluginelement = 'jenkins.plugins.shiningpanda.builders.ToxBuilder'
+ pluginelement = "jenkins.plugins.shiningpanda.builders.ToxBuilder"
t = XML.SubElement(xml_parent, pluginelement)
- mappings = [
- ('ini', 'toxIni', 'tox.ini'),
- ('recreate', 'recreate', False),
- ]
+ mappings = [("ini", "toxIni", "tox.ini"), ("recreate", "recreate", False)]
helpers.convert_mapping_to_xml(t, data, mappings, fail_required=True)
- pattern = data.get('toxenv-pattern')
+ pattern = data.get("toxenv-pattern")
if pattern:
- XML.SubElement(t, 'toxenvPattern').text = pattern
+ XML.SubElement(t, "toxenvPattern").text = pattern
def managed_script(registry, xml_parent, data):
@@ -2710,24 +2693,21 @@ def managed_script(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/managed-winbatch.yaml
:language: yaml
"""
- step_type = data.get('type', 'script').lower()
- if step_type == 'script':
- step = 'ScriptBuildStep'
- script_tag = 'buildStepId'
- elif step_type == 'batch':
- step = 'WinBatchBuildStep'
- script_tag = 'command'
+ step_type = data.get("type", "script").lower()
+ if step_type == "script":
+ step = "ScriptBuildStep"
+ script_tag = "buildStepId"
+ elif step_type == "batch":
+ step = "WinBatchBuildStep"
+ script_tag = "command"
else:
- raise InvalidAttributeError('type', step_type, ['script', 'batch'])
- ms = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.managedscripts.' + step)
- mapping = [
- ('script-id', script_tag, None),
- ]
+ raise InvalidAttributeError("type", step_type, ["script", "batch"])
+ ms = XML.SubElement(xml_parent, "org.jenkinsci.plugins.managedscripts." + step)
+ mapping = [("script-id", script_tag, None)]
helpers.convert_mapping_to_xml(ms, data, mapping, fail_required=True)
- args = XML.SubElement(ms, 'buildStepArgs')
- for arg in data.get('args', []):
- XML.SubElement(args, 'string').text = arg
+ args = XML.SubElement(ms, "buildStepArgs")
+ for arg in data.get("args", []):
+ XML.SubElement(args, "string").text = arg
def cmake(registry, xml_parent, data):
@@ -2836,59 +2816,55 @@ def cmake(registry, xml_parent, data):
:language: yaml
"""
- BUILD_TYPES = ['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel']
- cmake = XML.SubElement(xml_parent, 'hudson.plugins.cmake.CmakeBuilder')
+ BUILD_TYPES = ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"]
+ cmake = XML.SubElement(xml_parent, "hudson.plugins.cmake.CmakeBuilder")
mapping = [
- ('source-dir', 'sourceDir', None), # Required parameter
- ('generator', 'generator', "Unix Makefiles"),
- ('clean-build-dir', 'cleanBuild', False),
+ ("source-dir", "sourceDir", None), # Required parameter
+ ("generator", "generator", "Unix Makefiles"),
+ ("clean-build-dir", "cleanBuild", False),
]
- helpers.convert_mapping_to_xml(
- cmake, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(cmake, data, mapping, fail_required=True)
info = registry.get_plugin_info("CMake plugin")
# Note: Assume latest version of plugin is preferred config format
- version = pkg_resources.parse_version(
- info.get("version", str(sys.maxsize)))
+ version = pkg_resources.parse_version(info.get("version", str(sys.maxsize)))
if version >= pkg_resources.parse_version("2.0"):
mapping_20 = [
- ('preload-script', 'preloadScript', None), # Optional parameter
- ('working-dir', 'workingDir', ''),
- ('build-type', 'buildType', 'Debug'),
- ('installation-name', 'installationName', 'InSearchPath'),
- ('other-arguments', 'toolArgs', ''),
+ ("preload-script", "preloadScript", None), # Optional parameter
+ ("working-dir", "workingDir", ""),
+ ("build-type", "buildType", "Debug"),
+ ("installation-name", "installationName", "InSearchPath"),
+ ("other-arguments", "toolArgs", ""),
]
- helpers.convert_mapping_to_xml(
- cmake, data, mapping_20, fail_required=False)
+ helpers.convert_mapping_to_xml(cmake, data, mapping_20, fail_required=False)
- tool_steps = XML.SubElement(cmake, 'toolSteps')
+ tool_steps = XML.SubElement(cmake, "toolSteps")
- for step_data in data.get('build-tool-invocations', []):
- step = XML.SubElement(
- tool_steps, 'hudson.plugins.cmake.BuildToolStep')
+ for step_data in data.get("build-tool-invocations", []):
+ step = XML.SubElement(tool_steps, "hudson.plugins.cmake.BuildToolStep")
step_mapping = [
- ('use-cmake', 'withCmake', False),
- ('arguments', 'args', ''),
- ('environment-variables', 'vars', ''),
+ ("use-cmake", "withCmake", False),
+ ("arguments", "args", ""),
+ ("environment-variables", "vars", ""),
]
helpers.convert_mapping_to_xml(
- step, step_data, step_mapping, fail_required=True)
+ step, step_data, step_mapping, fail_required=True
+ )
else:
mapping_10 = [
- ('preload-script', 'preloadScript', ''),
- ('build-dir', 'buildDir', ''),
- ('install-dir', 'installDir', ''),
- ('make-command', 'makeCommand', 'make'),
- ('install-command', 'installCommand', 'make install'),
- ('other-arguments', 'cmakeArgs', ''),
- ('custom-cmake-path', 'projectCmakePath', ''),
- ('clean-install-dir', 'cleanInstallDir', False),
+ ("preload-script", "preloadScript", ""),
+ ("build-dir", "buildDir", ""),
+ ("install-dir", "installDir", ""),
+ ("make-command", "makeCommand", "make"),
+ ("install-command", "installCommand", "make install"),
+ ("other-arguments", "cmakeArgs", ""),
+ ("custom-cmake-path", "projectCmakePath", ""),
+ ("clean-install-dir", "cleanInstallDir", False),
]
- helpers.convert_mapping_to_xml(
- cmake, data, mapping_10, fail_required=True)
+ helpers.convert_mapping_to_xml(cmake, data, mapping_10, fail_required=True)
# The options buildType and otherBuildType work together on the CMake
# plugin:
@@ -2900,20 +2876,20 @@ def cmake(registry, xml_parent, data):
# It is strange and confusing that the plugin author chose to do
# something like that instead of simply passing a string "buildType"
# option, so this was done to simplify it for the JJB user.
- build_type = XML.SubElement(cmake, 'buildType')
- build_type.text = data.get('build-type', BUILD_TYPES[0])
- other_build_type = XML.SubElement(cmake, 'otherBuildType')
+ build_type = XML.SubElement(cmake, "buildType")
+ build_type.text = data.get("build-type", BUILD_TYPES[0])
+ other_build_type = XML.SubElement(cmake, "otherBuildType")
if build_type.text not in BUILD_TYPES:
other_build_type.text = build_type.text
build_type.text = BUILD_TYPES[0]
else:
- other_build_type.text = ''
+ other_build_type.text = ""
# The plugin generates this tag, but there doesn't seem to be anything
# that can be configurable by it. Let's keep it to maintain
# compatibility:
- XML.SubElement(cmake, 'builderImpl')
+ XML.SubElement(cmake, "builderImpl")
def dsl(registry, xml_parent, data):
@@ -2950,61 +2926,61 @@ def dsl(registry, xml_parent, data):
"""
- dsl = XML.SubElement(xml_parent,
- 'javaposse.jobdsl.plugin.ExecuteDslScripts')
+ dsl = XML.SubElement(xml_parent, "javaposse.jobdsl.plugin.ExecuteDslScripts")
- if 'target' in data:
- if 'targets' not in data:
- logger.warning("Converting from old format of 'target' to new "
- "name 'targets', please update your job "
- "definitions.")
- data['targets'] = data['target']
+ if "target" in data:
+ if "targets" not in data:
+ logger.warning(
+ "Converting from old format of 'target' to new "
+ "name 'targets', please update your job "
+ "definitions."
+ )
+ data["targets"] = data["target"]
else:
- logger.warning("Ignoring old argument 'target' in favour of new "
- "format argument 'targets', please remove old "
- "format.")
-
- if data.get('script-text'):
- XML.SubElement(dsl, 'scriptText').text = data.get('script-text')
- XML.SubElement(dsl, 'usingScriptText').text = 'true'
- elif data.get('targets'):
- XML.SubElement(dsl, 'targets').text = data.get('targets')
- XML.SubElement(dsl, 'usingScriptText').text = 'false'
+ logger.warning(
+ "Ignoring old argument 'target' in favour of new "
+ "format argument 'targets', please remove old "
+ "format."
+ )
+
+ if data.get("script-text"):
+ XML.SubElement(dsl, "scriptText").text = data.get("script-text")
+ XML.SubElement(dsl, "usingScriptText").text = "true"
+ elif data.get("targets"):
+ XML.SubElement(dsl, "targets").text = data.get("targets")
+ XML.SubElement(dsl, "usingScriptText").text = "false"
else:
- raise MissingAttributeError(['script-text', 'target'])
+ raise MissingAttributeError(["script-text", "target"])
- XML.SubElement(dsl, 'ignoreExisting').text = str(data.get(
- 'ignore-existing', False)).lower()
+ XML.SubElement(dsl, "ignoreExisting").text = str(
+ data.get("ignore-existing", False)
+ ).lower()
- supportedJobActions = ['IGNORE', 'DISABLE', 'DELETE']
- removedJobAction = data.get('removed-job-action',
- supportedJobActions[0])
+ supportedJobActions = ["IGNORE", "DISABLE", "DELETE"]
+ removedJobAction = data.get("removed-job-action", supportedJobActions[0])
if removedJobAction not in supportedJobActions:
- raise InvalidAttributeError('removed-job-action',
- removedJobAction,
- supportedJobActions)
- XML.SubElement(dsl, 'removedJobAction').text = removedJobAction
-
- supportedViewActions = ['IGNORE', 'DELETE']
- removedViewAction = data.get('removed-view-action',
- supportedViewActions[0])
+ raise InvalidAttributeError(
+ "removed-job-action", removedJobAction, supportedJobActions
+ )
+ XML.SubElement(dsl, "removedJobAction").text = removedJobAction
+
+ supportedViewActions = ["IGNORE", "DELETE"]
+ removedViewAction = data.get("removed-view-action", supportedViewActions[0])
if removedViewAction not in supportedViewActions:
- raise InvalidAttributeError('removed-view-action',
- removedViewAction,
- supportedViewActions)
- XML.SubElement(dsl, 'removedViewAction').text = removedViewAction
-
- supportedLookupActions = ['JENKINS_ROOT', 'SEED_JOB']
- lookupStrategy = data.get('lookup-strategy',
- supportedLookupActions[0])
+ raise InvalidAttributeError(
+ "removed-view-action", removedViewAction, supportedViewActions
+ )
+ XML.SubElement(dsl, "removedViewAction").text = removedViewAction
+
+ supportedLookupActions = ["JENKINS_ROOT", "SEED_JOB"]
+ lookupStrategy = data.get("lookup-strategy", supportedLookupActions[0])
if lookupStrategy not in supportedLookupActions:
- raise InvalidAttributeError('lookup-strategy',
- lookupStrategy,
- supportedLookupActions)
- XML.SubElement(dsl, 'lookupStrategy').text = lookupStrategy
+ raise InvalidAttributeError(
+ "lookup-strategy", lookupStrategy, supportedLookupActions
+ )
+ XML.SubElement(dsl, "lookupStrategy").text = lookupStrategy
- XML.SubElement(dsl, 'additionalClasspath').text = data.get(
- 'additional-classpath')
+ XML.SubElement(dsl, "additionalClasspath").text = data.get("additional-classpath")
def github_notifier(registry, xml_parent, data):
@@ -3017,8 +2993,7 @@ def github_notifier(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/github-notifier.yaml
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'com.cloudbees.jenkins.GitHubSetCommitStatusBuilder')
+ XML.SubElement(xml_parent, "com.cloudbees.jenkins.GitHubSetCommitStatusBuilder")
def scan_build(registry, xml_parent, data):
@@ -3063,23 +3038,21 @@ def scan_build(registry, xml_parent, data):
:language: yaml
"""
p = XML.SubElement(
- xml_parent,
- 'jenkins.plugins.clangscanbuild.ClangScanBuildBuilder')
- p.set('plugin', 'clang-scanbuild')
+ xml_parent, "jenkins.plugins.clangscanbuild.ClangScanBuildBuilder"
+ )
+ p.set("plugin", "clang-scanbuild")
mappings = [
- ('target', 'target', None),
- ('target-sdk', 'targetSdk', 'iphonesimulator'),
- ('config', 'config', 'Debug'),
- ('clang-install-name', 'clangInstallationName', ''),
- ('xcode-sub-path', 'xcodeProjectSubPath', 'myProj/subfolder'),
- ('workspace', 'workspace', ''),
- ('scheme', 'scheme', ''),
- ('scan-build-args', 'scanbuildargs', '--use-analyzer Xcode'),
- ('xcode-build-args',
- 'xcodebuildargs',
- '-derivedDataPath $WORKSPACE/build'),
- ('report-folder', 'outputFolderName', 'clangScanBuildReports'),
+ ("target", "target", None),
+ ("target-sdk", "targetSdk", "iphonesimulator"),
+ ("config", "config", "Debug"),
+ ("clang-install-name", "clangInstallationName", ""),
+ ("xcode-sub-path", "xcodeProjectSubPath", "myProj/subfolder"),
+ ("workspace", "workspace", ""),
+ ("scheme", "scheme", ""),
+ ("scan-build-args", "scanbuildargs", "--use-analyzer Xcode"),
+ ("xcode-build-args", "xcodebuildargs", "-derivedDataPath $WORKSPACE/build"),
+ ("report-folder", "outputFolderName", "clangScanBuildReports"),
]
helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
@@ -3098,13 +3071,9 @@ def ssh_builder(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/ssh-builder.yaml
:language: yaml
"""
- builder = XML.SubElement(
- xml_parent, 'org.jvnet.hudson.plugins.SSHBuilder')
+ builder = XML.SubElement(xml_parent, "org.jvnet.hudson.plugins.SSHBuilder")
- mapping = [
- ('ssh-user-ip', 'siteName', None),
- ('command', 'command', None),
- ]
+ mapping = [("ssh-user-ip", "siteName", None), ("command", "command", None)]
helpers.convert_mapping_to_xml(builder, data, mapping, fail_required=True)
@@ -3132,21 +3101,20 @@ def sonar(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/sonar.yaml
:language: yaml
"""
- sonar = XML.SubElement(xml_parent,
- 'hudson.plugins.sonar.SonarRunnerBuilder')
- sonar.set('plugin', 'sonar')
- XML.SubElement(sonar, 'installationName').text = data['sonar-name']
+ sonar = XML.SubElement(xml_parent, "hudson.plugins.sonar.SonarRunnerBuilder")
+ sonar.set("plugin", "sonar")
+ XML.SubElement(sonar, "installationName").text = data["sonar-name"]
mappings = [
- ('scanner-name', 'sonarScannerName', ''),
- ('task', 'task', ''),
- ('project', 'project', ''),
- ('properties', 'properties', ''),
- ('java-opts', 'javaOpts', ''),
- ('additional-arguments', 'additionalArguments', ''),
+ ("scanner-name", "sonarScannerName", ""),
+ ("task", "task", ""),
+ ("project", "project", ""),
+ ("properties", "properties", ""),
+ ("java-opts", "javaOpts", ""),
+ ("additional-arguments", "additionalArguments", ""),
]
helpers.convert_mapping_to_xml(sonar, data, mappings, fail_required=True)
- if 'jdk' in data:
- XML.SubElement(sonar, 'jdk').text = data['jdk']
+ if "jdk" in data:
+ XML.SubElement(sonar, "jdk").text = data["jdk"]
def xcode(registry, xml_parent, data):
@@ -3226,85 +3194,84 @@ def xcode(registry, xml_parent, data):
:language: yaml
"""
- if data.get('developer-profile'):
- profile = XML.SubElement(xml_parent, 'au.com.rayh.'
- 'DeveloperProfileLoader')
- mapping = [
- ('developer-profile', 'id', None),
- ]
- helpers.convert_mapping_to_xml(
- profile, data, mapping, fail_required=False)
+ if data.get("developer-profile"):
+ profile = XML.SubElement(xml_parent, "au.com.rayh." "DeveloperProfileLoader")
+ mapping = [("developer-profile", "id", None)]
+ helpers.convert_mapping_to_xml(profile, data, mapping, fail_required=False)
- xcode = XML.SubElement(xml_parent, 'au.com.rayh.XCodeBuilder')
+ xcode = XML.SubElement(xml_parent, "au.com.rayh.XCodeBuilder")
mappings = [
- ('clean-build', 'cleanBeforeBuild', False),
- ('clean-test-reports', 'cleanTestReports', False),
- ('archive', 'generateArchive', False),
- ('configuration', 'configuration', 'Release'),
- ('configuration-directory', 'configurationBuildDir', ''),
- ('target', 'target', ''),
- ('sdk', 'sdk', ''),
- ('symroot', 'symRoot', ''),
- ('project-path', 'xcodeProjectPath', ''),
- ('project-file', 'xcodeProjectFile', ''),
- ('build-arguments', 'xcodebuildArguments', ''),
- ('schema', 'xcodeSchema', ''),
- ('workspace', 'xcodeWorkspaceFile', ''),
- ('profile', 'embeddedProfileFile', ''),
- ('codesign-id', 'codeSigningIdentity', ''),
- ('allow-failing', 'allowFailingBuildResults', False),
+ ("clean-build", "cleanBeforeBuild", False),
+ ("clean-test-reports", "cleanTestReports", False),
+ ("archive", "generateArchive", False),
+ ("configuration", "configuration", "Release"),
+ ("configuration-directory", "configurationBuildDir", ""),
+ ("target", "target", ""),
+ ("sdk", "sdk", ""),
+ ("symroot", "symRoot", ""),
+ ("project-path", "xcodeProjectPath", ""),
+ ("project-file", "xcodeProjectFile", ""),
+ ("build-arguments", "xcodebuildArguments", ""),
+ ("schema", "xcodeSchema", ""),
+ ("workspace", "xcodeWorkspaceFile", ""),
+ ("profile", "embeddedProfileFile", ""),
+ ("codesign-id", "codeSigningIdentity", ""),
+ ("allow-failing", "allowFailingBuildResults", False),
]
helpers.convert_mapping_to_xml(xcode, data, mappings, fail_required=True)
- version = XML.SubElement(xcode, 'provideApplicationVersion')
- version_technical = XML.SubElement(xcode,
- 'cfBundleVersionValue')
- version_marketing = XML.SubElement(xcode,
- 'cfBundleShortVersionStringValue')
+ version = XML.SubElement(xcode, "provideApplicationVersion")
+ version_technical = XML.SubElement(xcode, "cfBundleVersionValue")
+ version_marketing = XML.SubElement(xcode, "cfBundleShortVersionStringValue")
- if data.get('version-technical') or data.get('version-marketing'):
- version.text = 'true'
- version_technical.text = data.get('version-technical', '')
- version_marketing.text = data.get('version-marketing', '')
+ if data.get("version-technical") or data.get("version-marketing"):
+ version.text = "true"
+ version_technical.text = data.get("version-technical", "")
+ version_marketing.text = data.get("version-marketing", "")
else:
- version.text = 'false'
+ version.text = "false"
- XML.SubElement(xcode, 'buildIpa').text = str(
- bool(data.get('ipa-version')) or False).lower()
+ XML.SubElement(xcode, "buildIpa").text = str(
+ bool(data.get("ipa-version")) or False
+ ).lower()
- valid_ipa_export_methods = ['', 'ad-hoc', 'app-store', 'development']
+ valid_ipa_export_methods = ["", "ad-hoc", "app-store", "development"]
mapping = [
- ('ipa-export-method', 'ipaExportMethod', '',
- valid_ipa_export_methods),
- ('ipa-version', 'ipaName', ''),
- ('ipa-output', 'ipaOutputDirectory', ''),
- ('development-team-id', 'developmentTeamID', ''),
- ('keychain-name', 'keychainName', ''),
- ('keychain-path', 'keychainPath', ''),
- ('keychain-password', 'keychainPwd', ''),
- ('keychain-unlock', 'unlockKeychain', False),
- ('compile-bitcode', 'compileBitcode', True),
- ('upload-bitcode', 'uploadBitcode', True),
- ('upload-symbols', 'uploadSymbols', True)
+ ("ipa-export-method", "ipaExportMethod", "", valid_ipa_export_methods),
+ ("ipa-version", "ipaName", ""),
+ ("ipa-output", "ipaOutputDirectory", ""),
+ ("development-team-id", "developmentTeamID", ""),
+ ("keychain-name", "keychainName", ""),
+ ("keychain-path", "keychainPath", ""),
+ ("keychain-password", "keychainPwd", ""),
+ ("keychain-unlock", "unlockKeychain", False),
+ ("compile-bitcode", "compileBitcode", True),
+ ("upload-bitcode", "uploadBitcode", True),
+ ("upload-symbols", "uploadSymbols", True),
]
helpers.convert_mapping_to_xml(xcode, data, mapping, fail_required=True)
- has_provisioning_profiles = bool(data.get('provisioning-profiles'))
- XML.SubElement(xcode, 'manualSigning').text = str(
- has_provisioning_profiles or False).lower()
+ has_provisioning_profiles = bool(data.get("provisioning-profiles"))
+ XML.SubElement(xcode, "manualSigning").text = str(
+ has_provisioning_profiles or False
+ ).lower()
if has_provisioning_profiles:
- provisioning_profiles_xml = XML.SubElement(
- xcode, 'provisioningProfiles')
+ provisioning_profiles_xml = XML.SubElement(xcode, "provisioningProfiles")
mapping = [
- ('bundle-id', 'provisioningProfileAppId', ''),
- ('provisioning-profile-uuid', 'provisioningProfileUUID', ''),
+ ("bundle-id", "provisioningProfileAppId", ""),
+ ("provisioning-profile-uuid", "provisioningProfileUUID", ""),
]
- for provisioning_profile in data.get('provisioning-profiles'):
+ for provisioning_profile in data.get("provisioning-profiles"):
provisioning_profile_xml = XML.SubElement(
- provisioning_profiles_xml, 'au.com.rayh.ProvisioningProfile')
- helpers.convert_mapping_to_xml(provisioning_profile_xml,
- provisioning_profile, mapping, fail_required=True)
+ provisioning_profiles_xml, "au.com.rayh.ProvisioningProfile"
+ )
+ helpers.convert_mapping_to_xml(
+ provisioning_profile_xml,
+ provisioning_profile,
+ mapping,
+ fail_required=True,
+ )
def sonatype_clm(registry, xml_parent, data):
@@ -3343,35 +3310,33 @@ def sonatype_clm(registry, xml_parent, data):
/../../tests/builders/fixtures/sonatype-clm-full.yaml
:language: yaml
"""
- clm = XML.SubElement(xml_parent,
- 'com.sonatype.insight.ci.hudson.PreBuildScan')
- clm.set('plugin', 'sonatype-clm-ci')
- SUPPORTED_VALUES = ['list', 'manual']
- SUPPORTED_STAGES = ['build', 'stage-release', 'release', 'operate']
-
- application_select = XML.SubElement(clm,
- 'applicationSelectType')
+ clm = XML.SubElement(xml_parent, "com.sonatype.insight.ci.hudson.PreBuildScan")
+ clm.set("plugin", "sonatype-clm-ci")
+ SUPPORTED_VALUES = ["list", "manual"]
+ SUPPORTED_STAGES = ["build", "stage-release", "release", "operate"]
+
+ application_select = XML.SubElement(clm, "applicationSelectType")
application_mappings = [
- ('value', 'value', 'list', SUPPORTED_VALUES),
- ('application-name', 'applicationId', None),
+ ("value", "value", "list", SUPPORTED_VALUES),
+ ("application-name", "applicationId", None),
]
helpers.convert_mapping_to_xml(
- application_select, data, application_mappings, fail_required=True)
+ application_select, data, application_mappings, fail_required=True
+ )
- path = XML.SubElement(clm, 'pathConfig')
+ path = XML.SubElement(clm, "pathConfig")
path_mappings = [
- ('scan-targets', 'scanTargets', ''),
- ('module-excludes', 'moduleExcludes', ''),
- ('advanced-options', 'scanProperties', ''),
+ ("scan-targets", "scanTargets", ""),
+ ("module-excludes", "moduleExcludes", ""),
+ ("advanced-options", "scanProperties", ""),
]
- helpers.convert_mapping_to_xml(
- path, data, path_mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(path, data, path_mappings, fail_required=True)
mappings = [
- ('fail-on-clm-server-failure', 'failOnClmServerFailures', False),
- ('stage', 'stageId', 'build', SUPPORTED_STAGES),
- ('username', 'username', ''),
- ('password', 'password', ''),
+ ("fail-on-clm-server-failure", "failOnClmServerFailures", False),
+ ("stage", "stageId", "build", SUPPORTED_STAGES),
+ ("username", "username", ""),
+ ("password", "password", ""),
]
helpers.convert_mapping_to_xml(clm, data, mappings, fail_required=True)
@@ -3395,24 +3360,26 @@ def beaker(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/beaker-content.yaml
:language: yaml
"""
- beaker = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.beakerbuilder.'
- 'BeakerBuilder')
- jobSource = XML.SubElement(beaker, 'jobSource')
- if 'content' in data and 'path' in data:
+ beaker = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.beakerbuilder." "BeakerBuilder"
+ )
+ jobSource = XML.SubElement(beaker, "jobSource")
+ if "content" in data and "path" in data:
raise JenkinsJobsException("Use just one of 'content' or 'path'")
- elif 'content' in data:
+ elif "content" in data:
jobSourceClass = "org.jenkinsci.plugins.beakerbuilder.StringJobSource"
- jobSource.set('class', jobSourceClass)
- XML.SubElement(jobSource, 'jobContent').text = data['content']
- elif 'path' in data:
+ jobSource.set("class", jobSourceClass)
+ XML.SubElement(jobSource, "jobContent").text = data["content"]
+ elif "path" in data:
jobSourceClass = "org.jenkinsci.plugins.beakerbuilder.FileJobSource"
- jobSource.set('class', jobSourceClass)
- XML.SubElement(jobSource, 'jobPath').text = data['path']
+ jobSource.set("class", jobSourceClass)
+ XML.SubElement(jobSource, "jobPath").text = data["path"]
else:
raise JenkinsJobsException("Use one of 'content' or 'path'")
- XML.SubElement(beaker, 'downloadFiles').text = str(data.get(
- 'download-logs', False)).lower()
+ XML.SubElement(beaker, "downloadFiles").text = str(
+ data.get("download-logs", False)
+ ).lower()
def cloudformation(registry, xml_parent, data):
@@ -3452,11 +3419,11 @@ def cloudformation(registry, xml_parent, data):
:language: yaml
"""
region_dict = helpers.cloudformation_region_dict()
- stacks = helpers.cloudformation_init(
- xml_parent, data, 'CloudFormationBuildStep')
+ stacks = helpers.cloudformation_init(xml_parent, data, "CloudFormationBuildStep")
for stack in data:
helpers.cloudformation_stack(
- xml_parent, stack, 'PostBuildStackBean', stacks, region_dict)
+ xml_parent, stack, "PostBuildStackBean", stacks, region_dict
+ )
def jms_messaging(registry, xml_parent, data):
@@ -3499,8 +3466,9 @@ def jms_messaging(registry, xml_parent, data):
../../tests/builders/fixtures/jms-messaging-minimal.yaml
:language: yaml
"""
- helpers.jms_messaging_common(xml_parent, 'com.redhat.jenkins.plugins.ci.'
- 'CIMessageBuilder', data)
+ helpers.jms_messaging_common(
+ xml_parent, "com.redhat.jenkins.plugins.ci." "CIMessageBuilder", data
+ )
def openshift_build_verify(registry, xml_parent, data):
@@ -3537,17 +3505,17 @@ def openshift_build_verify(registry, xml_parent, data):
../../tests/builders/fixtures/openshift-build-verify002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftBuildVerifier')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftBuildVerifier"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("bld-cfg", 'bldCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("bld-cfg", "bldCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3590,20 +3558,20 @@ def openshift_builder(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/openshift-builder002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftBuilder')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftBuilder"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("bld-cfg", 'bldCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("commit-ID", 'commitID', ''),
- ("verbose", 'verbose', False),
- ("build-name", 'buildName', ''),
- ("show-build-logs", 'showBuildLogs', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("bld-cfg", "bldCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("commit-ID", "commitID", ""),
+ ("verbose", "verbose", False),
+ ("build-name", "buildName", ""),
+ ("show-build-logs", "showBuildLogs", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3641,17 +3609,17 @@ def openshift_creator(registry, xml_parent, data):
../../tests/builders/fixtures/openshift-creator002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftCreator')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftCreator"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("jsonyaml", 'jsonyaml', ''),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("jsonyaml", "jsonyaml", ""),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3691,18 +3659,19 @@ def openshift_dep_verify(registry, xml_parent, data):
../../tests/builders/fixtures/openshift-dep-verify002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftDeploymentVerifier')
+ osb = XML.SubElement(
+ xml_parent,
+ "com.openshift.jenkins.plugins.pipeline." "OpenShiftDeploymentVerifier",
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("dep-cfg", 'depCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("replica-count", 'replicaCount', 0),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("dep-cfg", "depCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("replica-count", "replicaCount", 0),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3738,17 +3707,17 @@ def openshift_deployer(registry, xml_parent, data):
../../tests/builders/fixtures/openshift-deployer002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftDeployer')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftDeployer"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("dep-cfg", 'depCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("dep-cfg", "depCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3788,18 +3757,18 @@ def openshift_img_tagger(registry, xml_parent, data):
../../tests/builders/fixtures/openshift-img-tagger002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftImageTagger')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftImageTagger"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("test-tag", 'testTag', 'origin-nodejs-sample:latest'),
- ("prod-tag", 'prodTag', 'origin-nodejs-sample:prod'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("test-tag", "testTag", "origin-nodejs-sample:latest"),
+ ("prod-tag", "prodTag", "origin-nodejs-sample:prod"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3835,18 +3804,18 @@ def openshift_scaler(registry, xml_parent, data):
.. literalinclude:: ../../tests/builders/fixtures/openshift-scaler002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftScaler')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftScaler"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("dep-cfg", 'depCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("replica-count", 'replicaCount', 0),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("dep-cfg", "depCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("replica-count", "replicaCount", 0),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3881,17 +3850,17 @@ def openshift_svc_verify(registry, xml_parent, data):
../../tests/builders/fixtures/openshift-svc-verify002.yaml
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftServiceVerifier')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftServiceVerifier"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("svc-name", 'svcName', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("svc-name", "svcName", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -3915,14 +3884,15 @@ def runscope(registry, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/runscope-full.yaml
:language: yaml
"""
- runscope = XML.SubElement(xml_parent,
- 'com.runscope.jenkins.Runscope.RunscopeBuilder')
- runscope.set('plugin', 'runscope')
+ runscope = XML.SubElement(
+ xml_parent, "com.runscope.jenkins.Runscope.RunscopeBuilder"
+ )
+ runscope.set("plugin", "runscope")
mapping = [
- ('test-trigger-url', 'triggerEndPoint', None),
- ('access-token', 'accessToken', None),
- ('timeout', 'timeout', 60),
+ ("test-trigger-url", "triggerEndPoint", None),
+ ("access-token", "accessToken", None),
+ ("timeout", "timeout", 60),
]
helpers.convert_mapping_to_xml(runscope, data, mapping, fail_required=True)
@@ -3947,15 +3917,12 @@ def description_setter(registry, xml_parent, data):
"""
descriptionsetter = XML.SubElement(
- xml_parent,
- 'hudson.plugins.descriptionsetter.DescriptionSetterBuilder')
- mapping = [
- ('regexp', 'regexp', ''),
- ]
- if 'description' in data:
- mapping.append(('description', 'description', None))
- helpers.convert_mapping_to_xml(
- descriptionsetter, data, mapping, fail_required=True)
+ xml_parent, "hudson.plugins.descriptionsetter.DescriptionSetterBuilder"
+ )
+ mapping = [("regexp", "regexp", "")]
+ if "description" in data:
+ mapping.append(("description", "description", None))
+ helpers.convert_mapping_to_xml(descriptionsetter, data, mapping, fail_required=True)
def build_publish_docker_image(registry, xml_parent, data):
@@ -3989,33 +3956,31 @@ def build_publish_docker_image(registry, xml_parent, data):
.. literalinclude::
/../../tests/builders/fixtures/build-publish-docker-image-full.yaml
"""
- dbp = XML.SubElement(xml_parent,
- 'com.nirima.jenkins.plugins.docker.builder'
- '.DockerBuilderPublisher')
- dbp.set('plugin', 'docker-plugin')
-
- from_registry = XML.SubElement(dbp, 'fromRegistry')
- from_registry.set('plugin', 'docker-commons')
- from_registry_mapping = [
- ('docker-registry-url', 'url', ''),
- ]
+ dbp = XML.SubElement(
+ xml_parent,
+ "com.nirima.jenkins.plugins.docker.builder" ".DockerBuilderPublisher",
+ )
+ dbp.set("plugin", "docker-plugin")
+
+ from_registry = XML.SubElement(dbp, "fromRegistry")
+ from_registry.set("plugin", "docker-commons")
+ from_registry_mapping = [("docker-registry-url", "url", "")]
helpers.convert_mapping_to_xml(
- from_registry, data, from_registry_mapping,
- fail_required=False)
+ from_registry, data, from_registry_mapping, fail_required=False
+ )
- tags = XML.SubElement(dbp, 'tags')
- XML.SubElement(tags, 'string').text = data.get('image', '')
+ tags = XML.SubElement(dbp, "tags")
+ XML.SubElement(tags, "string").text = data.get("image", "")
mapping = [
- ('docker-file-directory', 'dockerFileDirectory', ''),
- ('push-on-success', 'pushOnSuccess', False),
- ('push-credentials-id', 'pushCredentialsId', ''),
- ('clean-images', 'cleanImages', False),
- ('jenkins-job-delete', 'cleanupWithJenkinsJobDelete', False),
- ('cloud', 'cloud', ''),
+ ("docker-file-directory", "dockerFileDirectory", ""),
+ ("push-on-success", "pushOnSuccess", False),
+ ("push-credentials-id", "pushCredentialsId", ""),
+ ("clean-images", "cleanImages", False),
+ ("jenkins-job-delete", "cleanupWithJenkinsJobDelete", False),
+ ("cloud", "cloud", ""),
]
- helpers.convert_mapping_to_xml(
- dbp, data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(dbp, data, mapping, fail_required=False)
def docker_build_publish(parse, xml_parent, data):
@@ -4060,52 +4025,51 @@ def docker_build_publish(parse, xml_parent, data):
.. literalinclude:: /../../tests/builders/fixtures/docker-builder002.yaml
"""
- db = XML.SubElement(xml_parent,
- 'com.cloudbees.dockerpublish.DockerBuilder')
- db.set('plugin', 'docker-build-publish')
+ db = XML.SubElement(xml_parent, "com.cloudbees.dockerpublish.DockerBuilder")
+ db.set("plugin", "docker-build-publish")
mapping = [
- ('repo-name', 'repoName', None),
- ('repo-tag', 'repoTag', ''),
- ('no-cache', 'noCache', False),
- ('no-force-pull', 'noForcePull', False),
- ('skip-build', 'skipBuild', False),
- ('skip-decorate', 'skipDecorate', False),
- ('skip-tag-latest', 'skipTagLatest', False),
- ('skip-push', 'skipPush', False),
- ('file-path', 'dockerfilePath', ''),
- ('build-context', 'buildContext', ''),
- ('create-fingerprint', 'createFingerprint', False),
- ('build-args', 'buildAdditionalArgs', ''),
- ('force-tag', 'forceTag', False),
+ ("repo-name", "repoName", None),
+ ("repo-tag", "repoTag", ""),
+ ("no-cache", "noCache", False),
+ ("no-force-pull", "noForcePull", False),
+ ("skip-build", "skipBuild", False),
+ ("skip-decorate", "skipDecorate", False),
+ ("skip-tag-latest", "skipTagLatest", False),
+ ("skip-push", "skipPush", False),
+ ("file-path", "dockerfilePath", ""),
+ ("build-context", "buildContext", ""),
+ ("create-fingerprint", "createFingerprint", False),
+ ("build-args", "buildAdditionalArgs", ""),
+ ("force-tag", "forceTag", False),
]
helpers.convert_mapping_to_xml(db, data, mapping, fail_required=True)
mapping = []
- if 'server' in data:
- server = XML.SubElement(db, 'server')
- server.set('plugin', 'docker-commons')
- server_data = data['server']
- if 'credentials-id' in server_data:
- mapping.append(('credentials-id', 'credentialsId', None))
-
- if 'uri' in server_data:
- mapping.append(('uri', 'uri', None))
- helpers.convert_mapping_to_xml(
- server, server_data, mapping, fail_required=True)
+ if "server" in data:
+ server = XML.SubElement(db, "server")
+ server.set("plugin", "docker-commons")
+ server_data = data["server"]
+ if "credentials-id" in server_data:
+ mapping.append(("credentials-id", "credentialsId", None))
+
+ if "uri" in server_data:
+ mapping.append(("uri", "uri", None))
+ helpers.convert_mapping_to_xml(server, server_data, mapping, fail_required=True)
mappings = []
- if 'registry' in data:
- registry = XML.SubElement(db, 'registry')
- registry.set('plugin', 'docker-commons')
- registry_data = data['registry']
- if 'credentials-id' in registry_data:
- mappings.append(('credentials-id', 'credentialsId', None))
-
- if 'url' in registry_data:
- mappings.append(('url', 'url', None))
+ if "registry" in data:
+ registry = XML.SubElement(db, "registry")
+ registry.set("plugin", "docker-commons")
+ registry_data = data["registry"]
+ if "credentials-id" in registry_data:
+ mappings.append(("credentials-id", "credentialsId", None))
+
+ if "url" in registry_data:
+ mappings.append(("url", "url", None))
helpers.convert_mapping_to_xml(
- registry, registry_data, mappings, fail_required=True)
+ registry, registry_data, mappings, fail_required=True
+ )
def docker_pull_image(registry, xml_parent, data):
@@ -4131,22 +4095,23 @@ def docker_pull_image(registry, xml_parent, data):
/../../tests/builders/fixtures/docker-pull-image-full.yaml
"""
docker_pull_image = XML.SubElement(
- xml_parent, 'org.jenkinsci.plugins.registry.'
- 'notification.DockerPullImageBuilder')
- docker_pull_image.set('plugin', 'dockerhub-notification')
- registry = XML.SubElement(docker_pull_image, 'registry')
- registry.set('plugin', 'docker-commons')
- mapping = [
- ('image', 'image', ''),
- ]
+ xml_parent,
+ "org.jenkinsci.plugins.registry." "notification.DockerPullImageBuilder",
+ )
+ docker_pull_image.set("plugin", "dockerhub-notification")
+ registry = XML.SubElement(docker_pull_image, "registry")
+ registry.set("plugin", "docker-commons")
+ mapping = [("image", "image", "")]
helpers.convert_mapping_to_xml(
- docker_pull_image, data, mapping, fail_required=False)
+ docker_pull_image, data, mapping, fail_required=False
+ )
registry_mapping = [
- ('docker-registry-url', 'url', ''),
- ('credentials-id', 'credentialsId', ''),
+ ("docker-registry-url", "url", ""),
+ ("credentials-id", "credentialsId", ""),
]
helpers.convert_mapping_to_xml(
- registry, data, registry_mapping, fail_required=False)
+ registry, data, registry_mapping, fail_required=False
+ )
def build_name_setter(registry, xml_parent, data):
@@ -4177,17 +4142,16 @@ def build_name_setter(registry, xml_parent, data):
:language: yaml
"""
build_name_setter = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.buildnameupdater.BuildNameUpdater')
+ xml_parent, "org.jenkinsci.plugins.buildnameupdater.BuildNameUpdater"
+ )
mapping = [
- ('name', 'buildName', 'version.txt'),
- ('template', 'macroTemplate', '#${BUILD_NUMBER}'),
- ('file', 'fromFile', False),
- ('macro', 'fromMacro', False),
- ('macro-first', 'macroFirst', False),
+ ("name", "buildName", "version.txt"),
+ ("template", "macroTemplate", "#${BUILD_NUMBER}"),
+ ("file", "fromFile", False),
+ ("macro", "fromMacro", False),
+ ("macro-first", "macroFirst", False),
]
- helpers.convert_mapping_to_xml(
- build_name_setter, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(build_name_setter, data, mapping, fail_required=True)
def nexus_artifact_uploader(registry, xml_parent, data):
@@ -4225,25 +4189,26 @@ def nexus_artifact_uploader(registry, xml_parent, data):
:language: yaml
"""
nexus_artifact_uploader = XML.SubElement(
- xml_parent,
- 'sp.sd.nexusartifactuploader.NexusArtifactUploader')
+ xml_parent, "sp.sd.nexusartifactuploader.NexusArtifactUploader"
+ )
mapping = [
- ('protocol', 'protocol', 'https'),
- ('nexus_url', 'nexusUrl', ''),
- ('nexus_user', 'nexusUser', ''),
- ('nexus_password', 'nexusPassword', ''),
- ('group_id', 'groupId', ''),
- ('artifact_id', 'artifactId', ''),
- ('version', 'version', ''),
- ('packaging', 'packaging', ''),
- ('type', 'type', ''),
- ('classifier', 'classifier', ''),
- ('repository', 'repository', ''),
- ('file', 'file', ''),
- ('credentials_id', 'credentialsId', ''),
+ ("protocol", "protocol", "https"),
+ ("nexus_url", "nexusUrl", ""),
+ ("nexus_user", "nexusUser", ""),
+ ("nexus_password", "nexusPassword", ""),
+ ("group_id", "groupId", ""),
+ ("artifact_id", "artifactId", ""),
+ ("version", "version", ""),
+ ("packaging", "packaging", ""),
+ ("type", "type", ""),
+ ("classifier", "classifier", ""),
+ ("repository", "repository", ""),
+ ("file", "file", ""),
+ ("credentials_id", "credentialsId", ""),
]
helpers.convert_mapping_to_xml(
- nexus_artifact_uploader, data, mapping, fail_required=True)
+ nexus_artifact_uploader, data, mapping, fail_required=True
+ )
def nexus_iq_policy_evaluator(registry, xml_parent, data):
@@ -4285,55 +4250,60 @@ def nexus_iq_policy_evaluator(registry, xml_parent, data):
:language: yaml
"""
nexus_iq_policy_evaluator = XML.SubElement(
- xml_parent,
- 'org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep')
+ xml_parent, "org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep"
+ )
format_dict = {
- 'stage': 'com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage',
- 'fone': 'com__sonatype__nexus__ci__iq__IqPolicyEvaluator'
- '____failBuildOnNetworkError',
+ "stage": "com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage",
+ "fone": "com__sonatype__nexus__ci__iq__IqPolicyEvaluator"
+ "____failBuildOnNetworkError",
}
- valid_stages = ['build', 'release', 'stage-release', 'operate']
+ valid_stages = ["build", "release", "stage-release", "operate"]
mapping = [
- ('stage', format_dict.get('stage'), None, valid_stages),
- ('fail-build-network-error', format_dict.get('fone'), False),
+ ("stage", format_dict.get("stage"), None, valid_stages),
+ ("fail-build-network-error", format_dict.get("fone"), False),
]
helpers.convert_mapping_to_xml(
- nexus_iq_policy_evaluator, data, mapping, fail_required=True)
+ nexus_iq_policy_evaluator, data, mapping, fail_required=True
+ )
- application_type_label = data.get('application-type', 'manual').lower()
+ application_type_label = data.get("application-type", "manual").lower()
application_type_label_dict = {
- 'manual': 'org.sonatype.nexus.ci.iq.ManualApplication',
- 'selected': 'org.sonatype.nexus.ci.iq.SelectedApplication',
+ "manual": "org.sonatype.nexus.ci.iq.ManualApplication",
+ "selected": "org.sonatype.nexus.ci.iq.SelectedApplication",
}
if application_type_label not in application_type_label_dict:
- raise InvalidAttributeError(application_type_label,
- application_type_label,
- application_type_label_dict.keys())
+ raise InvalidAttributeError(
+ application_type_label,
+ application_type_label,
+ application_type_label_dict.keys(),
+ )
application_type_tag = XML.SubElement(
nexus_iq_policy_evaluator,
- 'com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication')
+ "com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication",
+ )
application_type_tag.set(
"class", application_type_label_dict[application_type_label]
)
- mapping = [
- ('application-id', 'applicationId', None),
- ]
- helpers.convert_mapping_to_xml(application_type_tag, data,
- mapping, fail_required=True)
+ mapping = [("application-id", "applicationId", None)]
+ helpers.convert_mapping_to_xml(
+ application_type_tag, data, mapping, fail_required=True
+ )
- scan_pattern_list = data.get('scan-patterns', [])
- iq_scan_pattern_tag = XML.SubElement(nexus_iq_policy_evaluator,
- 'com__sonatype__nexus__ci__iq'
- '__IqPolicyEvaluator____iqScanPatterns')
+ scan_pattern_list = data.get("scan-patterns", [])
+ iq_scan_pattern_tag = XML.SubElement(
+ nexus_iq_policy_evaluator,
+ "com__sonatype__nexus__ci__iq" "__IqPolicyEvaluator____iqScanPatterns",
+ )
for scan_pattern in scan_pattern_list:
scan_pattern_tag = XML.SubElement(
- iq_scan_pattern_tag, 'org.sonatype.nexus.ci.iq.ScanPattern')
- XML.SubElement(scan_pattern_tag, 'scanPattern').text = scan_pattern
+ iq_scan_pattern_tag, "org.sonatype.nexus.ci.iq.ScanPattern"
+ )
+ XML.SubElement(scan_pattern_tag, "scanPattern").text = scan_pattern
def nexus_repo_manager(registry, xml_parent, data):
@@ -4352,15 +4322,16 @@ def nexus_repo_manager(registry, xml_parent, data):
/../../tests/builders/fixtures/nexus-repo-manager-minimal.yaml
:language: yaml
"""
- nexus_repo_manager = XML.SubElement(xml_parent,
- 'org.sonatype.nexus.ci.'
- 'nxrm.NexusPublisherBuildStep')
+ nexus_repo_manager = XML.SubElement(
+ xml_parent, "org.sonatype.nexus.ci." "nxrm.NexusPublisherBuildStep"
+ )
mapping = [
- ('instance-id', 'nexusInstanceId', None),
- ('repo-id', 'nexusRepositoryId', None),
+ ("instance-id", "nexusInstanceId", None),
+ ("repo-id", "nexusRepositoryId", None),
]
- helpers.convert_mapping_to_xml(nexus_repo_manager,
- data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ nexus_repo_manager, data, mapping, fail_required=True
+ )
def ansible_playbook(parser, xml_parent, data):
@@ -4434,88 +4405,91 @@ def ansible_playbook(parser, xml_parent, data):
:language: yaml
"""
plugin = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder')
+ xml_parent, "org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder"
+ )
try:
- XML.SubElement(plugin, 'playbook').text = str(data['playbook'])
+ XML.SubElement(plugin, "playbook").text = str(data["playbook"])
except KeyError as ex:
raise MissingAttributeError(ex)
- inventory_types = ('path', 'content', 'do-not-specify')
- inventory_type = str(
- data.get('inventory-type', inventory_types[0])).lower()
+ inventory_types = ("path", "content", "do-not-specify")
+ inventory_type = str(data.get("inventory-type", inventory_types[0])).lower()
- inventory = XML.SubElement(plugin, 'inventory')
- inv_data = data.get('inventory', {})
- if inventory_type == 'path':
- inventory.set(
- 'class', 'org.jenkinsci.plugins.ansible.InventoryPath')
+ inventory = XML.SubElement(plugin, "inventory")
+ inv_data = data.get("inventory", {})
+ if inventory_type == "path":
+ inventory.set("class", "org.jenkinsci.plugins.ansible.InventoryPath")
try:
- path = inv_data['path']
+ path = inv_data["path"]
except KeyError:
- raise MissingAttributeError('inventory[\'path\']')
- XML.SubElement(inventory, 'path').text = path
- elif inventory_type == 'content':
- inventory.set(
- 'class', 'org.jenkinsci.plugins.ansible.InventoryContent')
+ raise MissingAttributeError("inventory['path']")
+ XML.SubElement(inventory, "path").text = path
+ elif inventory_type == "content":
+ inventory.set("class", "org.jenkinsci.plugins.ansible.InventoryContent")
try:
- content = inv_data['content']
+ content = inv_data["content"]
except KeyError:
- raise MissingAttributeError('inventory[\'content\']')
- XML.SubElement(inventory, 'content').text = content
- XML.SubElement(inventory, 'dynamic').text = str(
- inv_data.get('dynamic', False)).lower()
- elif inventory_type == 'do-not-specify':
- inventory.set(
- 'class', 'org.jenkinsci.plugins.ansible.InventoryDoNotSpecify')
+ raise MissingAttributeError("inventory['content']")
+ XML.SubElement(inventory, "content").text = content
+ XML.SubElement(inventory, "dynamic").text = str(
+ inv_data.get("dynamic", False)
+ ).lower()
+ elif inventory_type == "do-not-specify":
+ inventory.set("class", "org.jenkinsci.plugins.ansible.InventoryDoNotSpecify")
else:
- raise InvalidAttributeError(
- 'inventory-type', inventory_type, inventory_types)
- XML.SubElement(plugin, 'limit').text = data.get('hosts', '')
- XML.SubElement(plugin, 'tags').text = data.get('tags-to-run', '')
- XML.SubElement(plugin, 'skippedTags').text = data.get('tags-to-skip', '')
- XML.SubElement(plugin, 'startAtTask').text = data.get(
- 'task-to-start-at', '')
- XML.SubElement(plugin, 'credentialsId').text = data.get(
- 'credentials-id', '')
- XML.SubElement(plugin, 'vaultCredentialsId').text = data.get(
- 'vault-credentials-id', '')
- if data.get('sudo', False):
- XML.SubElement(plugin, 'sudo').text = 'true'
- XML.SubElement(plugin, 'sudoUser').text = data.get('sudo-user', '')
+ raise InvalidAttributeError("inventory-type", inventory_type, inventory_types)
+ XML.SubElement(plugin, "limit").text = data.get("hosts", "")
+ XML.SubElement(plugin, "tags").text = data.get("tags-to-run", "")
+ XML.SubElement(plugin, "skippedTags").text = data.get("tags-to-skip", "")
+ XML.SubElement(plugin, "startAtTask").text = data.get("task-to-start-at", "")
+ XML.SubElement(plugin, "credentialsId").text = data.get("credentials-id", "")
+ XML.SubElement(plugin, "vaultCredentialsId").text = data.get(
+ "vault-credentials-id", ""
+ )
+ if data.get("sudo", False):
+ XML.SubElement(plugin, "sudo").text = "true"
+ XML.SubElement(plugin, "sudoUser").text = data.get("sudo-user", "")
else:
- XML.SubElement(plugin, 'sudo').text = 'false'
- XML.SubElement(plugin, 'forks').text = str(data.get('workers', '5'))
- XML.SubElement(plugin, 'unbufferedOutput').text = str(
- data.get('unbuffered-output', True)).lower()
- XML.SubElement(plugin, 'colorizedOutput').text = str(
- data.get('colorized-output', False)).lower()
- XML.SubElement(plugin, 'hostKeyChecking').text = str(
- data.get('host-key-checking', False)).lower()
- XML.SubElement(plugin, 'additionalParameters').text = str(
- data.get('additional-parameters', ''))
+ XML.SubElement(plugin, "sudo").text = "false"
+ XML.SubElement(plugin, "forks").text = str(data.get("workers", "5"))
+ XML.SubElement(plugin, "unbufferedOutput").text = str(
+ data.get("unbuffered-output", True)
+ ).lower()
+ XML.SubElement(plugin, "colorizedOutput").text = str(
+ data.get("colorized-output", False)
+ ).lower()
+ XML.SubElement(plugin, "hostKeyChecking").text = str(
+ data.get("host-key-checking", False)
+ ).lower()
+ XML.SubElement(plugin, "additionalParameters").text = str(
+ data.get("additional-parameters", "")
+ )
# Following option is not available from UI
- XML.SubElement(plugin, 'copyCredentialsInWorkspace').text = 'false'
- variables = data.get('variables', [])
+ XML.SubElement(plugin, "copyCredentialsInWorkspace").text = "false"
+ variables = data.get("variables", [])
if variables:
if not is_sequence(variables):
raise InvalidAttributeError(
- 'variables', variables, 'list(dict(name, value, hidden))')
- variables_elm = XML.SubElement(plugin, 'extraVars')
+ "variables", variables, "list(dict(name, value, hidden))"
+ )
+ variables_elm = XML.SubElement(plugin, "extraVars")
for idx, values in enumerate(variables):
- if not hasattr(values, 'keys'):
+ if not hasattr(values, "keys"):
raise InvalidAttributeError(
- 'variables[%s]' % idx, values, 'dict(name, value, hidden)')
+ "variables[%s]" % idx, values, "dict(name, value, hidden)"
+ )
try:
- var_name = values['name']
+ var_name = values["name"]
except KeyError:
- raise MissingAttributeError('variables[%s][\'name\']' % idx)
+ raise MissingAttributeError("variables[%s]['name']" % idx)
value_elm = XML.SubElement(
- variables_elm, 'org.jenkinsci.plugins.ansible.ExtraVar')
- XML.SubElement(value_elm, 'key').text = var_name
- XML.SubElement(value_elm, 'value').text = values.get('value', '')
- XML.SubElement(value_elm, 'hidden').text = str(
- values.get('hidden', False)).lower()
+ variables_elm, "org.jenkinsci.plugins.ansible.ExtraVar"
+ )
+ XML.SubElement(value_elm, "key").text = var_name
+ XML.SubElement(value_elm, "value").text = values.get("value", "")
+ XML.SubElement(value_elm, "hidden").text = str(
+ values.get("hidden", False)
+ ).lower()
def nodejs(parser, xml_parent, data):
@@ -4541,20 +4515,18 @@ def nodejs(parser, xml_parent, data):
../../tests/builders/fixtures/nodejs-full.yaml
:language: yaml
"""
- nodejs = XML.SubElement(xml_parent,
- 'jenkins.plugins.nodejs.NodeJSCommandInterpreter')
- mapping = [
- ('script', 'command', None),
- ]
+ nodejs = XML.SubElement(
+ xml_parent, "jenkins.plugins.nodejs.NodeJSCommandInterpreter"
+ )
+ mapping = [("script", "command", None)]
mapping_opt = [
- ('name', 'nodeJSInstallationName', None),
- ('config-id', 'configId', None),
+ ("name", "nodeJSInstallationName", None),
+ ("config-id", "configId", None),
]
helpers.convert_mapping_to_xml(nodejs, data, mapping, fail_required=True)
- helpers.convert_mapping_to_xml(
- nodejs, data, mapping_opt, fail_required=False)
+ helpers.convert_mapping_to_xml(nodejs, data, mapping_opt, fail_required=False)
def xunit(registry, xml_parent, data):
@@ -4614,29 +4586,28 @@ def xunit(registry, xml_parent, data):
"""
logger = logging.getLogger(__name__)
- xunit = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.xunit.XUnitBuilder')
- xunit.set('plugin', 'xunit')
+ xunit = XML.SubElement(xml_parent, "org.jenkinsci.plugins.xunit.XUnitBuilder")
+ xunit.set("plugin", "xunit")
# Map our internal types to the XML element names used by Jenkins plugin
types_to_plugin_types = {
- 'aunit': 'AUnitJunitHudsonTestType',
- 'boosttest': 'BoostTestJunitHudsonTestType',
- 'checktype': 'CheckType',
- 'cpptest': 'CppTestJunitHudsonTestType',
- 'cppunit': 'CppUnitJunitHudsonTestType',
- 'ctest': 'CTestType',
- 'dotnettest': 'XUnitDotNetTestType', # since plugin v1.93
- 'embunit': 'EmbUnitType', # since plugin v1.84
- 'fpcunit': 'FPCUnitJunitHudsonTestType',
- 'gtest': 'GoogleTestType',
- 'junit': 'JUnitType',
- 'mstest': 'MSTestJunitHudsonTestType',
- 'nunit': 'NUnitJunitHudsonTestType',
- 'phpunit': 'PHPUnitJunitHudsonTestType',
- 'tusar': 'TUSARJunitHudsonTestType',
- 'unittest': 'UnitTestJunitHudsonTestType',
- 'valgrind': 'ValgrindJunitHudsonTestType',
+ "aunit": "AUnitJunitHudsonTestType",
+ "boosttest": "BoostTestJunitHudsonTestType",
+ "checktype": "CheckType",
+ "cpptest": "CppTestJunitHudsonTestType",
+ "cppunit": "CppUnitJunitHudsonTestType",
+ "ctest": "CTestType",
+ "dotnettest": "XUnitDotNetTestType", # since plugin v1.93
+ "embunit": "EmbUnitType", # since plugin v1.84
+ "fpcunit": "FPCUnitJunitHudsonTestType",
+ "gtest": "GoogleTestType",
+ "junit": "JUnitType",
+ "mstest": "MSTestJunitHudsonTestType",
+ "nunit": "NUnitJunitHudsonTestType",
+ "phpunit": "PHPUnitJunitHudsonTestType",
+ "tusar": "TUSARJunitHudsonTestType",
+ "unittest": "UnitTestJunitHudsonTestType",
+ "valgrind": "ValgrindJunitHudsonTestType",
# FIXME should implement the 'custom' type
}
implemented_types = types_to_plugin_types.keys() # shortcut
@@ -4644,58 +4615,56 @@ def xunit(registry, xml_parent, data):
# Unit framework we are going to generate xml for
supported_types = []
- for configured_type in data['types']:
+ for configured_type in data["types"]:
type_name = next(iter(configured_type.keys()))
if type_name not in implemented_types:
- logger.warning("Requested xUnit type '%s' is not yet supported",
- type_name)
+ logger.warning("Requested xUnit type '%s' is not yet supported", type_name)
else:
# Append for generation
supported_types.append(configured_type)
# Generate XML for each of the supported framework types
- xmltypes = XML.SubElement(xunit, 'types')
+ xmltypes = XML.SubElement(xunit, "types")
mappings = [
- ('pattern', 'pattern', ''),
- ('requireupdate', 'failIfNotNew', True),
- ('deleteoutput', 'deleteOutputFiles', True),
- ('skip-if-no-test-files', 'skipNoTestFiles', False),
- ('stoponerror', 'stopProcessingIfError', True),
+ ("pattern", "pattern", ""),
+ ("requireupdate", "failIfNotNew", True),
+ ("deleteoutput", "deleteOutputFiles", True),
+ ("skip-if-no-test-files", "skipNoTestFiles", False),
+ ("stoponerror", "stopProcessingIfError", True),
]
for supported_type in supported_types:
framework_name = next(iter(supported_type.keys()))
- xmlframework = XML.SubElement(xmltypes,
- types_to_plugin_types[framework_name])
+ xmlframework = XML.SubElement(xmltypes, types_to_plugin_types[framework_name])
- helpers.convert_mapping_to_xml(xmlframework,
- supported_type[framework_name],
- mappings,
- fail_required=True)
+ helpers.convert_mapping_to_xml(
+ xmlframework, supported_type[framework_name], mappings, fail_required=True
+ )
- xmlthresholds = XML.SubElement(xunit, 'thresholds')
- for t in data.get('thresholds', []):
- if not ('failed' in t or 'skipped' in t):
- logger.warning(
- "Unrecognized threshold, should be 'failed' or 'skipped'")
+ xmlthresholds = XML.SubElement(xunit, "thresholds")
+ for t in data.get("thresholds", []):
+ if not ("failed" in t or "skipped" in t):
+ logger.warning("Unrecognized threshold, should be 'failed' or 'skipped'")
continue
- elname = ("org.jenkinsci.plugins.xunit.threshold.%sThreshold" %
- next(iter(t.keys())).title())
+ elname = (
+ "org.jenkinsci.plugins.xunit.threshold.%sThreshold"
+ % next(iter(t.keys())).title()
+ )
el = XML.SubElement(xmlthresholds, elname)
for threshold_name, threshold_value in next(iter(t.values())).items():
# Normalize and craft the element name for this threshold
- elname = "%sThreshold" % threshold_name.lower().replace(
- 'new', 'New')
+ elname = "%sThreshold" % threshold_name.lower().replace("new", "New")
XML.SubElement(el, elname).text = str(threshold_value)
# Whether to use percent of exact number of tests.
# Thresholdmode is either:
# - 1 : absolute (number of tests), default.
# - 2 : relative (percentage of tests)
- thresholdmode = '1'
- if 'percent' == data.get('thresholdmode', 'number'):
- thresholdmode = '2'
- XML.SubElement(xunit, 'thresholdMode').text = thresholdmode
-
- extra_config = XML.SubElement(xunit, 'extraConfiguration')
- XML.SubElement(extra_config, 'testTimeMargin').text = str(
- data.get('test-time-margin', '3000'))
+ thresholdmode = "1"
+ if "percent" == data.get("thresholdmode", "number"):
+ thresholdmode = "2"
+ XML.SubElement(xunit, "thresholdMode").text = thresholdmode
+
+ extra_config = XML.SubElement(xunit, "extraConfiguration")
+ XML.SubElement(extra_config, "testTimeMargin").text = str(
+ data.get("test-time-margin", "3000")
+ )
diff --git a/jenkins_jobs/modules/general.py b/jenkins_jobs/modules/general.py
index 6a893afa..02b1647b 100644
--- a/jenkins_jobs/modules/general.py
+++ b/jenkins_jobs/modules/general.py
@@ -123,88 +123,85 @@ class General(jenkins_jobs.modules.base.Base):
logrotate_warn_issued = False
def gen_xml(self, xml, data):
- jdk = data.get('jdk', None)
+ jdk = data.get("jdk", None)
if jdk:
- XML.SubElement(xml, 'jdk').text = jdk
- XML.SubElement(xml, 'actions')
- desc_text = data.get('description', None)
+ XML.SubElement(xml, "jdk").text = jdk
+ XML.SubElement(xml, "actions")
+ desc_text = data.get("description", None)
if desc_text is not None:
- description = XML.SubElement(xml, 'description')
+ description = XML.SubElement(xml, "description")
description.text = desc_text
- XML.SubElement(xml, 'keepDependencies').text = 'false'
+ XML.SubElement(xml, "keepDependencies").text = "false"
# Need to ensure we support the None parameter to allow disabled to
# remain the last setting if the user purposely adds and then removes
# the disabled parameter.
# See: http://lists.openstack.org/pipermail/openstack-infra/2016-March/003980.html # noqa
- disabled = data.get('disabled', None)
+ disabled = data.get("disabled", None)
if disabled is not None:
- XML.SubElement(xml, 'disabled').text = str(disabled).lower()
+ XML.SubElement(xml, "disabled").text = str(disabled).lower()
- if 'display-name' in data:
- XML.SubElement(xml, 'displayName').text = data['display-name']
- if data.get('block-downstream'):
- XML.SubElement(xml,
- 'blockBuildWhenDownstreamBuilding').text = 'true'
+ if "display-name" in data:
+ XML.SubElement(xml, "displayName").text = data["display-name"]
+ if data.get("block-downstream"):
+ XML.SubElement(xml, "blockBuildWhenDownstreamBuilding").text = "true"
else:
- XML.SubElement(xml,
- 'blockBuildWhenDownstreamBuilding').text = 'false'
- if data.get('block-upstream'):
- XML.SubElement(xml,
- 'blockBuildWhenUpstreamBuilding').text = 'true'
+ XML.SubElement(xml, "blockBuildWhenDownstreamBuilding").text = "false"
+ if data.get("block-upstream"):
+ XML.SubElement(xml, "blockBuildWhenUpstreamBuilding").text = "true"
else:
- XML.SubElement(xml,
- 'blockBuildWhenUpstreamBuilding').text = 'false'
- authtoken = data.get('auth-token', None)
+ XML.SubElement(xml, "blockBuildWhenUpstreamBuilding").text = "false"
+ authtoken = data.get("auth-token", None)
if authtoken is not None:
- XML.SubElement(xml, 'authToken').text = authtoken
- if data.get('concurrent'):
- XML.SubElement(xml, 'concurrentBuild').text = 'true'
+ XML.SubElement(xml, "authToken").text = authtoken
+ if data.get("concurrent"):
+ XML.SubElement(xml, "concurrentBuild").text = "true"
else:
- XML.SubElement(xml, 'concurrentBuild').text = 'false'
- if 'workspace' in data:
- XML.SubElement(xml, 'customWorkspace').text = \
- str(data['workspace'])
- if (xml.tag == 'matrix-project') and ('child-workspace' in data):
- XML.SubElement(xml, 'childCustomWorkspace').text = \
- str(data['child-workspace'])
- if 'quiet-period' in data:
- XML.SubElement(xml, 'quietPeriod').text = str(data['quiet-period'])
- node = data.get('node', None)
+ XML.SubElement(xml, "concurrentBuild").text = "false"
+ if "workspace" in data:
+ XML.SubElement(xml, "customWorkspace").text = str(data["workspace"])
+ if (xml.tag == "matrix-project") and ("child-workspace" in data):
+ XML.SubElement(xml, "childCustomWorkspace").text = str(
+ data["child-workspace"]
+ )
+ if "quiet-period" in data:
+ XML.SubElement(xml, "quietPeriod").text = str(data["quiet-period"])
+ node = data.get("node", None)
if node:
- XML.SubElement(xml, 'assignedNode').text = node
- XML.SubElement(xml, 'canRoam').text = 'false'
+ XML.SubElement(xml, "assignedNode").text = node
+ XML.SubElement(xml, "canRoam").text = "false"
else:
- XML.SubElement(xml, 'canRoam').text = 'true'
- if 'retry-count' in data:
- XML.SubElement(xml, 'scmCheckoutRetryCount').text = \
- str(data['retry-count'])
+ XML.SubElement(xml, "canRoam").text = "true"
+ if "retry-count" in data:
+ XML.SubElement(xml, "scmCheckoutRetryCount").text = str(data["retry-count"])
- if 'logrotate' in data:
+ if "logrotate" in data:
if not self.logrotate_warn_issued:
- logging.warning('logrotate is deprecated on jenkins>=1.637,'
- ' the property build-discarder on newer'
- ' jenkins instead')
+ logging.warning(
+ "logrotate is deprecated on jenkins>=1.637,"
+ " the property build-discarder on newer"
+ " jenkins instead"
+ )
self.logrotate_warn_issued = True
- lr_xml = XML.SubElement(xml, 'logRotator')
- logrotate = data['logrotate']
- lr_days = XML.SubElement(lr_xml, 'daysToKeep')
- lr_days.text = str(logrotate.get('daysToKeep', -1))
- lr_num = XML.SubElement(lr_xml, 'numToKeep')
- lr_num.text = str(logrotate.get('numToKeep', -1))
- lr_adays = XML.SubElement(lr_xml, 'artifactDaysToKeep')
- lr_adays.text = str(logrotate.get('artifactDaysToKeep', -1))
- lr_anum = XML.SubElement(lr_xml, 'artifactNumToKeep')
- lr_anum.text = str(logrotate.get('artifactNumToKeep', -1))
+ lr_xml = XML.SubElement(xml, "logRotator")
+ logrotate = data["logrotate"]
+ lr_days = XML.SubElement(lr_xml, "daysToKeep")
+ lr_days.text = str(logrotate.get("daysToKeep", -1))
+ lr_num = XML.SubElement(lr_xml, "numToKeep")
+ lr_num.text = str(logrotate.get("numToKeep", -1))
+ lr_adays = XML.SubElement(lr_xml, "artifactDaysToKeep")
+ lr_adays.text = str(logrotate.get("artifactDaysToKeep", -1))
+ lr_anum = XML.SubElement(lr_xml, "artifactNumToKeep")
+ lr_anum.text = str(logrotate.get("artifactNumToKeep", -1))
- if 'raw' in data:
- raw(self.registry, xml, data['raw'])
+ if "raw" in data:
+ raw(self.registry, xml, data["raw"])
def raw(registry, xml_parent, data):
# documented in definition.rst since includes and docs is not working well
# For cross cutting method like this
- root = XML.fromstring(data.get('xml'))
+ root = XML.fromstring(data.get("xml"))
remove_ignorable_whitespace(root)
xml_parent.append(root)
diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py
index d4bea4ca..10945c71 100644
--- a/jenkins_jobs/modules/helpers.py
+++ b/jenkins_jobs/modules/helpers.py
@@ -29,59 +29,62 @@ def build_trends_publisher(plugin_name, xml_element, data):
"""Appends the status thresholds.
"""
- for status in ['unstable', 'failed']:
+ for status in ["unstable", "failed"]:
status_data = data.get(status, {})
limits = [
- ('total-all', 'TotalAll'),
- ('total-high', 'TotalHigh'),
- ('total-normal', 'TotalNormal'),
- ('total-low', 'TotalLow')]
+ ("total-all", "TotalAll"),
+ ("total-high", "TotalHigh"),
+ ("total-normal", "TotalNormal"),
+ ("total-low", "TotalLow"),
+ ]
if only_totals is False:
- limits.extend([
- ('new-all', 'NewAll'),
- ('new-high', 'NewHigh'),
- ('new-normal', 'NewNormal'),
- ('new-low', 'NewLow')])
+ limits.extend(
+ [
+ ("new-all", "NewAll"),
+ ("new-high", "NewHigh"),
+ ("new-normal", "NewNormal"),
+ ("new-low", "NewLow"),
+ ]
+ )
for key, tag_suffix in limits:
tag_name = status + tag_suffix
- XML.SubElement(element, tag_name).text = str(
- status_data.get(key, ''))
+ XML.SubElement(element, tag_name).text = str(status_data.get(key, ""))
# Tuples containing: setting name, tag name, default value
settings = [
- ('healthy', 'healthy', ''),
- ('unhealthy', 'unHealthy', ''),
- ('health-threshold', 'thresholdLimit', 'low'),
- ('plugin-name', 'pluginName', plugin_name),
- ('default-encoding', 'defaultEncoding', ''),
- ('can-run-on-failed', 'canRunOnFailed', False),
- ('use-stable-build-as-reference', 'useStableBuildAsReference', False),
- ('use-previous-build-as-reference',
- 'usePreviousBuildAsReference', False),
- ('use-delta-values', 'useDeltaValues', False),
- ('thresholds', 'thresholds', {}),
- ('should-detect-modules', 'shouldDetectModules', False),
- ('dont-compute-new', 'dontComputeNew', True),
- ('do-not-resolve-relative-paths', 'doNotResolveRelativePaths', False),
- ('pattern', 'pattern', '')]
-
- thresholds = ['low', 'normal', 'high']
+ ("healthy", "healthy", ""),
+ ("unhealthy", "unHealthy", ""),
+ ("health-threshold", "thresholdLimit", "low"),
+ ("plugin-name", "pluginName", plugin_name),
+ ("default-encoding", "defaultEncoding", ""),
+ ("can-run-on-failed", "canRunOnFailed", False),
+ ("use-stable-build-as-reference", "useStableBuildAsReference", False),
+ ("use-previous-build-as-reference", "usePreviousBuildAsReference", False),
+ ("use-delta-values", "useDeltaValues", False),
+ ("thresholds", "thresholds", {}),
+ ("should-detect-modules", "shouldDetectModules", False),
+ ("dont-compute-new", "dontComputeNew", True),
+ ("do-not-resolve-relative-paths", "doNotResolveRelativePaths", False),
+ ("pattern", "pattern", ""),
+ ]
+
+ thresholds = ["low", "normal", "high"]
for key, tag_name, default in settings:
xml_config = XML.SubElement(xml_element, tag_name)
config_value = data.get(key, default)
- if key == 'thresholds':
+ if key == "thresholds":
append_thresholds(
- xml_config,
- config_value,
- data.get('dont-compute-new', True))
- elif key == 'health-threshold' and config_value not in thresholds:
- raise JenkinsJobsException("health-threshold must be one of %s" %
- ", ".join(thresholds))
+ xml_config, config_value, data.get("dont-compute-new", True)
+ )
+ elif key == "health-threshold" and config_value not in thresholds:
+ raise JenkinsJobsException(
+ "health-threshold must be one of %s" % ", ".join(thresholds)
+ )
else:
if isinstance(default, bool):
xml_config.text = str(config_value).lower()
@@ -91,379 +94,385 @@ def build_trends_publisher(plugin_name, xml_element, data):
def config_file_provider_builder(xml_parent, data):
"""Builder / Wrapper helper"""
- xml_files = XML.SubElement(xml_parent, 'managedFiles')
+ xml_files = XML.SubElement(xml_parent, "managedFiles")
- files = data.get('files', [])
+ files = data.get("files", [])
for file in files:
- xml_file = XML.SubElement(xml_files, 'org.jenkinsci.plugins.'
- 'configfiles.buildwrapper.ManagedFile')
+ xml_file = XML.SubElement(
+ xml_files, "org.jenkinsci.plugins." "configfiles.buildwrapper.ManagedFile"
+ )
mapping = [
- ('file-id', 'fileId', None),
- ('target', 'targetLocation', ''),
- ('variable', 'variable', ''),
- ('replace-tokens', 'replaceTokens', False),
+ ("file-id", "fileId", None),
+ ("target", "targetLocation", ""),
+ ("variable", "variable", ""),
+ ("replace-tokens", "replaceTokens", False),
]
convert_mapping_to_xml(xml_file, file, mapping, fail_required=True)
def config_file_provider_settings(xml_parent, data):
- SETTINGS_TYPES = ['file', 'cfp']
+ SETTINGS_TYPES = ["file", "cfp"]
settings = {
- 'default-settings':
- 'jenkins.mvn.DefaultSettingsProvider',
- 'settings':
- 'jenkins.mvn.FilePathSettingsProvider',
- 'config-file-provider-settings':
- 'org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider',
- 'default-global-settings':
- 'jenkins.mvn.DefaultGlobalSettingsProvider',
- 'global-settings':
- 'jenkins.mvn.FilePathGlobalSettingsProvider',
- 'config-file-provider-global-settings':
- 'org.jenkinsci.plugins.configfiles.maven.job.'
- 'MvnGlobalSettingsProvider',
+ "default-settings": "jenkins.mvn.DefaultSettingsProvider",
+ "settings": "jenkins.mvn.FilePathSettingsProvider",
+ "config-file-provider-settings": "org.jenkinsci.plugins.configfiles.maven.job.MvnSettingsProvider",
+ "default-global-settings": "jenkins.mvn.DefaultGlobalSettingsProvider",
+ "global-settings": "jenkins.mvn.FilePathGlobalSettingsProvider",
+ "config-file-provider-global-settings": "org.jenkinsci.plugins.configfiles.maven.job."
+ "MvnGlobalSettingsProvider",
}
- if 'settings' in data:
+ if "settings" in data:
# Support for Config File Provider
- settings_file = str(data['settings'])
- settings_type = data.get('settings-type', 'file')
+ settings_file = str(data["settings"])
+ settings_type = data.get("settings-type", "file")
# For cfp versions <2.10.0 we are able to detect cfp via the config
# settings name.
- text = 'org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig'
+ text = "org.jenkinsci.plugins.configfiles.maven.MavenSettingsConfig"
if settings_file.startswith(text):
- settings_type = 'cfp'
+ settings_type = "cfp"
- if settings_type == 'file':
+ if settings_type == "file":
lsettings = XML.SubElement(
- xml_parent, 'settings',
- {'class': settings['settings']})
- XML.SubElement(lsettings, 'path').text = settings_file
- elif settings_type == 'cfp':
+ xml_parent, "settings", {"class": settings["settings"]}
+ )
+ XML.SubElement(lsettings, "path").text = settings_file
+ elif settings_type == "cfp":
lsettings = XML.SubElement(
- xml_parent, 'settings',
- {'class': settings['config-file-provider-settings']})
- XML.SubElement(lsettings, 'settingsConfigId').text = settings_file
+ xml_parent,
+ "settings",
+ {"class": settings["config-file-provider-settings"]},
+ )
+ XML.SubElement(lsettings, "settingsConfigId").text = settings_file
else:
- raise InvalidAttributeError(
- 'settings-type', settings_type, SETTINGS_TYPES)
+ raise InvalidAttributeError("settings-type", settings_type, SETTINGS_TYPES)
else:
- XML.SubElement(xml_parent, 'settings',
- {'class': settings['default-settings']})
+ XML.SubElement(xml_parent, "settings", {"class": settings["default-settings"]})
- if 'global-settings' in data:
+ if "global-settings" in data:
# Support for Config File Provider
- global_settings_file = str(data['global-settings'])
- global_settings_type = data.get('global-settings-type', 'file')
+ global_settings_file = str(data["global-settings"])
+ global_settings_type = data.get("global-settings-type", "file")
# For cfp versions <2.10.0 we are able to detect cfp via the config
# settings name.
- text = ('org.jenkinsci.plugins.configfiles.maven.'
- 'GlobalMavenSettingsConfig')
+ text = "org.jenkinsci.plugins.configfiles.maven." "GlobalMavenSettingsConfig"
if global_settings_file.startswith(text):
- global_settings_type = 'cfp'
+ global_settings_type = "cfp"
- if global_settings_type == 'file':
- gsettings = XML.SubElement(xml_parent, 'globalSettings',
- {'class': settings['global-settings']})
- XML.SubElement(gsettings, 'path').text = global_settings_file
- elif global_settings_type == 'cfp':
+ if global_settings_type == "file":
+ gsettings = XML.SubElement(
+ xml_parent, "globalSettings", {"class": settings["global-settings"]}
+ )
+ XML.SubElement(gsettings, "path").text = global_settings_file
+ elif global_settings_type == "cfp":
gsettings = XML.SubElement(
- xml_parent, 'globalSettings',
- {'class': settings['config-file-provider-global-settings']})
- XML.SubElement(
- gsettings,
- 'settingsConfigId').text = global_settings_file
+ xml_parent,
+ "globalSettings",
+ {"class": settings["config-file-provider-global-settings"]},
+ )
+ XML.SubElement(gsettings, "settingsConfigId").text = global_settings_file
else:
raise InvalidAttributeError(
- 'settings-type', global_settings_type, SETTINGS_TYPES)
+ "settings-type", global_settings_type, SETTINGS_TYPES
+ )
else:
- XML.SubElement(xml_parent, 'globalSettings',
- {'class': settings['default-global-settings']})
+ XML.SubElement(
+ xml_parent, "globalSettings", {"class": settings["default-global-settings"]}
+ )
-def copyartifact_build_selector(xml_parent, data, select_tag='selector'):
+def copyartifact_build_selector(xml_parent, data, select_tag="selector"):
- select = data.get('which-build', 'last-successful')
+ select = data.get("which-build", "last-successful")
selectdict = {
- 'last-successful': 'StatusBuildSelector',
- 'last-completed': 'LastCompletedBuildSelector',
- 'specific-build': 'SpecificBuildSelector',
- 'last-saved': 'SavedBuildSelector',
- 'upstream-build': 'TriggeredBuildSelector',
- 'permalink': 'PermalinkBuildSelector',
- 'workspace-latest': 'WorkspaceSelector',
- 'build-param': 'ParameterizedBuildSelector',
- 'downstream-build': 'DownstreamBuildSelector',
- 'multijob-build': 'MultiJobBuildSelector'
+ "last-successful": "StatusBuildSelector",
+ "last-completed": "LastCompletedBuildSelector",
+ "specific-build": "SpecificBuildSelector",
+ "last-saved": "SavedBuildSelector",
+ "upstream-build": "TriggeredBuildSelector",
+ "permalink": "PermalinkBuildSelector",
+ "workspace-latest": "WorkspaceSelector",
+ "build-param": "ParameterizedBuildSelector",
+ "downstream-build": "DownstreamBuildSelector",
+ "multijob-build": "MultiJobBuildSelector",
}
if select not in selectdict:
- raise InvalidAttributeError('which-build',
- select,
- selectdict.keys())
- permalink = data.get('permalink', 'last')
- permalinkdict = {'last': 'lastBuild',
- 'last-stable': 'lastStableBuild',
- 'last-successful': 'lastSuccessfulBuild',
- 'last-failed': 'lastFailedBuild',
- 'last-unstable': 'lastUnstableBuild',
- 'last-unsuccessful': 'lastUnsuccessfulBuild'}
+ raise InvalidAttributeError("which-build", select, selectdict.keys())
+ permalink = data.get("permalink", "last")
+ permalinkdict = {
+ "last": "lastBuild",
+ "last-stable": "lastStableBuild",
+ "last-successful": "lastSuccessfulBuild",
+ "last-failed": "lastFailedBuild",
+ "last-unstable": "lastUnstableBuild",
+ "last-unsuccessful": "lastUnsuccessfulBuild",
+ }
if permalink not in permalinkdict:
- raise InvalidAttributeError('permalink',
- permalink,
- permalinkdict.keys())
- if select == 'multijob-build':
- selector = XML.SubElement(xml_parent, select_tag,
- {'class':
- 'com.tikal.jenkins.plugins.multijob.' +
- selectdict[select]})
+ raise InvalidAttributeError("permalink", permalink, permalinkdict.keys())
+ if select == "multijob-build":
+ selector = XML.SubElement(
+ xml_parent,
+ select_tag,
+ {"class": "com.tikal.jenkins.plugins.multijob." + selectdict[select]},
+ )
else:
- selector = XML.SubElement(xml_parent, select_tag,
- {'class':
- 'hudson.plugins.copyartifact.' +
- selectdict[select]})
+ selector = XML.SubElement(
+ xml_parent,
+ select_tag,
+ {"class": "hudson.plugins.copyartifact." + selectdict[select]},
+ )
mapping = []
- if select == 'specific-build':
- mapping.append(('build-number', 'buildNumber', ''))
- if select == 'last-successful':
- mapping.append(('stable', 'stable', False))
- if select == 'upstream-build':
- mapping.append(
- ('fallback-to-last-successful', 'fallbackToLastSuccessful', False))
- if select == 'permalink':
- mapping.append(('', 'id', permalinkdict[permalink]))
- if select == 'build-param':
- mapping.append(('param', 'parameterName', ''))
- if select == 'downstream-build':
- mapping.append(
- ('upstream-project-name', 'upstreamProjectName', ''))
+ if select == "specific-build":
+ mapping.append(("build-number", "buildNumber", ""))
+ if select == "last-successful":
+ mapping.append(("stable", "stable", False))
+ if select == "upstream-build":
mapping.append(
- ('upstream-build-number', 'upstreamBuildNumber', ''))
+ ("fallback-to-last-successful", "fallbackToLastSuccessful", False)
+ )
+ if select == "permalink":
+ mapping.append(("", "id", permalinkdict[permalink]))
+ if select == "build-param":
+ mapping.append(("param", "parameterName", ""))
+ if select == "downstream-build":
+ mapping.append(("upstream-project-name", "upstreamProjectName", ""))
+ mapping.append(("upstream-build-number", "upstreamBuildNumber", ""))
convert_mapping_to_xml(selector, data, mapping, fail_required=False)
def findbugs_settings(xml_parent, data):
# General Options
mapping = [
- ('rank-priority', 'isRankActivated', False),
- ('include-files', 'includePattern', ''),
- ('exclude-files', 'excludePattern', ''),
+ ("rank-priority", "isRankActivated", False),
+ ("include-files", "includePattern", ""),
+ ("exclude-files", "excludePattern", ""),
]
convert_mapping_to_xml(xml_parent, data, mapping, fail_required=True)
def get_value_from_yaml_or_config_file(key, section, data, jjb_config):
- return jjb_config.get_plugin_config(section, key, data.get(key, ''))
+ return jjb_config.get_plugin_config(section, key, data.get(key, ""))
def cloudformation_region_dict():
- region_dict = {'us-east-1': 'US_East_Northern_Virginia',
- 'us-west-1': 'US_WEST_Northern_California',
- 'us-west-2': 'US_WEST_Oregon',
- 'eu-central-1': 'EU_Frankfurt',
- 'eu-west-1': 'EU_Ireland',
- 'ap-southeast-1': 'Asia_Pacific_Singapore',
- 'ap-southeast-2': 'Asia_Pacific_Sydney',
- 'ap-northeast-1': 'Asia_Pacific_Tokyo',
- 'sa-east-1': 'South_America_Sao_Paulo'}
+ region_dict = {
+ "us-east-1": "US_East_Northern_Virginia",
+ "us-west-1": "US_WEST_Northern_California",
+ "us-west-2": "US_WEST_Oregon",
+ "eu-central-1": "EU_Frankfurt",
+ "eu-west-1": "EU_Ireland",
+ "ap-southeast-1": "Asia_Pacific_Singapore",
+ "ap-southeast-2": "Asia_Pacific_Sydney",
+ "ap-northeast-1": "Asia_Pacific_Tokyo",
+ "sa-east-1": "South_America_Sao_Paulo",
+ }
return region_dict
def cloudformation_init(xml_parent, data, xml_tag):
cloudformation = XML.SubElement(
- xml_parent, 'com.syncapse.jenkinsci.'
- 'plugins.awscloudformationwrapper.' + xml_tag)
- return XML.SubElement(cloudformation, 'stacks')
+ xml_parent,
+ "com.syncapse.jenkinsci." "plugins.awscloudformationwrapper." + xml_tag,
+ )
+ return XML.SubElement(cloudformation, "stacks")
def cloudformation_stack(xml_parent, stack, xml_tag, stacks, region_dict):
- if 'name' not in stack or stack['name'] == '':
- raise MissingAttributeError('name')
+ if "name" not in stack or stack["name"] == "":
+ raise MissingAttributeError("name")
step = XML.SubElement(
- stacks, 'com.syncapse.jenkinsci.plugins.'
- 'awscloudformationwrapper.' + xml_tag)
+ stacks, "com.syncapse.jenkinsci.plugins." "awscloudformationwrapper." + xml_tag
+ )
- if xml_tag == 'SimpleStackBean':
- mapping = [('prefix', 'isPrefixSelected', False)]
+ if xml_tag == "SimpleStackBean":
+ mapping = [("prefix", "isPrefixSelected", False)]
else:
- parameters_value = ','.join(stack.get('parameters', []))
+ parameters_value = ",".join(stack.get("parameters", []))
mapping = [
- ('description', 'description', ''),
- ('', 'parameters', parameters_value),
- ('timeout', 'timeout', '0'),
- ('sleep', 'sleep', '0'),
- ('recipe', 'cloudFormationRecipe', None)]
+ ("description", "description", ""),
+ ("", "parameters", parameters_value),
+ ("timeout", "timeout", "0"),
+ ("sleep", "sleep", "0"),
+ ("recipe", "cloudFormationRecipe", None),
+ ]
cloudformation_stack_mapping = [
- ('name', 'stackName', None),
- ('access-key', 'awsAccessKey', None),
- ('secret-key', 'awsSecretKey', None),
- ('region', 'awsRegion', None, region_dict)]
+ ("name", "stackName", None),
+ ("access-key", "awsAccessKey", None),
+ ("secret-key", "awsSecretKey", None),
+ ("region", "awsRegion", None, region_dict),
+ ]
for map in mapping:
cloudformation_stack_mapping.append(map)
- convert_mapping_to_xml(step, stack,
- cloudformation_stack_mapping, fail_required=True)
+ convert_mapping_to_xml(
+ step, stack, cloudformation_stack_mapping, fail_required=True
+ )
-def include_exclude_patterns(xml_parent, data, yaml_prefix,
- xml_elem_name):
+def include_exclude_patterns(xml_parent, data, yaml_prefix, xml_elem_name):
xml_element = XML.SubElement(xml_parent, xml_elem_name)
- XML.SubElement(xml_element, 'includePatterns').text = ','.join(
- data.get(yaml_prefix + '-include-patterns', []))
- XML.SubElement(xml_element, 'excludePatterns').text = ','.join(
- data.get(yaml_prefix + '-exclude-patterns', []))
+ XML.SubElement(xml_element, "includePatterns").text = ",".join(
+ data.get(yaml_prefix + "-include-patterns", [])
+ )
+ XML.SubElement(xml_element, "excludePatterns").text = ",".join(
+ data.get(yaml_prefix + "-exclude-patterns", [])
+ )
def artifactory_deployment_patterns(xml_parent, data):
- include_exclude_patterns(xml_parent, data, 'deployment',
- 'artifactDeploymentPatterns')
+ include_exclude_patterns(
+ xml_parent, data, "deployment", "artifactDeploymentPatterns"
+ )
def artifactory_env_vars_patterns(xml_parent, data):
- include_exclude_patterns(xml_parent, data, 'env-vars',
- 'envVarsPatterns')
+ include_exclude_patterns(xml_parent, data, "env-vars", "envVarsPatterns")
def artifactory_optional_props(xml_parent, data, target):
optional_str_props = [
- ('scopes', 'scopes'),
- ('violationRecipients', 'violation-recipients'),
- ('blackDuckAppName', 'black-duck-app-name'),
- ('blackDuckAppVersion', 'black-duck-app-version'),
- ('blackDuckReportRecipients', 'black-duck-report-recipients'),
- ('blackDuckScopes', 'black-duck-scopes')
+ ("scopes", "scopes"),
+ ("violationRecipients", "violation-recipients"),
+ ("blackDuckAppName", "black-duck-app-name"),
+ ("blackDuckAppVersion", "black-duck-app-version"),
+ ("blackDuckReportRecipients", "black-duck-report-recipients"),
+ ("blackDuckScopes", "black-duck-scopes"),
]
for (xml_prop, yaml_prop) in optional_str_props:
- XML.SubElement(xml_parent, xml_prop).text = data.get(
- yaml_prop, '')
+ XML.SubElement(xml_parent, xml_prop).text = data.get(yaml_prop, "")
common_bool_props = [
# yaml property name, xml property name, default value
- ('deploy-artifacts', 'deployArtifacts', True),
- ('discard-old-builds', 'discardOldBuilds', False),
- ('discard-build-artifacts', 'discardBuildArtifacts', False),
- ('publish-build-info', 'deployBuildInfo', False),
- ('env-vars-include', 'includeEnvVars', False),
- ('run-checks', 'runChecks', False),
- ('include-publish-artifacts', 'includePublishArtifacts', False),
- ('license-auto-discovery', 'licenseAutoDiscovery', True),
- ('enable-issue-tracker-integration', 'enableIssueTrackerIntegration',
- False),
- ('aggregate-build-issues', 'aggregateBuildIssues', False),
- ('black-duck-run-checks', 'blackDuckRunChecks', False),
- ('black-duck-include-published-artifacts',
- 'blackDuckIncludePublishedArtifacts', False),
- ('auto-create-missing-component-requests',
- 'autoCreateMissingComponentRequests', True),
- ('auto-discard-stale-component-requests',
- 'autoDiscardStaleComponentRequests', True),
- ('filter-excluded-artifacts-from-build',
- 'filterExcludedArtifactsFromBuild', False)
+ ("deploy-artifacts", "deployArtifacts", True),
+ ("discard-old-builds", "discardOldBuilds", False),
+ ("discard-build-artifacts", "discardBuildArtifacts", False),
+ ("publish-build-info", "deployBuildInfo", False),
+ ("env-vars-include", "includeEnvVars", False),
+ ("run-checks", "runChecks", False),
+ ("include-publish-artifacts", "includePublishArtifacts", False),
+ ("license-auto-discovery", "licenseAutoDiscovery", True),
+ ("enable-issue-tracker-integration", "enableIssueTrackerIntegration", False),
+ ("aggregate-build-issues", "aggregateBuildIssues", False),
+ ("black-duck-run-checks", "blackDuckRunChecks", False),
+ (
+ "black-duck-include-published-artifacts",
+ "blackDuckIncludePublishedArtifacts",
+ False,
+ ),
+ (
+ "auto-create-missing-component-requests",
+ "autoCreateMissingComponentRequests",
+ True,
+ ),
+ (
+ "auto-discard-stale-component-requests",
+ "autoDiscardStaleComponentRequests",
+ True,
+ ),
+ (
+ "filter-excluded-artifacts-from-build",
+ "filterExcludedArtifactsFromBuild",
+ False,
+ ),
]
- convert_mapping_to_xml(
- xml_parent, data, common_bool_props, fail_required=True)
+ convert_mapping_to_xml(xml_parent, data, common_bool_props, fail_required=True)
- if 'wrappers' in target:
+ if "wrappers" in target:
wrapper_bool_props = [
- ('enable-resolve-artifacts', 'enableResolveArtifacts', False),
- ('disable-license-auto-discovery',
- 'disableLicenseAutoDiscovery', False),
- ('record-all-dependencies',
- 'recordAllDependencies', False)
+ ("enable-resolve-artifacts", "enableResolveArtifacts", False),
+ ("disable-license-auto-discovery", "disableLicenseAutoDiscovery", False),
+ ("record-all-dependencies", "recordAllDependencies", False),
]
- convert_mapping_to_xml(
- xml_parent, data, wrapper_bool_props, fail_required=True)
+ convert_mapping_to_xml(xml_parent, data, wrapper_bool_props, fail_required=True)
- if 'publishers' in target:
+ if "publishers" in target:
publisher_bool_props = [
- ('even-if-unstable', 'evenIfUnstable', False),
- ('pass-identified-downstream', 'passIdentifiedDownstream', False),
- ('allow-promotion-of-non-staged-builds',
- 'allowPromotionOfNonStagedBuilds', False)
+ ("even-if-unstable", "evenIfUnstable", False),
+ ("pass-identified-downstream", "passIdentifiedDownstream", False),
+ (
+ "allow-promotion-of-non-staged-builds",
+ "allowPromotionOfNonStagedBuilds",
+ False,
+ ),
]
convert_mapping_to_xml(
- xml_parent, data, publisher_bool_props, fail_required=True)
+ xml_parent, data, publisher_bool_props, fail_required=True
+ )
def artifactory_common_details(details, data):
- mapping = [
- ('name', 'artifactoryName', ''),
- ('url', 'artifactoryUrl', ''),
- ]
+ mapping = [("name", "artifactoryName", ""), ("url", "artifactoryUrl", "")]
convert_mapping_to_xml(details, data, mapping, fail_required=True)
def artifactory_repository(xml_parent, data, target):
- if 'release' in target:
+ if "release" in target:
release_mapping = [
- ('deploy-release-repo-key', 'keyFromText', ''),
- ('deploy-release-repo-key', 'keyFromSelect', ''),
- ('deploy-dynamic-mode', 'dynamicMode', False),
+ ("deploy-release-repo-key", "keyFromText", ""),
+ ("deploy-release-repo-key", "keyFromSelect", ""),
+ ("deploy-dynamic-mode", "dynamicMode", False),
]
- convert_mapping_to_xml(
- xml_parent, data, release_mapping, fail_required=True)
+ convert_mapping_to_xml(xml_parent, data, release_mapping, fail_required=True)
- if 'snapshot' in target:
+ if "snapshot" in target:
snapshot_mapping = [
- ('deploy-snapshot-repo-key', 'keyFromText', ''),
- ('deploy-snapshot-repo-key', 'keyFromSelect', ''),
- ('deploy-dynamic-mode', 'dynamicMode', False),
+ ("deploy-snapshot-repo-key", "keyFromText", ""),
+ ("deploy-snapshot-repo-key", "keyFromSelect", ""),
+ ("deploy-dynamic-mode", "dynamicMode", False),
]
- convert_mapping_to_xml(
- xml_parent, data, snapshot_mapping, fail_required=True)
+ convert_mapping_to_xml(xml_parent, data, snapshot_mapping, fail_required=True)
def append_git_revision_config(parent, config_def):
- params = XML.SubElement(
- parent, 'hudson.plugins.git.GitRevisionBuildParameters')
+ params = XML.SubElement(parent, "hudson.plugins.git.GitRevisionBuildParameters")
try:
# If git-revision is a boolean, the get() will
# throw an AttributeError
- combine_commits = str(
- config_def.get('combine-queued-commits', False)).lower()
+ combine_commits = str(config_def.get("combine-queued-commits", False)).lower()
except AttributeError:
- combine_commits = 'false'
+ combine_commits = "false"
- XML.SubElement(params, 'combineQueuedCommits').text = combine_commits
+ XML.SubElement(params, "combineQueuedCommits").text = combine_commits
def test_fairy_common(xml_element, data):
- xml_element.set('plugin', 'TestFairy')
- valid_max_duration = ['10m', '60m', '300m', '1440m']
+ xml_element.set("plugin", "TestFairy")
+ valid_max_duration = ["10m", "60m", "300m", "1440m"]
valid_interval = [1, 2, 5]
- valid_video_quality = ['high', 'medium', 'low']
+ valid_video_quality = ["high", "medium", "low"]
mappings = [
# General
- ('apikey', 'apiKey', None),
- ('appfile', 'appFile', None),
- ('tester-groups', 'testersGroups', ''),
- ('notify-testers', 'notifyTesters', True),
- ('autoupdate', 'autoUpdate', True),
+ ("apikey", "apiKey", None),
+ ("appfile", "appFile", None),
+ ("tester-groups", "testersGroups", ""),
+ ("notify-testers", "notifyTesters", True),
+ ("autoupdate", "autoUpdate", True),
# Session
- ('max-duration', 'maxDuration', '10m', valid_max_duration),
- ('record-on-background', 'recordOnBackground', False),
- ('data-only-wifi', 'dataOnlyWifi', False),
+ ("max-duration", "maxDuration", "10m", valid_max_duration),
+ ("record-on-background", "recordOnBackground", False),
+ ("data-only-wifi", "dataOnlyWifi", False),
# Video
- ('video-enabled', 'isVideoEnabled', True),
- ('screenshot-interval', 'screenshotInterval', 1, valid_interval),
- ('video-quality', 'videoQuality', 'high', valid_video_quality),
+ ("video-enabled", "isVideoEnabled", True),
+ ("screenshot-interval", "screenshotInterval", 1, valid_interval),
+ ("video-quality", "videoQuality", "high", valid_video_quality),
# Metrics
- ('cpu', 'cpu', True),
- ('memory', 'memory', True),
- ('logs', 'logs', True),
- ('network', 'network', False),
- ('phone-signal', 'phoneSignal', False),
- ('wifi', 'wifi', False),
- ('gps', 'gps', False),
- ('battery', 'battery', False),
- ('opengl', 'openGl', False),
+ ("cpu", "cpu", True),
+ ("memory", "memory", True),
+ ("logs", "logs", True),
+ ("network", "network", False),
+ ("phone-signal", "phoneSignal", False),
+ ("wifi", "wifi", False),
+ ("gps", "gps", False),
+ ("battery", "battery", False),
+ ("opengl", "openGl", False),
# Advanced options
- ('advanced-options', 'advancedOptions', '')
+ ("advanced-options", "advancedOptions", ""),
]
convert_mapping_to_xml(xml_element, data, mappings, fail_required=True)
@@ -471,25 +480,31 @@ def test_fairy_common(xml_element, data):
def trigger_get_parameter_order(registry, plugin):
logger = logging.getLogger("%s:trigger_get_parameter_order" % __name__)
- if str(registry.jjb_config.get_plugin_config(
- plugin, 'param_order_from_yaml', True)).lower() == 'false':
+ if (
+ str(
+ registry.jjb_config.get_plugin_config(plugin, "param_order_from_yaml", True)
+ ).lower()
+ == "false"
+ ):
logger.warning(
"Using deprecated order for parameter sets in %s. It is "
"recommended that you update your job definition instead of "
- "enabling use of the old hardcoded order", plugin)
+ "enabling use of the old hardcoded order",
+ plugin,
+ )
# deprecated order
return [
- 'predefined-parameters',
- 'git-revision',
- 'property-file',
- 'current-parameters',
- 'node-parameters',
- 'svn-revision',
- 'restrict-matrix-project',
- 'node-label-name',
- 'node-label',
- 'boolean-parameters',
+ "predefined-parameters",
+ "git-revision",
+ "property-file",
+ "current-parameters",
+ "node-parameters",
+ "svn-revision",
+ "restrict-matrix-project",
+ "node-label-name",
+ "node-label",
+ "boolean-parameters",
]
return None
@@ -498,7 +513,7 @@ def trigger_get_parameter_order(registry, plugin):
def trigger_project(tconfigs, project_def, param_order=None):
logger = logging.getLogger("%s:trigger_project" % __name__)
- pt_prefix = 'hudson.plugins.parameterizedtrigger.'
+ pt_prefix = "hudson.plugins.parameterizedtrigger."
if param_order:
parameters = param_order
else:
@@ -509,88 +524,93 @@ def trigger_project(tconfigs, project_def, param_order=None):
if param_value is None:
continue
- if param_type == 'predefined-parameters':
- params = XML.SubElement(tconfigs, pt_prefix +
- 'PredefinedBuildParameters')
- properties = XML.SubElement(params, 'properties')
+ if param_type == "predefined-parameters":
+ params = XML.SubElement(tconfigs, pt_prefix + "PredefinedBuildParameters")
+ properties = XML.SubElement(params, "properties")
properties.text = param_value
- elif param_type == 'git-revision' and param_value:
- if 'combine-queued-commits' in project_def:
+ elif param_type == "git-revision" and param_value:
+ if "combine-queued-commits" in project_def:
logger.warning(
"'combine-queued-commit' has moved to reside under "
"'git-revision' configuration, please update your "
"configs as support for this will be removed."
)
git_revision = {
- 'combine-queued-commits':
- project_def['combine-queued-commits']
+ "combine-queued-commits": project_def["combine-queued-commits"]
}
else:
- git_revision = project_def['git-revision']
+ git_revision = project_def["git-revision"]
append_git_revision_config(tconfigs, git_revision)
- elif param_type == 'property-file':
- params = XML.SubElement(tconfigs,
- pt_prefix + 'FileBuildParameters')
+ elif param_type == "property-file":
+ params = XML.SubElement(tconfigs, pt_prefix + "FileBuildParameters")
property_file_mapping = [
- ('property-file', 'propertiesFile', None),
- ('fail-on-missing', 'failTriggerOnMissing', False)]
- convert_mapping_to_xml(params, project_def,
- property_file_mapping, fail_required=True)
- if 'file-encoding' in project_def:
- XML.SubElement(params, 'encoding'
- ).text = project_def['file-encoding']
- if 'use-matrix-child-files' in project_def:
+ ("property-file", "propertiesFile", None),
+ ("fail-on-missing", "failTriggerOnMissing", False),
+ ]
+ convert_mapping_to_xml(
+ params, project_def, property_file_mapping, fail_required=True
+ )
+ if "file-encoding" in project_def:
+ XML.SubElement(params, "encoding").text = project_def["file-encoding"]
+ if "use-matrix-child-files" in project_def:
# TODO: These parameters only affect execution in
# publishers of matrix projects; we should warn if they are
# used in other contexts.
use_matrix_child_files_mapping = [
- ('use-matrix-child-files', "useMatrixChild", None),
- ('matrix-child-combination-filter',
- "combinationFilter", ''),
- ('only-exact-matrix-child-runs', "onlyExactRuns", False)]
- convert_mapping_to_xml(params, project_def,
- use_matrix_child_files_mapping, fail_required=True)
- elif param_type == 'current-parameters' and param_value:
- XML.SubElement(tconfigs, pt_prefix + 'CurrentBuildParameters')
- elif param_type == 'node-parameters' and param_value:
- XML.SubElement(tconfigs, pt_prefix + 'NodeParameters')
- elif param_type == 'svn-revision' and param_value:
- param = XML.SubElement(tconfigs, pt_prefix +
- 'SubversionRevisionBuildParameters')
- XML.SubElement(param, 'includeUpstreamParameters').text = str(
- project_def.get('include-upstream', False)).lower()
- elif param_type == 'restrict-matrix-project' and param_value:
- subset = XML.SubElement(tconfigs, pt_prefix +
- 'matrix.MatrixSubsetBuildParameters')
- XML.SubElement(subset, 'filter'
- ).text = project_def['restrict-matrix-project']
- elif (param_type == 'node-label-name' or
- param_type == 'node-label'):
- tag_name = ('org.jvnet.jenkins.plugins.nodelabelparameter.'
- 'parameterizedtrigger.NodeLabelBuildParameter')
+ ("use-matrix-child-files", "useMatrixChild", None),
+ ("matrix-child-combination-filter", "combinationFilter", ""),
+ ("only-exact-matrix-child-runs", "onlyExactRuns", False),
+ ]
+ convert_mapping_to_xml(
+ params,
+ project_def,
+ use_matrix_child_files_mapping,
+ fail_required=True,
+ )
+ elif param_type == "current-parameters" and param_value:
+ XML.SubElement(tconfigs, pt_prefix + "CurrentBuildParameters")
+ elif param_type == "node-parameters" and param_value:
+ XML.SubElement(tconfigs, pt_prefix + "NodeParameters")
+ elif param_type == "svn-revision" and param_value:
+ param = XML.SubElement(
+ tconfigs, pt_prefix + "SubversionRevisionBuildParameters"
+ )
+ XML.SubElement(param, "includeUpstreamParameters").text = str(
+ project_def.get("include-upstream", False)
+ ).lower()
+ elif param_type == "restrict-matrix-project" and param_value:
+ subset = XML.SubElement(
+ tconfigs, pt_prefix + "matrix.MatrixSubsetBuildParameters"
+ )
+ XML.SubElement(subset, "filter").text = project_def[
+ "restrict-matrix-project"
+ ]
+ elif param_type == "node-label-name" or param_type == "node-label":
+ tag_name = (
+ "org.jvnet.jenkins.plugins.nodelabelparameter."
+ "parameterizedtrigger.NodeLabelBuildParameter"
+ )
if tconfigs.find(tag_name) is not None:
# already processed and can only have one
continue
params = XML.SubElement(tconfigs, tag_name)
- name = XML.SubElement(params, 'name')
- if 'node-label-name' in project_def:
- name.text = project_def['node-label-name']
- label = XML.SubElement(params, 'nodeLabel')
- if 'node-label' in project_def:
- label.text = project_def['node-label']
- elif param_type == 'boolean-parameters' and param_value:
- params = XML.SubElement(tconfigs,
- pt_prefix + 'BooleanParameters')
- config_tag = XML.SubElement(params, 'configs')
- param_tag_text = pt_prefix + 'BooleanParameterConfig'
+ name = XML.SubElement(params, "name")
+ if "node-label-name" in project_def:
+ name.text = project_def["node-label-name"]
+ label = XML.SubElement(params, "nodeLabel")
+ if "node-label" in project_def:
+ label.text = project_def["node-label"]
+ elif param_type == "boolean-parameters" and param_value:
+ params = XML.SubElement(tconfigs, pt_prefix + "BooleanParameters")
+ config_tag = XML.SubElement(params, "configs")
+ param_tag_text = pt_prefix + "BooleanParameterConfig"
params_list = param_value
for name, value in params_list.items():
param_tag = XML.SubElement(config_tag, param_tag_text)
- mapping = [
- ('', 'name', name),
- ('', 'value', value or False)]
- convert_mapping_to_xml(param_tag, project_def,
- mapping, fail_required=True)
+ mapping = [("", "name", name), ("", "value", value or False)]
+ convert_mapping_to_xml(
+ param_tag, project_def, mapping, fail_required=True
+ )
def convert_mapping_to_xml(parent, data, mapping, fail_required=True):
@@ -661,19 +681,17 @@ def jms_messaging_common(parent, subelement, data):
data is passed to mapper helper function to map yaml fields to XML fields
"""
- namespace = XML.SubElement(parent,
- subelement)
+ namespace = XML.SubElement(parent, subelement)
- if 'override-topic' in data:
- overrides = XML.SubElement(namespace, 'overrides')
- XML.SubElement(overrides,
- 'topic').text = str(data.get('override-topic', ''))
+ if "override-topic" in data:
+ overrides = XML.SubElement(namespace, "overrides")
+ XML.SubElement(overrides, "topic").text = str(data.get("override-topic", ""))
mapping = [
# option, xml name, default value
- ("provider-name", 'providerName', ''),
- ("msg-type", 'messageType', 'CodeQualityChecksDone'),
- ("msg-props", 'messageProperties', ''),
- ("msg-content", 'messageContent', ''),
+ ("provider-name", "providerName", ""),
+ ("msg-type", "messageType", "CodeQualityChecksDone"),
+ ("msg-props", "messageProperties", ""),
+ ("msg-content", "messageContent", ""),
]
convert_mapping_to_xml(namespace, data, mapping, fail_required=True)
diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py
index c315c30c..3601fe54 100644
--- a/jenkins_jobs/modules/hipchat_notif.py
+++ b/jenkins_jobs/modules/hipchat_notif.py
@@ -104,95 +104,99 @@ class HipChat(jenkins_jobs.modules.base.Base):
jjb_config = self.registry.jjb_config
if not self.authToken:
try:
- self.authToken = jjb_config.get_plugin_config('hipchat',
- 'authtoken')
+ self.authToken = jjb_config.get_plugin_config("hipchat", "authtoken")
# Require that the authtoken is non-null
- if self.authToken == '':
+ if self.authToken == "":
raise jenkins_jobs.errors.JenkinsJobsException(
- "Hipchat authtoken must not be a blank string")
- except (configparser.NoSectionError,
- jenkins_jobs.errors.JenkinsJobsException) as e:
- logger.fatal("The configuration file needs a hipchat section" +
- " containing authtoken:\n{0}".format(e))
+ "Hipchat authtoken must not be a blank string"
+ )
+ except (
+ configparser.NoSectionError,
+ jenkins_jobs.errors.JenkinsJobsException,
+ ) as e:
+ logger.fatal(
+ "The configuration file needs a hipchat section"
+ + " containing authtoken:\n{0}".format(e)
+ )
sys.exit(1)
- self.jenkinsUrl = jjb_config.get_plugin_config('hipchat', 'url')
- self.sendAs = jjb_config.get_plugin_config('hipchat', 'send-as')
+ self.jenkinsUrl = jjb_config.get_plugin_config("hipchat", "url")
+ self.sendAs = jjb_config.get_plugin_config("hipchat", "send-as")
def gen_xml(self, xml_parent, data):
- hipchat = data.get('hipchat')
- if not hipchat or not hipchat.get('enabled', True):
+ hipchat = data.get("hipchat")
+ if not hipchat or not hipchat.get("enabled", True):
return
self._load_global_data()
# convert for compatibility before dispatch
- if 'room' in hipchat:
- if 'rooms' in hipchat:
- logger.warning("Ignoring deprecated 'room' as 'rooms' also "
- "defined.")
+ if "room" in hipchat:
+ if "rooms" in hipchat:
+ logger.warning("Ignoring deprecated 'room' as 'rooms' also " "defined.")
else:
logger.warning("'room' is deprecated, please use 'rooms'")
- hipchat['rooms'] = [hipchat['room']]
+ hipchat["rooms"] = [hipchat["room"]]
plugin_info = self.registry.get_plugin_info("Jenkins HipChat Plugin")
- version = pkg_resources.parse_version(plugin_info.get('version', '0'))
+ version = pkg_resources.parse_version(plugin_info.get("version", "0"))
if version >= pkg_resources.parse_version("0.1.9"):
- publishers = xml_parent.find('publishers')
+ publishers = xml_parent.find("publishers")
if publishers is None:
- publishers = XML.SubElement(xml_parent, 'publishers')
+ publishers = XML.SubElement(xml_parent, "publishers")
logger.warning(
"'hipchat' module supports the old plugin versions <1.9, "
"newer versions are supported via the 'publishers' module. "
- "Please upgrade you job definition")
- component = {'hipchat': hipchat}
- return self.registry.dispatch('publisher', publishers, component)
+ "Please upgrade you job definition"
+ )
+ component = {"hipchat": hipchat}
+ return self.registry.dispatch("publisher", publishers, component)
else:
- properties = xml_parent.find('properties')
+ properties = xml_parent.find("properties")
if properties is None:
- properties = XML.SubElement(xml_parent, 'properties')
- pdefhip = XML.SubElement(properties,
- 'jenkins.plugins.hipchat.'
- 'HipChatNotifier_-HipChatJobProperty')
+ properties = XML.SubElement(xml_parent, "properties")
+ pdefhip = XML.SubElement(
+ properties,
+ "jenkins.plugins.hipchat." "HipChatNotifier_-HipChatJobProperty",
+ )
- room = XML.SubElement(pdefhip, 'room')
- if 'rooms' in hipchat:
- room.text = ",".join(hipchat['rooms'])
+ room = XML.SubElement(pdefhip, "room")
+ if "rooms" in hipchat:
+ room.text = ",".join(hipchat["rooms"])
# Handle backwards compatibility 'start-notify' but all add an element
# of standardization with notify-*
- if hipchat.get('start-notify'):
- logger.warning("'start-notify' is deprecated, please use "
- "'notify-start'")
- XML.SubElement(pdefhip, 'startNotification').text = str(
- hipchat.get('notify-start', hipchat.get('start-notify',
- False))).lower()
+ if hipchat.get("start-notify"):
+ logger.warning("'start-notify' is deprecated, please use " "'notify-start'")
+ XML.SubElement(pdefhip, "startNotification").text = str(
+ hipchat.get("notify-start", hipchat.get("start-notify", False))
+ ).lower()
if version >= pkg_resources.parse_version("0.1.5"):
mapping = [
- ('notify-success', 'notifySuccess', False),
- ('notify-aborted', 'notifyAborted', False),
- ('notify-not-built', 'notifyNotBuilt', False),
- ('notify-unstable', 'notifyUnstable', False),
- ('notify-failure', 'notifyFailure', False),
- ('notify-back-to-normal', 'notifyBackToNormal', False),
+ ("notify-success", "notifySuccess", False),
+ ("notify-aborted", "notifyAborted", False),
+ ("notify-not-built", "notifyNotBuilt", False),
+ ("notify-unstable", "notifyUnstable", False),
+ ("notify-failure", "notifyFailure", False),
+ ("notify-back-to-normal", "notifyBackToNormal", False),
]
- helpers.convert_mapping_to_xml(pdefhip,
- hipchat, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ pdefhip, hipchat, mapping, fail_required=True
+ )
- publishers = xml_parent.find('publishers')
+ publishers = xml_parent.find("publishers")
if publishers is None:
- publishers = XML.SubElement(xml_parent, 'publishers')
- hippub = XML.SubElement(publishers,
- 'jenkins.plugins.hipchat.HipChatNotifier')
+ publishers = XML.SubElement(xml_parent, "publishers")
+ hippub = XML.SubElement(publishers, "jenkins.plugins.hipchat.HipChatNotifier")
if version >= pkg_resources.parse_version("0.1.8"):
- XML.SubElement(hippub, 'buildServerUrl').text = self.jenkinsUrl
- XML.SubElement(hippub, 'sendAs').text = self.sendAs
+ XML.SubElement(hippub, "buildServerUrl").text = self.jenkinsUrl
+ XML.SubElement(hippub, "sendAs").text = self.sendAs
else:
- XML.SubElement(hippub, 'jenkinsUrl').text = self.jenkinsUrl
+ XML.SubElement(hippub, "jenkinsUrl").text = self.jenkinsUrl
- XML.SubElement(hippub, 'authToken').text = self.authToken
+ XML.SubElement(hippub, "authToken").text = self.authToken
# The room specified here is the default room. The default is
# redundant in this case since a room must be specified. Leave empty.
- XML.SubElement(hippub, 'room').text = ''
+ XML.SubElement(hippub, "room").text = ""
diff --git a/jenkins_jobs/modules/hudson_model.py b/jenkins_jobs/modules/hudson_model.py
index 3f33a38d..1b7eb6f2 100644
--- a/jenkins_jobs/modules/hudson_model.py
+++ b/jenkins_jobs/modules/hudson_model.py
@@ -12,45 +12,20 @@
# Representation of the hudson.model.Result class
-SUCCESS = {
- 'name': 'SUCCESS',
- 'ordinal': '0',
- 'color': 'BLUE',
- 'complete': True
-}
+SUCCESS = {"name": "SUCCESS", "ordinal": "0", "color": "BLUE", "complete": True}
-UNSTABLE = {
- 'name': 'UNSTABLE',
- 'ordinal': '1',
- 'color': 'YELLOW',
- 'complete': True
-}
+UNSTABLE = {"name": "UNSTABLE", "ordinal": "1", "color": "YELLOW", "complete": True}
-FAILURE = {
- 'name': 'FAILURE',
- 'ordinal': '2',
- 'color': 'RED',
- 'complete': True
-}
+FAILURE = {"name": "FAILURE", "ordinal": "2", "color": "RED", "complete": True}
-NOTBUILD = {
- 'name': 'NOT_BUILD',
- 'ordinal': '3',
- 'color': 'NOTBUILD',
- 'complete': False
-}
+NOTBUILD = {"name": "NOT_BUILD", "ordinal": "3", "color": "NOTBUILD", "complete": False}
-ABORTED = {
- 'name': 'ABORTED',
- 'ordinal': '4',
- 'color': 'ABORTED',
- 'complete': False
-}
+ABORTED = {"name": "ABORTED", "ordinal": "4", "color": "ABORTED", "complete": False}
THRESHOLDS = {
- 'SUCCESS': SUCCESS,
- 'UNSTABLE': UNSTABLE,
- 'FAILURE': FAILURE,
- 'NOT_BUILD': NOTBUILD,
- 'ABORTED': ABORTED
+ "SUCCESS": SUCCESS,
+ "UNSTABLE": UNSTABLE,
+ "FAILURE": FAILURE,
+ "NOT_BUILD": NOTBUILD,
+ "ABORTED": ABORTED,
}
diff --git a/jenkins_jobs/modules/metadata.py b/jenkins_jobs/modules/metadata.py
index fb4c97c5..eb28ccd6 100644
--- a/jenkins_jobs/modules/metadata.py
+++ b/jenkins_jobs/modules/metadata.py
@@ -38,13 +38,14 @@ import jenkins_jobs.modules.base
def base_metadata(registry, xml_parent, data, mtype):
pdef = XML.SubElement(xml_parent, mtype)
- XML.SubElement(pdef, 'name').text = data['name']
- XML.SubElement(pdef, 'generated').text = 'false'
- XML.SubElement(pdef, 'parent', attrib={"class": "job-metadata",
- "reference": "../../.."})
-
- exposed_to_env = XML.SubElement(pdef, 'exposedToEnvironment')
- exposed_to_env.text = str(data.get('expose-to-env', False)).lower()
+ XML.SubElement(pdef, "name").text = data["name"]
+ XML.SubElement(pdef, "generated").text = "false"
+ XML.SubElement(
+ pdef, "parent", attrib={"class": "job-metadata", "reference": "../../.."}
+ )
+
+ exposed_to_env = XML.SubElement(pdef, "exposedToEnvironment")
+ exposed_to_env.text = str(data.get("expose-to-env", False)).lower()
return pdef
@@ -64,10 +65,9 @@ def string_metadata(registry, xml_parent, data):
value: bar
expose-to-env: true
"""
- pdef = base_metadata(registry, xml_parent, data,
- 'metadata-string')
- value = data.get('value', '')
- XML.SubElement(pdef, 'value').text = value
+ pdef = base_metadata(registry, xml_parent, data, "metadata-string")
+ value = data.get("value", "")
+ XML.SubElement(pdef, "value").text = value
def number_metadata(registry, xml_parent, data):
@@ -86,10 +86,9 @@ def number_metadata(registry, xml_parent, data):
value: 1
expose-to-env: true
"""
- pdef = base_metadata(registry, xml_parent, data,
- 'metadata-number')
- value = data.get('value', '')
- XML.SubElement(pdef, 'value').text = value
+ pdef = base_metadata(registry, xml_parent, data, "metadata-number")
+ value = data.get("value", "")
+ XML.SubElement(pdef, "value").text = value
def date_metadata(registry, xml_parent, data):
@@ -110,30 +109,28 @@ def date_metadata(registry, xml_parent, data):
timezone: Australia/Melbourne
expose-to-env: true
"""
- pdef = base_metadata(registry, xml_parent, data,
- 'metadata-date')
+ pdef = base_metadata(registry, xml_parent, data, "metadata-date")
# TODO: convert time from any reasonable format into epoch
- mval = XML.SubElement(pdef, 'value')
- XML.SubElement(mval, 'time').text = data['time']
- XML.SubElement(mval, 'timezone').text = data['timezone']
- XML.SubElement(pdef, 'checked').text = 'true'
+ mval = XML.SubElement(pdef, "value")
+ XML.SubElement(mval, "time").text = data["time"]
+ XML.SubElement(mval, "timezone").text = data["timezone"]
+ XML.SubElement(pdef, "checked").text = "true"
class Metadata(jenkins_jobs.modules.base.Base):
sequence = 21
- component_type = 'metadata'
- component_list_type = 'metadata'
+ component_type = "metadata"
+ component_list_type = "metadata"
def gen_xml(self, xml_parent, data):
- properties = xml_parent.find('properties')
+ properties = xml_parent.find("properties")
if properties is None:
- properties = XML.SubElement(xml_parent, 'properties')
+ properties = XML.SubElement(xml_parent, "properties")
- metadata = data.get('metadata', [])
+ metadata = data.get("metadata", [])
if metadata:
- pdefp = XML.SubElement(properties,
- 'job-metadata', plugin="metadata@1.0b")
- pdefs = XML.SubElement(pdefp, 'values')
+ pdefp = XML.SubElement(properties, "job-metadata", plugin="metadata@1.0b")
+ pdefs = XML.SubElement(pdefp, "values")
for mdata in metadata:
- self.registry.dispatch('metadata', pdefs, mdata)
+ self.registry.dispatch("metadata", pdefs, mdata)
diff --git a/jenkins_jobs/modules/notifications.py b/jenkins_jobs/modules/notifications.py
index e35cb75f..f1f9407e 100644
--- a/jenkins_jobs/modules/notifications.py
+++ b/jenkins_jobs/modules/notifications.py
@@ -52,44 +52,44 @@ def http_endpoint(registry, xml_parent, data):
:language: yaml
"""
- endpoint_element = XML.SubElement(xml_parent,
- 'com.tikal.hudson.plugins.notification.'
- 'Endpoint')
- supported_formats = ['JSON', 'XML']
- supported_events = ['started', 'completed', 'finalized', 'all']
- fmt = data.get('format', 'JSON').upper()
- event = data.get('event', 'all').lower()
+ endpoint_element = XML.SubElement(
+ xml_parent, "com.tikal.hudson.plugins.notification." "Endpoint"
+ )
+ supported_formats = ["JSON", "XML"]
+ supported_events = ["started", "completed", "finalized", "all"]
+ fmt = data.get("format", "JSON").upper()
+ event = data.get("event", "all").lower()
mapping = [
- ('', 'format', fmt, supported_formats),
- ('', 'protocol', 'HTTP'),
- ('', 'event', event, supported_events),
- ('timeout', 'timeout', 30000),
- ('url', 'url', None),
- ('log', 'loglines', 0),
+ ("", "format", fmt, supported_formats),
+ ("", "protocol", "HTTP"),
+ ("", "event", event, supported_events),
+ ("timeout", "timeout", 30000),
+ ("url", "url", None),
+ ("log", "loglines", 0),
]
- helpers.convert_mapping_to_xml(
- endpoint_element, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(endpoint_element, data, mapping, fail_required=True)
class Notifications(jenkins_jobs.modules.base.Base):
sequence = 22
- component_type = 'notification'
- component_list_type = 'notifications'
+ component_type = "notification"
+ component_list_type = "notifications"
def gen_xml(self, xml_parent, data):
- properties = xml_parent.find('properties')
+ properties = xml_parent.find("properties")
if properties is None:
- properties = XML.SubElement(xml_parent, 'properties')
+ properties = XML.SubElement(xml_parent, "properties")
- notifications = data.get('notifications', [])
+ notifications = data.get("notifications", [])
if notifications:
- notify_element = XML.SubElement(properties,
- 'com.tikal.hudson.plugins.'
- 'notification.'
- 'HudsonNotificationProperty')
- endpoints_element = XML.SubElement(notify_element, 'endpoints')
+ notify_element = XML.SubElement(
+ properties,
+ "com.tikal.hudson.plugins."
+ "notification."
+ "HudsonNotificationProperty",
+ )
+ endpoints_element = XML.SubElement(notify_element, "endpoints")
for endpoint in notifications:
- self.registry.dispatch('notification',
- endpoints_element, endpoint)
+ self.registry.dispatch("notification", endpoints_element, endpoint)
diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py
index acfe0164..763c0e24 100644
--- a/jenkins_jobs/modules/parameters.py
+++ b/jenkins_jobs/modules/parameters.py
@@ -43,14 +43,14 @@ import jenkins_jobs.modules.helpers as helpers
def base_param(registry, xml_parent, data, do_default, ptype):
pdef = XML.SubElement(xml_parent, ptype)
- XML.SubElement(pdef, 'name').text = data['name']
- XML.SubElement(pdef, 'description').text = data.get('description', '')
+ XML.SubElement(pdef, "name").text = data["name"]
+ XML.SubElement(pdef, "description").text = data.get("description", "")
if do_default:
- default = data.get('default', None)
+ default = data.get("default", None)
if default is not None:
- XML.SubElement(pdef, 'defaultValue').text = str(default)
+ XML.SubElement(pdef, "defaultValue").text = str(default)
else:
- XML.SubElement(pdef, 'defaultValue')
+ XML.SubElement(pdef, "defaultValue")
return pdef
@@ -70,8 +70,9 @@ def string_param(registry, xml_parent, data):
default: bar
description: "A parameter named FOO, defaults to 'bar'."
"""
- base_param(registry, xml_parent, data, True,
- 'hudson.model.StringParameterDefinition')
+ base_param(
+ registry, xml_parent, data, True, "hudson.model.StringParameterDefinition"
+ )
def promoted_param(registry, xml_parent, data):
@@ -92,16 +93,20 @@ def promoted_param(registry, xml_parent, data):
:language: yaml
"""
- pdef = base_param(registry, xml_parent, data, False,
- 'hudson.plugins.promoted__builds.parameters.'
- 'PromotedBuildParameterDefinition')
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "hudson.plugins.promoted__builds.parameters."
+ "PromotedBuildParameterDefinition",
+ )
try:
- XML.SubElement(pdef, 'projectName').text = data['project-name']
+ XML.SubElement(pdef, "projectName").text = data["project-name"]
except KeyError:
- raise MissingAttributeError('project-name')
+ raise MissingAttributeError("project-name")
- XML.SubElement(pdef, 'promotionProcessName').text = data.get(
- 'promotion-name', None)
+ XML.SubElement(pdef, "promotionProcessName").text = data.get("promotion-name", None)
def password_param(registry, xml_parent, data):
@@ -120,8 +125,9 @@ def password_param(registry, xml_parent, data):
default: 1HSC0Ts6E161FysGf+e1xasgsHkgleLh09JUTYnipPvw=
description: "A parameter named FOO."
"""
- base_param(registry, xml_parent, data, True,
- 'hudson.model.PasswordParameterDefinition')
+ base_param(
+ registry, xml_parent, data, True, "hudson.model.PasswordParameterDefinition"
+ )
def bool_param(registry, xml_parent, data):
@@ -140,9 +146,10 @@ def bool_param(registry, xml_parent, data):
default: false
description: "A parameter named FOO, defaults to 'false'."
"""
- data['default'] = str(data.get('default', False)).lower()
- base_param(registry, xml_parent, data, True,
- 'hudson.model.BooleanParameterDefinition')
+ data["default"] = str(data.get("default", False)).lower()
+ base_param(
+ registry, xml_parent, data, True, "hudson.model.BooleanParameterDefinition"
+ )
def file_param(registry, xml_parent, data):
@@ -159,8 +166,9 @@ def file_param(registry, xml_parent, data):
name: test.txt
description: "Upload test.txt."
"""
- base_param(registry, xml_parent, data, False,
- 'hudson.model.FileParameterDefinition')
+ base_param(
+ registry, xml_parent, data, False, "hudson.model.FileParameterDefinition"
+ )
def text_param(registry, xml_parent, data):
@@ -179,8 +187,7 @@ def text_param(registry, xml_parent, data):
default: bar
description: "A parameter named FOO, defaults to 'bar'."
"""
- base_param(registry, xml_parent, data, True,
- 'hudson.model.TextParameterDefinition')
+ base_param(registry, xml_parent, data, True, "hudson.model.TextParameterDefinition")
def label_param(registry, xml_parent, data):
@@ -204,35 +211,41 @@ def label_param(registry, xml_parent, data):
"""
- pdef = base_param(registry, xml_parent, data, True,
- 'org.jvnet.jenkins.plugins.nodelabelparameter.'
- 'LabelParameterDefinition')
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ True,
+ "org.jvnet.jenkins.plugins.nodelabelparameter." "LabelParameterDefinition",
+ )
- valid_types = ['allCases', 'success', 'unstable']
+ valid_types = ["allCases", "success", "unstable"]
mapping = [
- ('all-nodes', 'allNodesMatchingLabel', False),
- ('matching-label', 'triggerIfResult', 'allCases', valid_types),
+ ("all-nodes", "allNodesMatchingLabel", False),
+ ("matching-label", "triggerIfResult", "allCases", valid_types),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
- eligibility_label = data.get('node-eligibility', 'all').lower()
+ eligibility_label = data.get("node-eligibility", "all").lower()
eligibility_label_dict = {
- 'all': 'org.jvnet.jenkins.plugins.'
- 'nodelabelparameter.node.'
- 'AllNodeEligibility',
- 'ignore-offline': 'org.jvnet.jenkins.plugins.'
- 'nodelabelparameter.node.'
- 'IgnoreOfflineNodeEligibility',
- 'ignore-temp-offline': 'org.jvnet.jenkins.plugins.'
- 'nodelabelparameter.node.'
- 'IgnoreTempOfflineNodeEligibility',
+ "all": "org.jvnet.jenkins.plugins."
+ "nodelabelparameter.node."
+ "AllNodeEligibility",
+ "ignore-offline": "org.jvnet.jenkins.plugins."
+ "nodelabelparameter.node."
+ "IgnoreOfflineNodeEligibility",
+ "ignore-temp-offline": "org.jvnet.jenkins.plugins."
+ "nodelabelparameter.node."
+ "IgnoreTempOfflineNodeEligibility",
}
if eligibility_label not in eligibility_label_dict:
- raise InvalidAttributeError(eligibility_label, eligibility_label,
- eligibility_label_dict.keys())
+ raise InvalidAttributeError(
+ eligibility_label, eligibility_label, eligibility_label_dict.keys()
+ )
- XML.SubElement(pdef, 'nodeEligibility').set(
- "class", eligibility_label_dict[eligibility_label])
+ XML.SubElement(pdef, "nodeEligibility").set(
+ "class", eligibility_label_dict[eligibility_label]
+ )
def node_param(registry, xml_parent, data):
@@ -263,30 +276,37 @@ def node_param(registry, xml_parent, data):
:language: yaml
"""
- pdef = base_param(registry, xml_parent, data, False,
- 'org.jvnet.jenkins.plugins.nodelabelparameter.'
- 'NodeParameterDefinition')
- default = XML.SubElement(pdef, 'defaultSlaves')
- if 'default-slaves' in data:
- for slave in data['default-slaves']:
- XML.SubElement(default, 'string').text = slave
- allowed = XML.SubElement(pdef, 'allowedSlaves')
- if 'allowed-slaves' in data:
- for slave in data['allowed-slaves']:
- XML.SubElement(allowed, 'string').text = slave
- XML.SubElement(pdef, 'ignoreOfflineNodes').text = str(
- data.get('ignore-offline-nodes', False)).lower()
-
- if data.get('allowed-multiselect', False):
- XML.SubElement(pdef, 'triggerIfResult').text = \
- 'allowMultiSelectionForConcurrentBuilds'
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "org.jvnet.jenkins.plugins.nodelabelparameter." "NodeParameterDefinition",
+ )
+ default = XML.SubElement(pdef, "defaultSlaves")
+ if "default-slaves" in data:
+ for slave in data["default-slaves"]:
+ XML.SubElement(default, "string").text = slave
+ allowed = XML.SubElement(pdef, "allowedSlaves")
+ if "allowed-slaves" in data:
+ for slave in data["allowed-slaves"]:
+ XML.SubElement(allowed, "string").text = slave
+ XML.SubElement(pdef, "ignoreOfflineNodes").text = str(
+ data.get("ignore-offline-nodes", False)
+ ).lower()
+
+ if data.get("allowed-multiselect", False):
+ XML.SubElement(
+ pdef, "triggerIfResult"
+ ).text = "allowMultiSelectionForConcurrentBuilds"
else:
- XML.SubElement(pdef, 'triggerIfResult').text = \
- 'multiSelectionDisallowed'
- XML.SubElement(pdef, 'allowMultiNodeSelection').text = str(
- data.get('allowed-multiselect', False)).lower()
- XML.SubElement(pdef, 'triggerConcurrentBuilds').text = str(
- data.get('allowed-multiselect', False)).lower()
+ XML.SubElement(pdef, "triggerIfResult").text = "multiSelectionDisallowed"
+ XML.SubElement(pdef, "allowMultiNodeSelection").text = str(
+ data.get("allowed-multiselect", False)
+ ).lower()
+ XML.SubElement(pdef, "triggerConcurrentBuilds").text = str(
+ data.get("allowed-multiselect", False)
+ ).lower()
def choice_param(registry, xml_parent, data):
@@ -307,13 +327,13 @@ def choice_param(registry, xml_parent, data):
- glance
description: "On which project to run?"
"""
- pdef = base_param(registry, xml_parent, data, False,
- 'hudson.model.ChoiceParameterDefinition')
- choices = XML.SubElement(pdef, 'choices',
- {'class': 'java.util.Arrays$ArrayList'})
- a = XML.SubElement(choices, 'a', {'class': 'string-array'})
- for choice in data['choices']:
- XML.SubElement(a, 'string').text = choice
+ pdef = base_param(
+ registry, xml_parent, data, False, "hudson.model.ChoiceParameterDefinition"
+ )
+ choices = XML.SubElement(pdef, "choices", {"class": "java.util.Arrays$ArrayList"})
+ a = XML.SubElement(choices, "a", {"class": "string-array"})
+ for choice in data["choices"]:
+ XML.SubElement(a, "string").text = choice
def credentials_param(registry, xml_parent, data):
@@ -345,30 +365,33 @@ def credentials_param(registry, xml_parent, data):
"""
cred_impl_types = {
- 'any': 'com.cloudbees.plugins.credentials.common.StandardCredentials',
- 'usernamepassword': 'com.cloudbees.plugins.credentials.impl.' +
- 'UsernamePasswordCredentialsImpl',
- 'sshkey': 'com.cloudbees.jenkins.plugins.sshcredentials.impl.' +
- 'BasicSSHUserPrivateKey',
- 'secretfile': 'org.jenkinsci.plugins.plaincredentials.impl.' +
- 'FileCredentialsImpl',
- 'secrettext': 'org.jenkinsci.plugins.plaincredentials.impl.' +
- 'StringCredentialsImpl',
- 'certificate': 'com.cloudbees.plugins.credentials.impl.' +
- 'CertificateCredentialsImpl'
+ "any": "com.cloudbees.plugins.credentials.common.StandardCredentials",
+ "usernamepassword": "com.cloudbees.plugins.credentials.impl."
+ + "UsernamePasswordCredentialsImpl",
+ "sshkey": "com.cloudbees.jenkins.plugins.sshcredentials.impl."
+ + "BasicSSHUserPrivateKey",
+ "secretfile": "org.jenkinsci.plugins.plaincredentials.impl."
+ + "FileCredentialsImpl",
+ "secrettext": "org.jenkinsci.plugins.plaincredentials.impl."
+ + "StringCredentialsImpl",
+ "certificate": "com.cloudbees.plugins.credentials.impl."
+ + "CertificateCredentialsImpl",
}
- cred_type = data.get('type', 'any').lower()
+ cred_type = data.get("type", "any").lower()
if cred_type not in cred_impl_types:
- raise InvalidAttributeError('type', cred_type, cred_impl_types.keys())
+ raise InvalidAttributeError("type", cred_type, cred_impl_types.keys())
- pdef = base_param(registry, xml_parent, data, False,
- 'com.cloudbees.plugins.credentials.' +
- 'CredentialsParameterDefinition')
- XML.SubElement(pdef, 'defaultValue').text = data.get('default', '')
- XML.SubElement(pdef, 'credentialType').text = cred_impl_types[cred_type]
- XML.SubElement(pdef, 'required').text = str(data.get('required',
- False)).lower()
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "com.cloudbees.plugins.credentials." + "CredentialsParameterDefinition",
+ )
+ XML.SubElement(pdef, "defaultValue").text = data.get("default", "")
+ XML.SubElement(pdef, "credentialType").text = cred_impl_types[cred_type]
+ XML.SubElement(pdef, "required").text = str(data.get("required", False)).lower()
def run_param(registry, xml_parent, data):
@@ -385,11 +408,10 @@ def run_param(registry, xml_parent, data):
:language: yaml
"""
- pdef = base_param(registry, xml_parent, data, False,
- 'hudson.model.RunParameterDefinition')
- mapping = [
- ('project-name', 'projectName', None),
- ]
+ pdef = base_param(
+ registry, xml_parent, data, False, "hudson.model.RunParameterDefinition"
+ )
+ mapping = [("project-name", "projectName", None)]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -456,43 +478,50 @@ def extended_choice_param(registry, xml_parent, data):
/../../tests/parameters/fixtures/extended-choice-param-full.yaml
:language: yaml
"""
- pdef = base_param(registry, xml_parent, data, False,
- 'com.cwctravel.hudson.plugins.'
- 'extended__choice__parameter.'
- 'ExtendedChoiceParameterDefinition')
-
- choicedict = {'single-select': 'PT_SINGLE_SELECT',
- 'multi-select': 'PT_MULTI_SELECT',
- 'radio': 'PT_RADIO',
- 'checkbox': 'PT_CHECKBOX',
- 'textbox': 'PT_TEXTBOX',
- 'PT_SINGLE_SELECT': 'PT_SINGLE_SELECT',
- 'PT_MULTI_SELECT': 'PT_MULTI_SELECT',
- 'PT_RADIO': 'PT_RADIO',
- 'PT_CHECKBOX': 'PT_CHECKBOX',
- 'PT_TEXTBOX': 'PT_TEXTBOX'}
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "com.cwctravel.hudson.plugins."
+ "extended__choice__parameter."
+ "ExtendedChoiceParameterDefinition",
+ )
+
+ choicedict = {
+ "single-select": "PT_SINGLE_SELECT",
+ "multi-select": "PT_MULTI_SELECT",
+ "radio": "PT_RADIO",
+ "checkbox": "PT_CHECKBOX",
+ "textbox": "PT_TEXTBOX",
+ "PT_SINGLE_SELECT": "PT_SINGLE_SELECT",
+ "PT_MULTI_SELECT": "PT_MULTI_SELECT",
+ "PT_RADIO": "PT_RADIO",
+ "PT_CHECKBOX": "PT_CHECKBOX",
+ "PT_TEXTBOX": "PT_TEXTBOX",
+ }
mapping = [
- ('value', 'value', ''),
- ('visible-items', 'visibleItemCount', 5),
- ('multi-select-delimiter', 'multiSelectDelimiter', ','),
- ('quote-value', 'quoteValue', False),
- ('default-value', 'defaultValue', ''),
- ('value-description', 'descriptionPropertyValue', ''),
- ('type', 'type', 'single-select', choicedict),
- ('property-file', 'propertyFile', ''),
- ('property-key', 'propertyKey', ''),
- ('default-property-file', 'defaultPropertyFile', ''),
- ('default-property-key', 'defaultPropertyKey', ''),
- ('description-property-file', 'descriptionPropertyFile', ''),
- ('description-property-key', 'descriptionPropertyKey', ''),
- ('bindings', 'bindings', ''),
- ('groovy-script', 'groovyScript', ''),
- ('groovy-script-file', 'groovyScriptFile', ''),
- ('classpath', 'groovyClasspath', ''),
- ('default-groovy-script', 'defaultGroovyScript', ''),
- ('default-groovy-classpath', 'defaultGroovyClasspath', ''),
- ('description-groovy-script', 'descriptionGroovyScript', ''),
- ('description-groovy-classpath', 'descriptionGroovyClasspath', ''),
+ ("value", "value", ""),
+ ("visible-items", "visibleItemCount", 5),
+ ("multi-select-delimiter", "multiSelectDelimiter", ","),
+ ("quote-value", "quoteValue", False),
+ ("default-value", "defaultValue", ""),
+ ("value-description", "descriptionPropertyValue", ""),
+ ("type", "type", "single-select", choicedict),
+ ("property-file", "propertyFile", ""),
+ ("property-key", "propertyKey", ""),
+ ("default-property-file", "defaultPropertyFile", ""),
+ ("default-property-key", "defaultPropertyKey", ""),
+ ("description-property-file", "descriptionPropertyFile", ""),
+ ("description-property-key", "descriptionPropertyKey", ""),
+ ("bindings", "bindings", ""),
+ ("groovy-script", "groovyScript", ""),
+ ("groovy-script-file", "groovyScriptFile", ""),
+ ("classpath", "groovyClasspath", ""),
+ ("default-groovy-script", "defaultGroovyScript", ""),
+ ("default-groovy-classpath", "defaultGroovyClasspath", ""),
+ ("description-groovy-script", "descriptionGroovyScript", ""),
+ ("description-groovy-classpath", "descriptionGroovyClasspath", ""),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -519,13 +548,15 @@ def validating_string_param(registry, xml_parent, data):
regex: [A-Za-z]*
msg: Your entered value failed validation
"""
- pdef = base_param(registry, xml_parent, data, True,
- 'hudson.plugins.validating__string__parameter.'
- 'ValidatingStringParameterDefinition')
- mapping = [
- ('regex', 'regex', None),
- ('msg', 'failedValidationMessage', None),
- ]
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ True,
+ "hudson.plugins.validating__string__parameter."
+ "ValidatingStringParameterDefinition",
+ )
+ mapping = [("regex", "regex", None), ("msg", "failedValidationMessage", None)]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -557,17 +588,21 @@ def svn_tags_param(registry, xml_parent, data):
url: http://svn.example.com/repo
filter: [A-za-z0-9]*
"""
- pdef = base_param(registry, xml_parent, data, True,
- 'hudson.scm.listtagsparameter.'
- 'ListSubversionTagsParameterDefinition')
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ True,
+ "hudson.scm.listtagsparameter." "ListSubversionTagsParameterDefinition",
+ )
mapping = [
- ('url', 'tagsDir', None),
- ('credentials-id', 'credentialsId', ''),
- ('filter', 'tagsFilter', ''),
- ('max-tags', 'maxTags', '100'),
- ('sort-newest-first', 'reverseByDate', True),
- ('sort-z-to-a', 'reverseByName', False),
- ('', 'uuid', "1-1-1-1-1"),
+ ("url", "tagsDir", None),
+ ("credentials-id", "credentialsId", ""),
+ ("filter", "tagsFilter", ""),
+ ("max-tags", "maxTags", "100"),
+ ("sort-newest-first", "reverseByDate", True),
+ ("sort-z-to-a", "reverseByName", False),
+ ("", "uuid", "1-1-1-1-1"),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -597,8 +632,7 @@ def dynamic_choice_param(registry, xml_parent, data):
remote: false
read-only: false
"""
- dynamic_param_common(registry, xml_parent, data,
- 'ChoiceParameterDefinition')
+ dynamic_param_common(registry, xml_parent, data, "ChoiceParameterDefinition")
def dynamic_string_param(registry, xml_parent, data):
@@ -626,8 +660,7 @@ def dynamic_string_param(registry, xml_parent, data):
remote: false
read-only: false
"""
- dynamic_param_common(registry, xml_parent, data,
- 'StringParameterDefinition')
+ dynamic_param_common(registry, xml_parent, data, "StringParameterDefinition")
def dynamic_choice_scriptler_param(registry, xml_parent, data):
@@ -663,8 +696,9 @@ def dynamic_choice_scriptler_param(registry, xml_parent, data):
remote: false
read-only: false
"""
- dynamic_scriptler_param_common(registry, xml_parent, data,
- 'ScriptlerChoiceParameterDefinition')
+ dynamic_scriptler_param_common(
+ registry, xml_parent, data, "ScriptlerChoiceParameterDefinition"
+ )
def dynamic_string_scriptler_param(registry, xml_parent, data):
@@ -700,54 +734,64 @@ def dynamic_string_scriptler_param(registry, xml_parent, data):
remote: false
read-only: false
"""
- dynamic_scriptler_param_common(registry, xml_parent, data,
- 'ScriptlerStringParameterDefinition')
+ dynamic_scriptler_param_common(
+ registry, xml_parent, data, "ScriptlerStringParameterDefinition"
+ )
def dynamic_param_common(registry, xml_parent, data, ptype):
- pdef = base_param(registry, xml_parent, data, False,
- 'com.seitenbau.jenkins.plugins.dynamicparameter.' +
- ptype)
- XML.SubElement(pdef, '__remote').text = str(
- data.get('remote', False)).lower()
- XML.SubElement(pdef, '__script').text = data.get('script', None)
- localBaseDir = XML.SubElement(pdef, '__localBaseDirectory',
- {'serialization': 'custom'})
- filePath = XML.SubElement(localBaseDir, 'hudson.FilePath')
- default = XML.SubElement(filePath, 'default')
- XML.SubElement(filePath, 'boolean').text = "true"
- XML.SubElement(default, 'remote').text = \
- "/var/lib/jenkins/dynamic_parameter/classpath"
- XML.SubElement(pdef, '__remoteBaseDirectory').text = \
- "dynamic_parameter_classpath"
- XML.SubElement(pdef, '__classPath').text = data.get('classpath', None)
- XML.SubElement(pdef, 'readonlyInputField').text = str(
- data.get('read-only', False)).lower()
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "com.seitenbau.jenkins.plugins.dynamicparameter." + ptype,
+ )
+ XML.SubElement(pdef, "__remote").text = str(data.get("remote", False)).lower()
+ XML.SubElement(pdef, "__script").text = data.get("script", None)
+ localBaseDir = XML.SubElement(
+ pdef, "__localBaseDirectory", {"serialization": "custom"}
+ )
+ filePath = XML.SubElement(localBaseDir, "hudson.FilePath")
+ default = XML.SubElement(filePath, "default")
+ XML.SubElement(filePath, "boolean").text = "true"
+ XML.SubElement(
+ default, "remote"
+ ).text = "/var/lib/jenkins/dynamic_parameter/classpath"
+ XML.SubElement(pdef, "__remoteBaseDirectory").text = "dynamic_parameter_classpath"
+ XML.SubElement(pdef, "__classPath").text = data.get("classpath", None)
+ XML.SubElement(pdef, "readonlyInputField").text = str(
+ data.get("read-only", False)
+ ).lower()
def dynamic_scriptler_param_common(registry, xml_parent, data, ptype):
- pdef = base_param(registry, xml_parent, data, False,
- 'com.seitenbau.jenkins.plugins.dynamicparameter.'
- 'scriptler.' + ptype)
- parametersXML = XML.SubElement(pdef, '__parameters')
- parameters = data.get('parameters', [])
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "com.seitenbau.jenkins.plugins.dynamicparameter." "scriptler." + ptype,
+ )
+ parametersXML = XML.SubElement(pdef, "__parameters")
+ parameters = data.get("parameters", [])
if parameters:
- mapping = [
- ('name', 'name', None),
- ('value', 'value', None),
- ]
+ mapping = [("name", "name", None), ("value", "value", None)]
for parameter in parameters:
- parameterXML = XML.SubElement(parametersXML,
- 'com.seitenbau.jenkins.plugins.'
- 'dynamicparameter.scriptler.'
- 'ScriptlerParameterDefinition_'
- '-ScriptParameter')
+ parameterXML = XML.SubElement(
+ parametersXML,
+ "com.seitenbau.jenkins.plugins."
+ "dynamicparameter.scriptler."
+ "ScriptlerParameterDefinition_"
+ "-ScriptParameter",
+ )
helpers.convert_mapping_to_xml(
- parameterXML, parameter, mapping, fail_required=True)
+ parameterXML, parameter, mapping, fail_required=True
+ )
mapping = [
- ('script-id', '__scriptlerScriptId', None),
- ('remote', '__remote', False),
- ('read-only', 'readonlyInputField', False),
+ ("script-id", "__scriptlerScriptId", None),
+ ("remote", "__remote", False),
+ ("read-only", "readonlyInputField", False),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -770,14 +814,16 @@ def matrix_combinations_param(registry, xml_parent, data):
:language: yaml
"""
- element_name = 'hudson.plugins.matrix__configuration__parameter.' \
- 'MatrixCombinationsParameterDefinition'
+ element_name = (
+ "hudson.plugins.matrix__configuration__parameter."
+ "MatrixCombinationsParameterDefinition"
+ )
pdef = XML.SubElement(xml_parent, element_name)
mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ('filter', 'defaultCombinationFilter', ''),
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("filter", "defaultCombinationFilter", ""),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -806,15 +852,13 @@ def copyartifact_build_selector_param(registry, xml_parent, data):
"""
- t = XML.SubElement(xml_parent, 'hudson.plugins.copyartifact.'
- 'BuildSelectorParameter')
- mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ]
+ t = XML.SubElement(
+ xml_parent, "hudson.plugins.copyartifact." "BuildSelectorParameter"
+ )
+ mapping = [("name", "name", None), ("description", "description", "")]
helpers.convert_mapping_to_xml(t, data, mapping, fail_required=True)
- helpers.copyartifact_build_selector(t, data, 'defaultSelector')
+ helpers.copyartifact_build_selector(t, data, "defaultSelector")
def maven_metadata_param(registry, xml_parent, data):
@@ -855,31 +899,34 @@ def maven_metadata_param(registry, xml_parent, data):
:language: yaml
"""
- pdef = base_param(registry, xml_parent, data, False,
- 'eu.markov.jenkins.plugin.mvnmeta.'
- 'MavenMetadataParameterDefinition')
+ pdef = base_param(
+ registry,
+ xml_parent,
+ data,
+ False,
+ "eu.markov.jenkins.plugin.mvnmeta." "MavenMetadataParameterDefinition",
+ )
mapping = [
- ('repository-base-url', 'repoBaseUrl', ''),
- ('artifact-group-id', 'groupId', ''),
- ('artifact-id', 'artifactId', ''),
- ('packaging', 'packaging', ''),
- ('default-value', 'defaultValue', ''),
- ('versions-filter', 'versionFilter', ''),
+ ("repository-base-url", "repoBaseUrl", ""),
+ ("artifact-group-id", "groupId", ""),
+ ("artifact-id", "artifactId", ""),
+ ("packaging", "packaging", ""),
+ ("default-value", "defaultValue", ""),
+ ("versions-filter", "versionFilter", ""),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
- sort_order = data.get('sorting-order', 'descending').lower()
- sort_dict = {'descending': 'DESC',
- 'ascending': 'ASC'}
+ sort_order = data.get("sorting-order", "descending").lower()
+ sort_dict = {"descending": "DESC", "ascending": "ASC"}
if sort_order not in sort_dict:
raise InvalidAttributeError(sort_order, sort_order, sort_dict.keys())
- XML.SubElement(pdef, 'sortOrder').text = sort_dict[sort_order]
+ XML.SubElement(pdef, "sortOrder").text = sort_dict[sort_order]
mapping = [
- ('maximum-versions-to-display', 'maxVersions', 10),
- ('repository-username', 'username', ''),
- ('repository-password', 'password', ''),
+ ("maximum-versions-to-display", "maxVersions", 10),
+ ("repository-username", "username", ""),
+ ("repository-password", "password", ""),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -901,8 +948,9 @@ def hidden_param(parser, xml_parent, data):
:language: yaml
"""
- base_param(parser, xml_parent, data, True,
- 'com.wangyin.parameter.WHideParameterDefinition')
+ base_param(
+ parser, xml_parent, data, True, "com.wangyin.parameter.WHideParameterDefinition"
+ )
def random_string_param(registry, xml_parent, data):
@@ -923,16 +971,17 @@ def random_string_param(registry, xml_parent, data):
/../../tests/parameters/fixtures/random-string-param001.yaml
:language: yaml
"""
- pdef = XML.SubElement(xml_parent,
- 'hudson.plugins.random__string__parameter.'
- 'RandomStringParameterDefinition')
- if 'name' not in data:
- raise JenkinsJobsException('random-string must have a name parameter.')
+ pdef = XML.SubElement(
+ xml_parent,
+ "hudson.plugins.random__string__parameter." "RandomStringParameterDefinition",
+ )
+ if "name" not in data:
+ raise JenkinsJobsException("random-string must have a name parameter.")
mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ('failed-validation-message', 'failedValidationMessage', ''),
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("failed-validation-message", "failedValidationMessage", ""),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -1005,40 +1054,41 @@ def git_parameter_param(registry, xml_parent, data):
/../../tests/parameters/fixtures/git-parameter-param-full.yaml
:language: yaml
"""
- pdef = XML.SubElement(xml_parent,
- 'net.uaznia.lukanus.hudson.plugins.gitparameter.'
- 'GitParameterDefinition')
+ pdef = XML.SubElement(
+ xml_parent,
+ "net.uaznia.lukanus.hudson.plugins.gitparameter." "GitParameterDefinition",
+ )
valid_types = [
- 'PT_TAG',
- 'PT_BRANCH',
- 'PT_BRANCH_TAG',
- 'PT_REVISION',
- 'PT_PULL_REQUEST',
+ "PT_TAG",
+ "PT_BRANCH",
+ "PT_BRANCH_TAG",
+ "PT_REVISION",
+ "PT_PULL_REQUEST",
]
valid_sort_modes = [
- 'NONE',
- 'ASCENDING',
- 'ASCENDING_SMART',
- 'DESCENDING',
- 'DESCENDING_SMART',
+ "NONE",
+ "ASCENDING",
+ "ASCENDING_SMART",
+ "DESCENDING",
+ "DESCENDING_SMART",
]
- valid_selected_values = ['NONE', 'TOP', 'DEFAULT']
+ valid_selected_values = ["NONE", "TOP", "DEFAULT"]
mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ('type', 'type', 'PT_TAG', valid_types),
- ('branch', 'branch', ''),
- ('tagFilter', 'tagFilter', '*'),
- ('branchFilter', 'branchFilter', '.*'),
- ('sortMode', 'sortMode', 'NONE', valid_sort_modes),
- ('defaultValue', 'defaultValue', ''),
- ('selectedValue', 'selectedValue', 'NONE', valid_selected_values),
- ('useRepository', 'useRepository', ''),
- ('quickFilterEnabled', 'quickFilterEnabled', False),
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("type", "type", "PT_TAG", valid_types),
+ ("branch", "branch", ""),
+ ("tagFilter", "tagFilter", "*"),
+ ("branchFilter", "branchFilter", ".*"),
+ ("sortMode", "sortMode", "NONE", valid_sort_modes),
+ ("defaultValue", "defaultValue", ""),
+ ("selectedValue", "selectedValue", "NONE", valid_selected_values),
+ ("useRepository", "useRepository", ""),
+ ("quickFilterEnabled", "quickFilterEnabled", False),
]
helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True)
@@ -1046,28 +1096,29 @@ def git_parameter_param(registry, xml_parent, data):
class Parameters(jenkins_jobs.modules.base.Base):
sequence = 21
- component_type = 'parameter'
- component_list_type = 'parameters'
+ component_type = "parameter"
+ component_list_type = "parameters"
def gen_xml(self, xml_parent, data):
- properties = xml_parent.find('properties')
+ properties = xml_parent.find("properties")
if properties is None:
- properties = XML.SubElement(xml_parent, 'properties')
+ properties = XML.SubElement(xml_parent, "properties")
- parameters = data.get('parameters', [])
- hmodel = 'hudson.model.'
+ parameters = data.get("parameters", [])
+ hmodel = "hudson.model."
if parameters:
# The conditionals here are to work around the extended_choice
# parameter also being definable in the properties module. This
# usage has been deprecated but not removed. Because it may have
# added these elements before us, we need to check if they already
# exist, and only add them if they're missing.
- pdefp = properties.find(hmodel + 'ParametersDefinitionProperty')
+ pdefp = properties.find(hmodel + "ParametersDefinitionProperty")
if pdefp is None:
- pdefp = XML.SubElement(properties,
- hmodel + 'ParametersDefinitionProperty')
- pdefs = pdefp.find('parameterDefinitions')
+ pdefp = XML.SubElement(
+ properties, hmodel + "ParametersDefinitionProperty"
+ )
+ pdefs = pdefp.find("parameterDefinitions")
if pdefs is None:
- pdefs = XML.SubElement(pdefp, 'parameterDefinitions')
+ pdefs = XML.SubElement(pdefp, "parameterDefinitions")
for param in parameters:
- self.registry.dispatch('parameter', pdefs, param)
+ self.registry.dispatch("parameter", pdefs, param)
diff --git a/jenkins_jobs/modules/project_externaljob.py b/jenkins_jobs/modules/project_externaljob.py
index 8839c260..c6c7c490 100644
--- a/jenkins_jobs/modules/project_externaljob.py
+++ b/jenkins_jobs/modules/project_externaljob.py
@@ -40,5 +40,5 @@ class ExternalJob(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- xml_parent = XML.Element('hudson.model.ExternalJob')
+ xml_parent = XML.Element("hudson.model.ExternalJob")
return xml_parent
diff --git a/jenkins_jobs/modules/project_flow.py b/jenkins_jobs/modules/project_flow.py
index d9bb4e2e..2033c01f 100644
--- a/jenkins_jobs/modules/project_flow.py
+++ b/jenkins_jobs/modules/project_flow.py
@@ -59,15 +59,15 @@ class Flow(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- xml_parent = XML.Element('com.cloudbees.plugins.flow.BuildFlow')
+ xml_parent = XML.Element("com.cloudbees.plugins.flow.BuildFlow")
- needs_workspace = data.get('needs-workspace', False)
+ needs_workspace = data.get("needs-workspace", False)
mapping = [
- ('dsl', 'dsl', ''),
- ('needs-workspace', 'buildNeedsWorkspace', False),
+ ("dsl", "dsl", ""),
+ ("needs-workspace", "buildNeedsWorkspace", False),
]
convert_mapping_to_xml(xml_parent, data, mapping, fail_required=True)
- if needs_workspace and 'dsl-file' in data:
- XML.SubElement(xml_parent, 'dslFile').text = data['dsl-file']
+ if needs_workspace and "dsl-file" in data:
+ XML.SubElement(xml_parent, "dslFile").text = data["dsl-file"]
return xml_parent
diff --git a/jenkins_jobs/modules/project_folder.py b/jenkins_jobs/modules/project_folder.py
index a16a1215..b88db566 100644
--- a/jenkins_jobs/modules/project_folder.py
+++ b/jenkins_jobs/modules/project_folder.py
@@ -43,19 +43,18 @@ class Folder(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- xml_parent = XML.Element('com.cloudbees.hudson.plugins.folder.Folder',
- plugin="cloudbees-folder")
- attributes = {"class": "com.cloudbees.hudson.plugins.folder."
- "icons.StockFolderIcon"}
- XML.SubElement(xml_parent, 'icon', attrib=attributes)
- XML.SubElement(xml_parent, 'views')
+ xml_parent = XML.Element(
+ "com.cloudbees.hudson.plugins.folder.Folder", plugin="cloudbees-folder"
+ )
+ attributes = {
+ "class": "com.cloudbees.hudson.plugins.folder." "icons.StockFolderIcon"
+ }
+ XML.SubElement(xml_parent, "icon", attrib=attributes)
+ XML.SubElement(xml_parent, "views")
attributes = {"class": "hudson.views.DefaultViewsTabBar"}
- XML.SubElement(xml_parent, 'viewsTabBar', attrib=attributes)
+ XML.SubElement(xml_parent, "viewsTabBar", attrib=attributes)
- mappings = [
- ('', 'primaryView', 'All'),
- ('', 'healthMetrics', ''),
- ]
+ mappings = [("", "primaryView", "All"), ("", "healthMetrics", "")]
convert_mapping_to_xml(xml_parent, data, mappings, True)
return xml_parent
diff --git a/jenkins_jobs/modules/project_freestyle.py b/jenkins_jobs/modules/project_freestyle.py
index cdc133d8..63f9af4e 100644
--- a/jenkins_jobs/modules/project_freestyle.py
+++ b/jenkins_jobs/modules/project_freestyle.py
@@ -36,5 +36,5 @@ class Freestyle(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- xml_parent = XML.Element('project')
+ xml_parent = XML.Element("project")
return xml_parent
diff --git a/jenkins_jobs/modules/project_matrix.py b/jenkins_jobs/modules/project_matrix.py
index 13c67721..f092279b 100644
--- a/jenkins_jobs/modules/project_matrix.py
+++ b/jenkins_jobs/modules/project_matrix.py
@@ -113,139 +113,144 @@ class Matrix(jenkins_jobs.modules.base.Base):
# List the supported Axis names in our configuration
# and map them to the Jenkins XML element name.
supported_axis = {
- 'label-expression': 'hudson.matrix.LabelExpAxis',
- 'user-defined': 'hudson.matrix.TextAxis',
- 'slave': 'hudson.matrix.LabelAxis',
- 'jdk': 'hudson.matrix.JDKAxis',
- 'dynamic': 'ca.silvermaplesolutions.jenkins.plugins.daxis.DynamicAxis',
- 'python': 'jenkins.plugins.shiningpanda.matrix.PythonAxis',
- 'tox': 'jenkins.plugins.shiningpanda.matrix.ToxAxis',
- 'groovy': 'org.jenkinsci.plugins.GroovyAxis',
- 'yaml': 'org.jenkinsci.plugins.yamlaxis.YamlAxis',
+ "label-expression": "hudson.matrix.LabelExpAxis",
+ "user-defined": "hudson.matrix.TextAxis",
+ "slave": "hudson.matrix.LabelAxis",
+ "jdk": "hudson.matrix.JDKAxis",
+ "dynamic": "ca.silvermaplesolutions.jenkins.plugins.daxis.DynamicAxis",
+ "python": "jenkins.plugins.shiningpanda.matrix.PythonAxis",
+ "tox": "jenkins.plugins.shiningpanda.matrix.ToxAxis",
+ "groovy": "org.jenkinsci.plugins.GroovyAxis",
+ "yaml": "org.jenkinsci.plugins.yamlaxis.YamlAxis",
}
supported_strategies = {
# Jenkins built-in, default
- 'execution-strategy':
- 'hudson.matrix.DefaultMatrixExecutionStrategyImpl',
- 'yaml-strategy':
- 'org.jenkinsci.plugins.yamlaxis.YamlMatrixExecutionStrategy',
- 'p4-strategy':
- 'org.jenkinsci.plugins.p4.matrix.MatrixOptions'
+ "execution-strategy": "hudson.matrix.DefaultMatrixExecutionStrategyImpl",
+ "yaml-strategy": "org.jenkinsci.plugins.yamlaxis.YamlMatrixExecutionStrategy",
+ "p4-strategy": "org.jenkinsci.plugins.p4.matrix.MatrixOptions",
}
def root_xml(self, data):
- root = XML.Element('matrix-project')
+ root = XML.Element("matrix-project")
# Default to 'execution-strategy'
- strategies = ([s for s in data.keys() if s.endswith('-strategy')] or
- ['execution-strategy'])
+ strategies = [s for s in data.keys() if s.endswith("-strategy")] or [
+ "execution-strategy"
+ ]
# Job can not have multiple strategies
if len(strategies) > 1:
raise ValueError(
- 'matrix-project does not support multiple strategies. '
- 'Given %s: %s' % (len(strategies), ', '.join(strategies)))
+ "matrix-project does not support multiple strategies. "
+ "Given %s: %s" % (len(strategies), ", ".join(strategies))
+ )
strategy_name = strategies[0]
if strategy_name not in self.supported_strategies:
raise ValueError(
- 'Given strategy %s. Only %s strategies are supported'
- % (strategy_name, self.supported_strategies.keys()))
+ "Given strategy %s. Only %s strategies are supported"
+ % (strategy_name, self.supported_strategies.keys())
+ )
ex_r = XML.SubElement(
- root, 'executionStrategy',
- {'class': self.supported_strategies[strategy_name]})
+ root,
+ "executionStrategy",
+ {"class": self.supported_strategies[strategy_name]},
+ )
strategy = data.get(strategy_name, {})
- if strategy_name == 'execution-strategy':
- XML.SubElement(root, 'combinationFilter').text = (
- str(strategy.get('combination-filter', '')).rstrip()
- )
- XML.SubElement(ex_r, 'runSequentially').text = (
- str(strategy.get('sequential', False)).lower()
- )
- if 'touchstone' in strategy:
- XML.SubElement(ex_r, 'touchStoneCombinationFilter').text = (
- str(strategy['touchstone'].get('expr', ''))
+ if strategy_name == "execution-strategy":
+ XML.SubElement(root, "combinationFilter").text = str(
+ strategy.get("combination-filter", "")
+ ).rstrip()
+ XML.SubElement(ex_r, "runSequentially").text = str(
+ strategy.get("sequential", False)
+ ).lower()
+ if "touchstone" in strategy:
+ XML.SubElement(ex_r, "touchStoneCombinationFilter").text = str(
+ strategy["touchstone"].get("expr", "")
)
- threshold = strategy['touchstone'].get(
- 'result', 'stable').upper()
- supported_thresholds = ('STABLE', 'UNSTABLE')
+ threshold = strategy["touchstone"].get("result", "stable").upper()
+ supported_thresholds = ("STABLE", "UNSTABLE")
if threshold not in supported_thresholds:
raise InvalidAttributeError(
- 'touchstone', threshold, supported_thresholds)
+ "touchstone", threshold, supported_thresholds
+ )
# Web ui uses Stable but hudson.model.Result has Success
- if threshold == 'STABLE':
- threshold = 'SUCCESS'
+ if threshold == "STABLE":
+ threshold = "SUCCESS"
- t_r = XML.SubElement(ex_r, 'touchStoneResultCondition')
- for sub_elem in ('name', 'ordinal', 'color'):
- XML.SubElement(t_r, sub_elem).text = (
- hudson_model.THRESHOLDS[threshold][sub_elem])
+ t_r = XML.SubElement(ex_r, "touchStoneResultCondition")
+ for sub_elem in ("name", "ordinal", "color"):
+ XML.SubElement(t_r, sub_elem).text = hudson_model.THRESHOLDS[
+ threshold
+ ][sub_elem]
- elif strategy_name == 'yaml-strategy':
- filename = str(strategy.get('filename', ''))
- text = str(strategy.get('text', ''))
- exclude_key = str(strategy.get('exclude-key', ''))
+ elif strategy_name == "yaml-strategy":
+ filename = str(strategy.get("filename", ""))
+ text = str(strategy.get("text", ""))
+ exclude_key = str(strategy.get("exclude-key", ""))
if bool(filename) == bool(text): # xor with str
- raise ValueError('yaml-strategy must be given '
- 'either "filename" or "text"')
+ raise ValueError(
+ "yaml-strategy must be given " 'either "filename" or "text"'
+ )
- yamlType = (filename and 'file') or (text and 'text')
- XML.SubElement(ex_r, 'yamlType').text = yamlType
+ yamlType = (filename and "file") or (text and "text")
+ XML.SubElement(ex_r, "yamlType").text = yamlType
- XML.SubElement(ex_r, 'yamlFile').text = filename
- XML.SubElement(ex_r, 'yamlText').text = text
+ XML.SubElement(ex_r, "yamlFile").text = filename
+ XML.SubElement(ex_r, "yamlText").text = text
- XML.SubElement(ex_r, 'excludeKey').text = exclude_key
+ XML.SubElement(ex_r, "excludeKey").text = exclude_key
- elif strategy_name == 'p4-strategy':
- XML.SubElement(ex_r, 'runSequentially').text = (
- str(strategy.get('sequential', False)).lower()
- )
+ elif strategy_name == "p4-strategy":
+ XML.SubElement(ex_r, "runSequentially").text = str(
+ strategy.get("sequential", False)
+ ).lower()
- XML.SubElement(ex_r, 'buildParent').text = (
- str(strategy.get('build-parent', False)).lower()
- )
+ XML.SubElement(ex_r, "buildParent").text = str(
+ strategy.get("build-parent", False)
+ ).lower()
- ax_root = XML.SubElement(root, 'axes')
- for axis_ in data.get('axes', []):
- axis = axis_['axis']
- axis_type = axis['type']
+ ax_root = XML.SubElement(root, "axes")
+ for axis_ in data.get("axes", []):
+ axis = axis_["axis"]
+ axis_type = axis["type"]
if axis_type not in self.supported_axis:
- raise ValueError('Only %s axes types are supported'
- % self.supported_axis.keys())
+ raise ValueError(
+ "Only %s axes types are supported" % self.supported_axis.keys()
+ )
axis_name = self.supported_axis.get(axis_type)
lbl_root = XML.SubElement(ax_root, axis_name)
- name, values = axis.get('name', ''), axis.get('values', [''])
- if axis_type == 'jdk':
- XML.SubElement(lbl_root, 'name').text = 'jdk'
- elif axis_type == 'python':
- XML.SubElement(lbl_root, 'name').text = 'PYTHON'
- elif axis_type == 'tox':
- XML.SubElement(lbl_root, 'name').text = 'TOXENV'
+ name, values = axis.get("name", ""), axis.get("values", [""])
+ if axis_type == "jdk":
+ XML.SubElement(lbl_root, "name").text = "jdk"
+ elif axis_type == "python":
+ XML.SubElement(lbl_root, "name").text = "PYTHON"
+ elif axis_type == "tox":
+ XML.SubElement(lbl_root, "name").text = "TOXENV"
else:
- XML.SubElement(lbl_root, 'name').text = str(name)
+ XML.SubElement(lbl_root, "name").text = str(name)
if axis_type != "groovy":
- v_root = XML.SubElement(lbl_root, 'values')
+ v_root = XML.SubElement(lbl_root, "values")
if axis_type == "dynamic":
- XML.SubElement(v_root, 'string').text = str(values[0])
- XML.SubElement(lbl_root, 'varName').text = str(values[0])
- v_root = XML.SubElement(lbl_root, 'axisValues')
- XML.SubElement(v_root, 'string').text = 'default'
+ XML.SubElement(v_root, "string").text = str(values[0])
+ XML.SubElement(lbl_root, "varName").text = str(values[0])
+ v_root = XML.SubElement(lbl_root, "axisValues")
+ XML.SubElement(v_root, "string").text = "default"
elif axis_type == "groovy":
- command = XML.SubElement(lbl_root, 'groovyString')
- command.text = axis.get('command')
- XML.SubElement(lbl_root, 'computedValues').text = ''
+ command = XML.SubElement(lbl_root, "groovyString")
+ command.text = axis.get("command")
+ XML.SubElement(lbl_root, "computedValues").text = ""
elif axis_type == "yaml":
- XML.SubElement(v_root, 'string').text = axis.get('filename')
+ XML.SubElement(v_root, "string").text = axis.get("filename")
else:
for v in values:
- XML.SubElement(v_root, 'string').text = str(v)
+ XML.SubElement(v_root, "string").text = str(v)
return root
diff --git a/jenkins_jobs/modules/project_maven.py b/jenkins_jobs/modules/project_maven.py
index 3e735688..719b1d2d 100755
--- a/jenkins_jobs/modules/project_maven.py
+++ b/jenkins_jobs/modules/project_maven.py
@@ -95,93 +95,109 @@ class Maven(jenkins_jobs.modules.base.Base):
sequence = 0
choices_private_repo = {
- 'default':
- 'hudson.maven.local_repo.DefaultLocalRepositoryLocator',
- 'local-to-workspace':
- 'hudson.maven.local_repo.PerJobLocalRepositoryLocator',
- 'local-to-executor':
- 'hudson.maven.local_repo.PerExecutorLocalRepositoryLocator',
+ "default": "hudson.maven.local_repo.DefaultLocalRepositoryLocator",
+ "local-to-workspace": "hudson.maven.local_repo.PerJobLocalRepositoryLocator",
+ "local-to-executor": "hudson.maven.local_repo.PerExecutorLocalRepositoryLocator",
}
def root_xml(self, data):
- xml_parent = XML.Element('maven2-moduleset')
- if 'maven' not in data:
+ xml_parent = XML.Element("maven2-moduleset")
+ if "maven" not in data:
return xml_parent
# determine version of plugin
plugin_info = self.registry.get_plugin_info("Maven Integration plugin")
- version = pkg_resources.parse_version(plugin_info.get('version', '0'))
-
- if 'root-module' in data['maven']:
- root_module = XML.SubElement(xml_parent, 'rootModule')
- XML.SubElement(root_module, 'groupId').text = \
- data['maven']['root-module']['group-id']
- XML.SubElement(root_module, 'artifactId').text = \
- data['maven']['root-module']['artifact-id']
- XML.SubElement(xml_parent, 'goals').text = data['maven']['goals']
-
- maven_opts = data['maven'].get('maven-opts')
+ version = pkg_resources.parse_version(plugin_info.get("version", "0"))
+
+ if "root-module" in data["maven"]:
+ root_module = XML.SubElement(xml_parent, "rootModule")
+ XML.SubElement(root_module, "groupId").text = data["maven"]["root-module"][
+ "group-id"
+ ]
+ XML.SubElement(root_module, "artifactId").text = data["maven"][
+ "root-module"
+ ]["artifact-id"]
+ XML.SubElement(xml_parent, "goals").text = data["maven"]["goals"]
+
+ maven_opts = data["maven"].get("maven-opts")
if maven_opts:
- XML.SubElement(xml_parent, 'mavenOpts').text = maven_opts
+ XML.SubElement(xml_parent, "mavenOpts").text = maven_opts
- maven_name = data['maven'].get('maven-name')
+ maven_name = data["maven"].get("maven-name")
if maven_name:
- XML.SubElement(xml_parent, 'mavenName').text = maven_name
+ XML.SubElement(xml_parent, "mavenName").text = maven_name
- private_repo = data['maven'].get('private-repository')
+ private_repo = data["maven"].get("private-repository")
if private_repo:
if private_repo not in self.choices_private_repo.keys():
- raise ValueError('Not a valid private-repository "%s", '
- 'must be one of "%s"' %
- (private_repo,
- ", ".join(self.choices_private_repo.keys())))
- XML.SubElement(xml_parent,
- 'localRepository',
- attrib={'class':
- self.choices_private_repo[private_repo]})
-
- XML.SubElement(xml_parent, 'ignoreUpstremChanges').text = str(
- data['maven'].get('ignore-upstream-changes', True)).lower()
-
- XML.SubElement(xml_parent, 'rootPOM').text = \
- data['maven'].get('root-pom', 'pom.xml')
- XML.SubElement(xml_parent, 'aggregatorStyleBuild').text = str(
- not data['maven'].get('parallel-build-modules', False)).lower()
- XML.SubElement(xml_parent, 'incrementalBuild').text = str(
- data['maven'].get('incremental-build', False)).lower()
- XML.SubElement(xml_parent, 'siteArchivingDisabled').text = str(
- not data['maven'].get('automatic-site-archiving', True)).lower()
- XML.SubElement(xml_parent, 'fingerprintingDisabled').text = str(
- not data['maven'].get('automatic-fingerprinting', True)).lower()
- if (version > pkg_resources.parse_version('0') and
- version < pkg_resources.parse_version('2.0.1')):
- XML.SubElement(xml_parent, 'perModuleEmail').text = str(
- data.get('per-module-email', True)).lower()
- XML.SubElement(xml_parent, 'archivingDisabled').text = str(
- not data['maven'].get('automatic-archiving', True)).lower()
- XML.SubElement(xml_parent, 'resolveDependencies').text = str(
- data['maven'].get('resolve-dependencies', False)).lower()
- XML.SubElement(xml_parent, 'processPlugins').text = str(
- data['maven'].get('process-plugins', False)).lower()
- XML.SubElement(xml_parent, 'mavenValidationLevel').text = '-1'
- XML.SubElement(xml_parent, 'runHeadless').text = str(
- data['maven'].get('run-headless', False)).lower()
- XML.SubElement(xml_parent, 'disableTriggerDownstreamProjects').text = \
- str(data['maven'].get('disable-downstream', False)).lower()
- if 'custom-workspace' in data['maven']:
- XML.SubElement(xml_parent, 'customWorkspace').text = str(
- data['maven'].get('custom-workspace'))
- helpers.config_file_provider_settings(xml_parent, data['maven'])
-
- run_post_steps = XML.SubElement(xml_parent, 'runPostStepsIfResult')
- run_conditions = ['SUCCESS', 'UNSTABLE', 'FAILURE']
- run_condition = data['maven'].get('post-step-run-condition', 'FAILURE')
+ raise ValueError(
+ 'Not a valid private-repository "%s", '
+ 'must be one of "%s"'
+ % (private_repo, ", ".join(self.choices_private_repo.keys()))
+ )
+ XML.SubElement(
+ xml_parent,
+ "localRepository",
+ attrib={"class": self.choices_private_repo[private_repo]},
+ )
+
+ XML.SubElement(xml_parent, "ignoreUpstremChanges").text = str(
+ data["maven"].get("ignore-upstream-changes", True)
+ ).lower()
+
+ XML.SubElement(xml_parent, "rootPOM").text = data["maven"].get(
+ "root-pom", "pom.xml"
+ )
+ XML.SubElement(xml_parent, "aggregatorStyleBuild").text = str(
+ not data["maven"].get("parallel-build-modules", False)
+ ).lower()
+ XML.SubElement(xml_parent, "incrementalBuild").text = str(
+ data["maven"].get("incremental-build", False)
+ ).lower()
+ XML.SubElement(xml_parent, "siteArchivingDisabled").text = str(
+ not data["maven"].get("automatic-site-archiving", True)
+ ).lower()
+ XML.SubElement(xml_parent, "fingerprintingDisabled").text = str(
+ not data["maven"].get("automatic-fingerprinting", True)
+ ).lower()
+ if version > pkg_resources.parse_version(
+ "0"
+ ) and version < pkg_resources.parse_version("2.0.1"):
+ XML.SubElement(xml_parent, "perModuleEmail").text = str(
+ data.get("per-module-email", True)
+ ).lower()
+ XML.SubElement(xml_parent, "archivingDisabled").text = str(
+ not data["maven"].get("automatic-archiving", True)
+ ).lower()
+ XML.SubElement(xml_parent, "resolveDependencies").text = str(
+ data["maven"].get("resolve-dependencies", False)
+ ).lower()
+ XML.SubElement(xml_parent, "processPlugins").text = str(
+ data["maven"].get("process-plugins", False)
+ ).lower()
+ XML.SubElement(xml_parent, "mavenValidationLevel").text = "-1"
+ XML.SubElement(xml_parent, "runHeadless").text = str(
+ data["maven"].get("run-headless", False)
+ ).lower()
+ XML.SubElement(xml_parent, "disableTriggerDownstreamProjects").text = str(
+ data["maven"].get("disable-downstream", False)
+ ).lower()
+ if "custom-workspace" in data["maven"]:
+ XML.SubElement(xml_parent, "customWorkspace").text = str(
+ data["maven"].get("custom-workspace")
+ )
+ helpers.config_file_provider_settings(xml_parent, data["maven"])
+
+ run_post_steps = XML.SubElement(xml_parent, "runPostStepsIfResult")
+ run_conditions = ["SUCCESS", "UNSTABLE", "FAILURE"]
+ run_condition = data["maven"].get("post-step-run-condition", "FAILURE")
if run_condition not in run_conditions:
- raise InvalidAttributeError('post-step-run-condition',
- run_condition, run_conditions)
+ raise InvalidAttributeError(
+ "post-step-run-condition", run_condition, run_conditions
+ )
cond_dict = hudson_model.THRESHOLDS[run_condition]
- XML.SubElement(run_post_steps, 'name').text = cond_dict['name']
- XML.SubElement(run_post_steps, 'ordinal').text = cond_dict['ordinal']
- XML.SubElement(run_post_steps, 'color').text = cond_dict['color']
+ XML.SubElement(run_post_steps, "name").text = cond_dict["name"]
+ XML.SubElement(run_post_steps, "ordinal").text = cond_dict["ordinal"]
+ XML.SubElement(run_post_steps, "color").text = cond_dict["color"]
return xml_parent
diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py
index cfb27165..3761ddc1 100644
--- a/jenkins_jobs/modules/project_multibranch.py
+++ b/jenkins_jobs/modules/project_multibranch.py
@@ -83,99 +83,102 @@ logger = logging.getLogger(str(__name__))
class WorkflowMultiBranch(jenkins_jobs.modules.base.Base):
sequence = 0
- multibranch_path = 'org.jenkinsci.plugins.workflow.multibranch'
- jenkins_class = ''.join([multibranch_path, '.WorkflowMultiBranchProject'])
- jenkins_factory_class = ''.join(
- [multibranch_path, '.WorkflowBranchProjectFactory'])
+ multibranch_path = "org.jenkinsci.plugins.workflow.multibranch"
+ jenkins_class = "".join([multibranch_path, ".WorkflowMultiBranchProject"])
+ jenkins_factory_class = "".join([multibranch_path, ".WorkflowBranchProjectFactory"])
def root_xml(self, data):
xml_parent = XML.Element(self.jenkins_class)
- xml_parent.attrib['plugin'] = 'workflow-multibranch'
- XML.SubElement(xml_parent, 'properties')
+ xml_parent.attrib["plugin"] = "workflow-multibranch"
+ XML.SubElement(xml_parent, "properties")
#########
# Views #
#########
- views = XML.SubElement(xml_parent, 'views')
- all_view = XML.SubElement(views, 'hudson.model.AllView')
+ views = XML.SubElement(xml_parent, "views")
+ all_view = XML.SubElement(views, "hudson.model.AllView")
all_view_mapping = [
- ('', 'name', 'All'),
- ('', 'filterExecutors', False),
- ('', 'filterQueue', False),
+ ("", "name", "All"),
+ ("", "filterExecutors", False),
+ ("", "filterQueue", False),
]
helpers.convert_mapping_to_xml(
- all_view, {}, all_view_mapping, fail_required=True)
+ all_view, {}, all_view_mapping, fail_required=True
+ )
- XML.SubElement(all_view, 'properties', {
- 'class': 'hudson.model.View$PropertyList'
- })
+ XML.SubElement(
+ all_view, "properties", {"class": "hudson.model.View$PropertyList"}
+ )
- XML.SubElement(all_view, 'owner', {
- 'class': self.jenkins_class,
- 'reference': '../../..'
- })
+ XML.SubElement(
+ all_view, "owner", {"class": self.jenkins_class, "reference": "../../.."}
+ )
- XML.SubElement(xml_parent, 'viewsTabBar', {
- 'class': 'hudson.views.DefaultViewsTabBar'
- })
+ XML.SubElement(
+ xml_parent, "viewsTabBar", {"class": "hudson.views.DefaultViewsTabBar"}
+ )
################
# Folder Views #
################
- folderViews = XML.SubElement(xml_parent, 'folderViews', {
- 'class': 'jenkins.branch.MultiBranchProjectViewHolder',
- 'plugin': 'branch-api',
- })
+ folderViews = XML.SubElement(
+ xml_parent,
+ "folderViews",
+ {
+ "class": "jenkins.branch.MultiBranchProjectViewHolder",
+ "plugin": "branch-api",
+ },
+ )
- XML.SubElement(folderViews, 'owner', {
- 'class': self.jenkins_class,
- 'reference': '../..'
- })
+ XML.SubElement(
+ folderViews, "owner", {"class": self.jenkins_class, "reference": "../.."}
+ )
##################
# Health Metrics #
##################
- hm = XML.SubElement(xml_parent, 'healthMetrics')
- hm_path = ('com.cloudbees.hudson.plugins.folder.health'
- '.WorstChildHealthMetric')
- hm_plugin = XML.SubElement(hm, hm_path, {
- 'plugin': 'cloudbees-folder',
- })
- XML.SubElement(hm_plugin, 'nonRecursive').text = 'false'
+ hm = XML.SubElement(xml_parent, "healthMetrics")
+ hm_path = "com.cloudbees.hudson.plugins.folder.health" ".WorstChildHealthMetric"
+ hm_plugin = XML.SubElement(hm, hm_path, {"plugin": "cloudbees-folder"})
+ XML.SubElement(hm_plugin, "nonRecursive").text = "false"
########
# Icon #
########
- icon = XML.SubElement(xml_parent, 'icon', {
- 'class': 'jenkins.branch.MetadataActionFolderIcon',
- 'plugin': 'branch-api',
- })
- XML.SubElement(icon, 'owner', {
- 'class': self.jenkins_class,
- 'reference': '../..'
- })
+ icon = XML.SubElement(
+ xml_parent,
+ "icon",
+ {
+ "class": "jenkins.branch.MetadataActionFolderIcon",
+ "plugin": "branch-api",
+ },
+ )
+ XML.SubElement(
+ icon, "owner", {"class": self.jenkins_class, "reference": "../.."}
+ )
########################
# Orphan Item Strategy #
########################
- ois_default_strategy = ('com.cloudbees.hudson.plugins.'
- 'folder.computed.DefaultOrphanedItemStrategy')
+ ois_default_strategy = (
+ "com.cloudbees.hudson.plugins."
+ "folder.computed.DefaultOrphanedItemStrategy"
+ )
ois = XML.SubElement(
- xml_parent, 'orphanedItemStrategy', {
- 'class': ois_default_strategy,
- 'plugin': 'cloudbees-folder',
- }
+ xml_parent,
+ "orphanedItemStrategy",
+ {"class": ois_default_strategy, "plugin": "cloudbees-folder"},
)
ois_mapping = [
- ('prune-dead-branches', 'pruneDeadBranches', True, [True, False]),
- ('days-to-keep', 'daysToKeep', -1),
- ('number-to-keep', 'numToKeep', -1),
+ ("prune-dead-branches", "pruneDeadBranches", True, [True, False]),
+ ("days-to-keep", "daysToKeep", -1),
+ ("number-to-keep", "numToKeep", -1),
]
helpers.convert_mapping_to_xml(ois, data, ois_mapping)
@@ -183,111 +186,109 @@ class WorkflowMultiBranch(jenkins_jobs.modules.base.Base):
# Periodic Folder Trigger #
###########################
- triggers = XML.SubElement(xml_parent, 'triggers')
+ triggers = XML.SubElement(xml_parent, "triggers")
# Valid options for the periodic trigger interval.
- pft_map = collections.OrderedDict([
- ("1m", ("* * * * *", '60000')),
- ("2m", ("*/2 * * * *", '120000')),
- ("5m", ("*/5 * * * *", '300000')),
- ("10m", ("H/6 * * * *", '600000')),
- ("15m", ("H/6 * * * *", '900000')),
- ("20m", ("H/3 * * * *", '1200000')),
- ("25m", ("H/3 * * * *", '1500000')),
- ("30m", ("H/2 * * * *", '1800000')),
- ("1h", ("H * * * *", '3600000')),
- ("2h", ("H * * * *", '7200000')),
- ("4h", ("H * * * *", '14400000')),
- ("8h", ("H * * * *", '28800000')),
- ("12h", ("H H * * *", '43200000')),
- ("1d", ("H H * * *", '86400000')),
- ("2d", ("H H * * *", '172800000')),
- ("1w", ("H H * * *", '604800000')),
- ("2w", ("H H * * *", '1209600000')),
- ("4w", ("H H * * *", '2419200000')),
- ])
-
- pft_val = data.get('periodic-folder-trigger')
+ pft_map = collections.OrderedDict(
+ [
+ ("1m", ("* * * * *", "60000")),
+ ("2m", ("*/2 * * * *", "120000")),
+ ("5m", ("*/5 * * * *", "300000")),
+ ("10m", ("H/6 * * * *", "600000")),
+ ("15m", ("H/6 * * * *", "900000")),
+ ("20m", ("H/3 * * * *", "1200000")),
+ ("25m", ("H/3 * * * *", "1500000")),
+ ("30m", ("H/2 * * * *", "1800000")),
+ ("1h", ("H * * * *", "3600000")),
+ ("2h", ("H * * * *", "7200000")),
+ ("4h", ("H * * * *", "14400000")),
+ ("8h", ("H * * * *", "28800000")),
+ ("12h", ("H H * * *", "43200000")),
+ ("1d", ("H H * * *", "86400000")),
+ ("2d", ("H H * * *", "172800000")),
+ ("1w", ("H H * * *", "604800000")),
+ ("2w", ("H H * * *", "1209600000")),
+ ("4w", ("H H * * *", "2419200000")),
+ ]
+ )
+
+ pft_val = data.get("periodic-folder-trigger")
if pft_val:
if not pft_map.get(pft_val):
raise InvalidAttributeError(
- 'periodic-folder-trigger',
- pft_val,
- pft_map.keys())
+ "periodic-folder-trigger", pft_val, pft_map.keys()
+ )
pft_path = (
- 'com.cloudbees.hudson.plugins.folder.computed.'
- 'PeriodicFolderTrigger')
- pft = XML.SubElement(triggers, pft_path, {
- 'plugin': 'cloudbees-folder'
- })
- XML.SubElement(pft, 'spec').text = pft_map[pft_val][0]
- XML.SubElement(pft, 'interval').text = pft_map[pft_val][1]
+ "com.cloudbees.hudson.plugins.folder.computed." "PeriodicFolderTrigger"
+ )
+ pft = XML.SubElement(triggers, pft_path, {"plugin": "cloudbees-folder"})
+ XML.SubElement(pft, "spec").text = pft_map[pft_val][0]
+ XML.SubElement(pft, "interval").text = pft_map[pft_val][1]
###########
# Sources #
###########
- sources = XML.SubElement(xml_parent, 'sources', {
- 'class': 'jenkins.branch.MultiBranchProject$BranchSourceList',
- 'plugin': 'branch-api',
- })
- sources_data = XML.SubElement(sources, 'data')
- XML.SubElement(sources, 'owner', {
- 'class': self.jenkins_class,
- 'reference': '../..',
- })
-
- valid_scm = [
- 'bitbucket',
- 'gerrit',
- 'git',
- 'github',
- ]
- for scm_data in data.get('scm', None):
+ sources = XML.SubElement(
+ xml_parent,
+ "sources",
+ {
+ "class": "jenkins.branch.MultiBranchProject$BranchSourceList",
+ "plugin": "branch-api",
+ },
+ )
+ sources_data = XML.SubElement(sources, "data")
+ XML.SubElement(
+ sources, "owner", {"class": self.jenkins_class, "reference": "../.."}
+ )
+
+ valid_scm = ["bitbucket", "gerrit", "git", "github"]
+ for scm_data in data.get("scm", None):
for scm in scm_data:
- bs = XML.SubElement(
- sources_data, 'jenkins.branch.BranchSource')
+ bs = XML.SubElement(sources_data, "jenkins.branch.BranchSource")
- if scm == 'bitbucket':
+ if scm == "bitbucket":
bitbucket_scm(bs, scm_data[scm])
- elif scm == 'gerrit':
+ elif scm == "gerrit":
gerrit_scm(bs, scm_data[scm])
- elif scm == 'git':
+ elif scm == "git":
git_scm(bs, scm_data[scm])
- elif scm == 'github':
+ elif scm == "github":
github_scm(bs, scm_data[scm])
else:
- raise InvalidAttributeError('scm', scm_data, valid_scm)
+ raise InvalidAttributeError("scm", scm_data, valid_scm)
###########
# Factory #
###########
- factory = XML.SubElement(xml_parent, 'factory', {
- 'class': self.jenkins_factory_class,
- })
- XML.SubElement(factory, 'owner', {
- 'class': self.jenkins_class,
- 'reference': '../..'
- })
- XML.SubElement(factory, 'scriptPath').text = data.get(
- 'script-path', 'Jenkinsfile')
+ factory = XML.SubElement(
+ xml_parent, "factory", {"class": self.jenkins_factory_class}
+ )
+ XML.SubElement(
+ factory, "owner", {"class": self.jenkins_class, "reference": "../.."}
+ )
+ XML.SubElement(factory, "scriptPath").text = data.get(
+ "script-path", "Jenkinsfile"
+ )
return xml_parent
class WorkflowMultiBranchDefaults(WorkflowMultiBranch):
jenkins_class = (
- 'org.jenkinsci.plugins.pipeline.multibranch'
- '.defaults.PipelineMultiBranchDefaultsProject')
+ "org.jenkinsci.plugins.pipeline.multibranch"
+ ".defaults.PipelineMultiBranchDefaultsProject"
+ )
jenkins_factory_class = (
- 'org.jenkinsci.plugins.pipeline.multibranch'
- '.defaults.PipelineBranchDefaultsProjectFactory')
+ "org.jenkinsci.plugins.pipeline.multibranch"
+ ".defaults.PipelineBranchDefaultsProjectFactory"
+ )
def bitbucket_scm(xml_parent, data):
@@ -395,148 +396,140 @@ def bitbucket_scm(xml_parent, data):
.. literalinclude::
/../../tests/multibranch/fixtures/scm_bitbucket_full.yaml
"""
- source = XML.SubElement(xml_parent, 'source', {
- 'class': 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource',
- 'plugin': 'cloudbees-bitbucket-branch-source',
- })
+ source = XML.SubElement(
+ xml_parent,
+ "source",
+ {
+ "class": "com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource",
+ "plugin": "cloudbees-bitbucket-branch-source",
+ },
+ )
source_mapping = [
- ('', 'id', '-'.join(['bb', data.get('repo-owner', ''),
- data.get('repo', '')])),
- ('repo-owner', 'repoOwner', None),
- ('repo', 'repository', None),
+ ("", "id", "-".join(["bb", data.get("repo-owner", ""), data.get("repo", "")])),
+ ("repo-owner", "repoOwner", None),
+ ("repo", "repository", None),
]
- helpers.convert_mapping_to_xml(
- source, data, source_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(source, data, source_mapping, fail_required=True)
mapping_optional = [
- ('credentials-id', 'credentialsId', None),
- ('server-url', 'serverUrl', None),
+ ("credentials-id", "credentialsId", None),
+ ("server-url", "serverUrl", None),
]
- helpers.convert_mapping_to_xml(
- source, data, mapping_optional, fail_required=False)
-
- traits = XML.SubElement(source, 'traits')
- if data.get('discover-tags', False):
- XML.SubElement(traits,
- 'com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait')
- if data.get('head-filter-regex', None):
- rshf = XML.SubElement(traits,
- 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
- XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')
-
- if data.get('discover-pr-origin', None):
- dpro = XML.SubElement(traits,
- 'com.cloudbees.jenkins.plugins.bitbucket'
- '.OriginPullRequestDiscoveryTrait')
- dpro_strategies = {
- 'mergeOnly': '1',
- 'headOnly': '2',
- 'mergeAndHead': '3'
- }
- dpro_mapping = [
- ('discover-pr-origin', 'strategyId', None, dpro_strategies)
- ]
- helpers.convert_mapping_to_xml(
- dpro, data, dpro_mapping, fail_required=True)
-
- if data.get('discover-pr-forks-strategy'):
- dprf = XML.SubElement(traits,
- 'com.cloudbees.jenkins.plugins.bitbucket'
- '.ForkPullRequestDiscoveryTrait')
- dprf_strategy = {
- 'merge-current': '1',
- 'current': '2',
- 'both': '3',
- }
+ helpers.convert_mapping_to_xml(source, data, mapping_optional, fail_required=False)
+
+ traits = XML.SubElement(source, "traits")
+ if data.get("discover-tags", False):
+ XML.SubElement(
+ traits, "com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait"
+ )
+ if data.get("head-filter-regex", None):
+ rshf = XML.SubElement(traits, "jenkins.scm.impl.trait.RegexSCMHeadFilterTrait")
+ XML.SubElement(rshf, "regex").text = data.get("head-filter-regex")
+
+ if data.get("discover-pr-origin", None):
+ dpro = XML.SubElement(
+ traits,
+ "com.cloudbees.jenkins.plugins.bitbucket"
+ ".OriginPullRequestDiscoveryTrait",
+ )
+ dpro_strategies = {"mergeOnly": "1", "headOnly": "2", "mergeAndHead": "3"}
+ dpro_mapping = [("discover-pr-origin", "strategyId", None, dpro_strategies)]
+ helpers.convert_mapping_to_xml(dpro, data, dpro_mapping, fail_required=True)
+
+ if data.get("discover-pr-forks-strategy"):
+ dprf = XML.SubElement(
+ traits,
+ "com.cloudbees.jenkins.plugins.bitbucket" ".ForkPullRequestDiscoveryTrait",
+ )
+ dprf_strategy = {"merge-current": "1", "current": "2", "both": "3"}
dprf_mapping = [
- ('discover-pr-forks-strategy', 'strategyId', 'merge-current',
- dprf_strategy)
+ ("discover-pr-forks-strategy", "strategyId", "merge-current", dprf_strategy)
]
- helpers.convert_mapping_to_xml(
- dprf, data, dprf_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(dprf, data, dprf_mapping, fail_required=True)
- trust = data.get('discover-pr-forks-trust', 'contributors')
+ trust = data.get("discover-pr-forks-trust", "contributors")
trust_map = {
- 'contributors': ''.join([
- 'com.cloudbees.jenkins.plugins.bitbucket'
- '.ForkPullRequestDiscoveryTrait$TrustContributors']),
- 'everyone': ''.join([
- 'com.cloudbees.jenkins.plugins.bitbucket'
- '.ForkPullRequestDiscoveryTrait$TrustEveryone']),
- 'permission': ''.join([
- 'com.cloudbees.jenkins.plugins.bitbucket'
- '.ForkPullRequestDiscoveryTrait$TrustPermission']),
- 'nobody': ''.join([
- 'com.cloudbees.jenkins.plugins.bitbucket'
- '.ForkPullRequestDiscoveryTrait$TrustNobody']),
+ "contributors": "".join(
+ [
+ "com.cloudbees.jenkins.plugins.bitbucket"
+ ".ForkPullRequestDiscoveryTrait$TrustContributors"
+ ]
+ ),
+ "everyone": "".join(
+ [
+ "com.cloudbees.jenkins.plugins.bitbucket"
+ ".ForkPullRequestDiscoveryTrait$TrustEveryone"
+ ]
+ ),
+ "permission": "".join(
+ [
+ "com.cloudbees.jenkins.plugins.bitbucket"
+ ".ForkPullRequestDiscoveryTrait$TrustPermission"
+ ]
+ ),
+ "nobody": "".join(
+ [
+ "com.cloudbees.jenkins.plugins.bitbucket"
+ ".ForkPullRequestDiscoveryTrait$TrustNobody"
+ ]
+ ),
}
if trust not in trust_map:
- raise InvalidAttributeError('discover-pr-forks-trust',
- trust,
- trust_map.keys())
- XML.SubElement(dprf, 'trust').attrib['class'] = trust_map[trust]
-
- if data.get('discover-branch', None):
- dbr = XML.SubElement(traits,
- 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait')
- dbr_strategies = {
- 'ex-pr': '1',
- 'only-pr': '2',
- 'all': '3'
- }
- dbr_mapping = [
- ('discover-branch', 'strategyId', None, dbr_strategies)
- ]
- helpers.convert_mapping_to_xml(
- dbr, data, dbr_mapping, fail_required=True)
+ raise InvalidAttributeError(
+ "discover-pr-forks-trust", trust, trust_map.keys()
+ )
+ XML.SubElement(dprf, "trust").attrib["class"] = trust_map[trust]
+
+ if data.get("discover-branch", None):
+ dbr = XML.SubElement(
+ traits, "com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait"
+ )
+ dbr_strategies = {"ex-pr": "1", "only-pr": "2", "all": "3"}
+ dbr_mapping = [("discover-branch", "strategyId", None, dbr_strategies)]
+ helpers.convert_mapping_to_xml(dbr, data, dbr_mapping, fail_required=True)
- if data.get('property-strategies', None):
+ if data.get("property-strategies", None):
property_strategies(xml_parent, data)
- if data.get('build-strategies', None):
+ if data.get("build-strategies", None):
build_strategies(xml_parent, data)
- if data.get('local-branch', False):
- lbr = XML.SubElement(traits,
- 'jenkins.plugins.git.traits.LocalBranchTrait', {
- 'plugin': 'git',
- }
+ if data.get("local-branch", False):
+ lbr = XML.SubElement(
+ traits, "jenkins.plugins.git.traits.LocalBranchTrait", {"plugin": "git"}
)
- lbr_extension = XML.SubElement(lbr,
- 'extension', {
- 'class': 'hudson.plugins.git.extensions.impl.LocalBranch',
- }
+ lbr_extension = XML.SubElement(
+ lbr,
+ "extension",
+ {"class": "hudson.plugins.git.extensions.impl.LocalBranch"},
)
- XML.SubElement(lbr_extension,
- 'localBranch').text = "**"
-
- if data.get('checkout-over-ssh', None):
- cossh = XML.SubElement(traits,
- 'com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait')
- cossh_credentials = [
- ('credentials', 'credentialsId', ''),
- ]
+ XML.SubElement(lbr_extension, "localBranch").text = "**"
+
+ if data.get("checkout-over-ssh", None):
+ cossh = XML.SubElement(
+ traits, "com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait"
+ )
+ cossh_credentials = [("credentials", "credentialsId", "")]
helpers.convert_mapping_to_xml(
- cossh,
- data.get('checkout-over-ssh'),
- cossh_credentials,
- fail_required=True)
-
- if data.get('filter-by-name-wildcard', None):
- wscmf_name = XML.SubElement(traits,
- 'jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait', {
- 'plugin': 'scm-api',
- }
+ cossh, data.get("checkout-over-ssh"), cossh_credentials, fail_required=True
+ )
+
+ if data.get("filter-by-name-wildcard", None):
+ wscmf_name = XML.SubElement(
+ traits,
+ "jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait",
+ {"plugin": "scm-api"},
)
wscmf_name_mapping = [
- ('includes', 'includes', ''),
- ('excludes', 'excludes', '')
+ ("includes", "includes", ""),
+ ("excludes", "excludes", ""),
]
helpers.convert_mapping_to_xml(
wscmf_name,
- data.get('filter-by-name-wildcard', ''),
+ data.get("filter-by-name-wildcard", ""),
wscmf_name_mapping,
- fail_required=True)
+ fail_required=True,
+ )
# handle the default git extensions like:
# - clean
@@ -587,56 +580,56 @@ def gerrit_scm(xml_parent, data):
.. literalinclude::
/../../tests/multibranch/fixtures/scm_gerrit_full.yaml
"""
- source = XML.SubElement(xml_parent, 'source', {
- 'class': 'jenkins.plugins.gerrit.GerritSCMSource',
- 'plugin': 'gerrit',
- })
+ source = XML.SubElement(
+ xml_parent,
+ "source",
+ {"class": "jenkins.plugins.gerrit.GerritSCMSource", "plugin": "gerrit"},
+ )
source_mapping = [
- ('', 'id', '-'.join(['gr', data.get('url', '')])),
- ('url', 'remote', None),
- ('credentials-id', 'credentialsId', ''),
- ('includes', 'includes', '*'),
- ('excludes', 'excludes', ''),
- ('ignore-on-push-notifications', 'ignoreOnPushNotifications', True),
+ ("", "id", "-".join(["gr", data.get("url", "")])),
+ ("url", "remote", None),
+ ("credentials-id", "credentialsId", ""),
+ ("includes", "includes", "*"),
+ ("excludes", "excludes", ""),
+ ("ignore-on-push-notifications", "ignoreOnPushNotifications", True),
]
- helpers.convert_mapping_to_xml(
- source, data, source_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(source, data, source_mapping, fail_required=True)
- source_mapping_optional = [
- ('api-uri', 'apiUri', None),
- ]
+ source_mapping_optional = [("api-uri", "apiUri", None)]
helpers.convert_mapping_to_xml(
- source, data, source_mapping_optional, fail_required=False)
+ source, data, source_mapping_optional, fail_required=False
+ )
# Traits
- traits = XML.SubElement(source, 'traits')
- XML.SubElement(traits,
- 'jenkins.plugins.gerrit.traits.ChangeDiscoveryTrait')
+ traits = XML.SubElement(source, "traits")
+ XML.SubElement(traits, "jenkins.plugins.gerrit.traits.ChangeDiscoveryTrait")
# Refspec Trait
refspec_trait = XML.SubElement(
- traits, 'jenkins.plugins.git.traits.RefSpecsSCMSourceTrait', {
- 'plugin': 'git',
- }
+ traits, "jenkins.plugins.git.traits.RefSpecsSCMSourceTrait", {"plugin": "git"}
+ )
+ templates = XML.SubElement(refspec_trait, "templates")
+ refspecs = data.get(
+ "refspecs",
+ [
+ "+refs/changes/*:refs/remotes/@{remote}/*",
+ "+refs/heads/*:refs/remotes/@{remote}/*",
+ ],
)
- templates = XML.SubElement(refspec_trait, 'templates')
- refspecs = data.get('refspecs', [
- '+refs/changes/*:refs/remotes/@{remote}/*',
- '+refs/heads/*:refs/remotes/@{remote}/*',
- ])
# convert single string to list
if isinstance(refspecs, six.string_types):
refspecs = [refspecs]
for x in refspecs:
e = XML.SubElement(
- templates, ('jenkins.plugins.git.traits'
- '.RefSpecsSCMSourceTrait_-RefSpecTemplate'))
- XML.SubElement(e, 'value').text = x
+ templates,
+ ("jenkins.plugins.git.traits" ".RefSpecsSCMSourceTrait_-RefSpecTemplate"),
+ )
+ XML.SubElement(e, "value").text = x
- if data.get('property-strategies', None):
+ if data.get("property-strategies", None):
property_strategies(xml_parent, data)
- if data.get('build-strategies', None):
+ if data.get("build-strategies", None):
build_strategies(xml_parent, data)
@@ -707,44 +700,42 @@ def git_scm(xml_parent, data):
.. literalinclude:: /../../tests/multibranch/fixtures/scm_git_full.yaml
"""
- source = XML.SubElement(xml_parent, 'source', {
- 'class': 'jenkins.plugins.git.GitSCMSource',
- 'plugin': 'git',
- })
+ source = XML.SubElement(
+ xml_parent,
+ "source",
+ {"class": "jenkins.plugins.git.GitSCMSource", "plugin": "git"},
+ )
source_mapping = [
- ('', 'id', '-'.join(['gt', data.get('url', '')])),
- ('url', 'remote', None),
- ('credentials-id', 'credentialsId', ''),
+ ("", "id", "-".join(["gt", data.get("url", "")])),
+ ("url", "remote", None),
+ ("credentials-id", "credentialsId", ""),
]
- helpers.convert_mapping_to_xml(
- source, data, source_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(source, data, source_mapping, fail_required=True)
##########
# Traits #
##########
- traits_path = 'jenkins.plugins.git.traits'
- traits = XML.SubElement(source, 'traits')
+ traits_path = "jenkins.plugins.git.traits"
+ traits = XML.SubElement(source, "traits")
- if data.get('discover-branches', True):
- XML.SubElement(traits, ''.join([traits_path, '.BranchDiscoveryTrait']))
+ if data.get("discover-branches", True):
+ XML.SubElement(traits, "".join([traits_path, ".BranchDiscoveryTrait"]))
- if data.get('discover-tags', False):
- XML.SubElement(traits, ''.join([traits_path, '.TagDiscoveryTrait']))
+ if data.get("discover-tags", False):
+ XML.SubElement(traits, "".join([traits_path, ".TagDiscoveryTrait"]))
- if data.get('ignore-on-push-notifications', False):
- XML.SubElement(
- traits, ''.join([traits_path, '.IgnoreOnPushNotificationTrait']))
+ if data.get("ignore-on-push-notifications", False):
+ XML.SubElement(traits, "".join([traits_path, ".IgnoreOnPushNotificationTrait"]))
- if data.get('head-filter-regex', None):
- rshf = XML.SubElement(traits,
- 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
- XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')
+ if data.get("head-filter-regex", None):
+ rshf = XML.SubElement(traits, "jenkins.scm.impl.trait.RegexSCMHeadFilterTrait")
+ XML.SubElement(rshf, "regex").text = data.get("head-filter-regex")
- if data.get('property-strategies', None):
+ if data.get("property-strategies", None):
property_strategies(xml_parent, data)
- if data.get('build-strategies', None):
+ if data.get("build-strategies", None):
build_strategies(xml_parent, data)
# handle the default git extensions like:
@@ -850,147 +841,117 @@ def github_scm(xml_parent, data):
.. literalinclude::
/../../tests/multibranch/fixtures/scm_github_full.yaml
"""
- github_path = 'org.jenkinsci.plugins.github_branch_source'
- github_path_dscore = 'org.jenkinsci.plugins.github__branch__source'
-
- source = XML.SubElement(xml_parent, 'source', {
- 'class': ''.join([github_path, '.GitHubSCMSource']),
- 'plugin': 'github-branch-source',
- })
+ github_path = "org.jenkinsci.plugins.github_branch_source"
+ github_path_dscore = "org.jenkinsci.plugins.github__branch__source"
+
+ source = XML.SubElement(
+ xml_parent,
+ "source",
+ {
+ "class": "".join([github_path, ".GitHubSCMSource"]),
+ "plugin": "github-branch-source",
+ },
+ )
mapping = [
- ('', 'id', '-'.join(['gh', data.get('repo-owner', ''),
- data.get('repo', '')])),
- ('repo-owner', 'repoOwner', None),
- ('repo', 'repository', None),
+ ("", "id", "-".join(["gh", data.get("repo-owner", ""), data.get("repo", "")])),
+ ("repo-owner", "repoOwner", None),
+ ("repo", "repository", None),
]
- helpers.convert_mapping_to_xml(
- source, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(source, data, mapping, fail_required=True)
mapping_optional = [
- ('api-uri', 'apiUri', None),
- ('credentials-id', 'credentialsId', None),
+ ("api-uri", "apiUri", None),
+ ("credentials-id", "credentialsId", None),
]
- helpers.convert_mapping_to_xml(
- source, data, mapping_optional, fail_required=False)
+ helpers.convert_mapping_to_xml(source, data, mapping_optional, fail_required=False)
- traits = XML.SubElement(source, 'traits')
+ traits = XML.SubElement(source, "traits")
# no-pr value is assumed if branch-discovery not mentioned.
- if data.get('branch-discovery', 'no-pr'):
- bd = XML.SubElement(traits, ''.join([
- github_path_dscore, '.BranchDiscoveryTrait']))
- bd_strategy = {
- 'no-pr': '1',
- 'only-pr': '2',
- 'all': '3',
- }
- bd_mapping = [
- ('branch-discovery', 'strategyId', 'no-pr', bd_strategy)
- ]
- helpers.convert_mapping_to_xml(
- bd, data, bd_mapping, fail_required=True)
+ if data.get("branch-discovery", "no-pr"):
+ bd = XML.SubElement(
+ traits, "".join([github_path_dscore, ".BranchDiscoveryTrait"])
+ )
+ bd_strategy = {"no-pr": "1", "only-pr": "2", "all": "3"}
+ bd_mapping = [("branch-discovery", "strategyId", "no-pr", bd_strategy)]
+ helpers.convert_mapping_to_xml(bd, data, bd_mapping, fail_required=True)
- if data.get('ssh-checkout', None):
+ if data.get("ssh-checkout", None):
cossh = XML.SubElement(
- traits, ''.join([
- github_path_dscore, '.SSHCheckoutTrait'
- ])
+ traits, "".join([github_path_dscore, ".SSHCheckoutTrait"])
)
- if not isinstance(data.get('ssh-checkout'), bool):
- cossh_credentials = [
- ('credentials', 'credentialsId', ''),
- ]
+ if not isinstance(data.get("ssh-checkout"), bool):
+ cossh_credentials = [("credentials", "credentialsId", "")]
helpers.convert_mapping_to_xml(
- cossh,
- data.get('ssh-checkout'),
- cossh_credentials,
- fail_required=True)
+ cossh, data.get("ssh-checkout"), cossh_credentials, fail_required=True
+ )
- if data.get('discover-tags', False):
- XML.SubElement(
- traits, ''.join([
- github_path_dscore, '.TagDiscoveryTrait'
- ])
- )
+ if data.get("discover-tags", False):
+ XML.SubElement(traits, "".join([github_path_dscore, ".TagDiscoveryTrait"]))
- if data.get('discover-pr-forks-strategy', 'merged-current'):
+ if data.get("discover-pr-forks-strategy", "merged-current"):
dprf = XML.SubElement(
- traits, ''.join([
- github_path_dscore, '.ForkPullRequestDiscoveryTrait'
- ])
+ traits, "".join([github_path_dscore, ".ForkPullRequestDiscoveryTrait"])
)
- dprf_strategy = {
- 'merge-current': '1',
- 'current': '2',
- 'both': '3',
- }
+ dprf_strategy = {"merge-current": "1", "current": "2", "both": "3"}
dprf_mapping = [
- ('discover-pr-forks-strategy', 'strategyId', 'merge-current',
- dprf_strategy)
+ ("discover-pr-forks-strategy", "strategyId", "merge-current", dprf_strategy)
]
- helpers.convert_mapping_to_xml(
- dprf, data, dprf_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(dprf, data, dprf_mapping, fail_required=True)
- trust = data.get('discover-pr-forks-trust', 'contributors')
+ trust = data.get("discover-pr-forks-trust", "contributors")
trust_map = {
- 'contributors': ''.join([
- github_path,
- '.ForkPullRequestDiscoveryTrait$TrustContributors']),
- 'everyone': ''.join([
- github_path,
- '.ForkPullRequestDiscoveryTrait$TrustEveryone']),
- 'permission': ''.join([
- github_path,
- '.ForkPullRequestDiscoveryTrait$TrustPermission']),
- 'nobody': ''.join([
- github_path,
- '.ForkPullRequestDiscoveryTrait$TrustNobody']),
+ "contributors": "".join(
+ [github_path, ".ForkPullRequestDiscoveryTrait$TrustContributors"]
+ ),
+ "everyone": "".join(
+ [github_path, ".ForkPullRequestDiscoveryTrait$TrustEveryone"]
+ ),
+ "permission": "".join(
+ [github_path, ".ForkPullRequestDiscoveryTrait$TrustPermission"]
+ ),
+ "nobody": "".join(
+ [github_path, ".ForkPullRequestDiscoveryTrait$TrustNobody"]
+ ),
}
if trust not in trust_map:
- raise InvalidAttributeError('discover-pr-forks-trust',
- trust,
- trust_map.keys())
- XML.SubElement(dprf, 'trust').attrib['class'] = trust_map[trust]
-
- dpro_strategy = data.get('discover-pr-origin', 'merge-current')
- dpro = XML.SubElement(traits, ''.join([
- github_path_dscore,
- '.OriginPullRequestDiscoveryTrait'
- ]))
- dpro_strategy_map = {
- 'merge-current': '1',
- 'current': '2',
- 'both': '3',
- }
+ raise InvalidAttributeError(
+ "discover-pr-forks-trust", trust, trust_map.keys()
+ )
+ XML.SubElement(dprf, "trust").attrib["class"] = trust_map[trust]
+
+ dpro_strategy = data.get("discover-pr-origin", "merge-current")
+ dpro = XML.SubElement(
+ traits, "".join([github_path_dscore, ".OriginPullRequestDiscoveryTrait"])
+ )
+ dpro_strategy_map = {"merge-current": "1", "current": "2", "both": "3"}
if dpro_strategy not in dpro_strategy_map:
- raise InvalidAttributeError('discover-pr-origin',
- dpro_strategy,
- dpro_strategy_map.keys())
+ raise InvalidAttributeError(
+ "discover-pr-origin", dpro_strategy, dpro_strategy_map.keys()
+ )
dpro_mapping = [
- ('discover-pr-origin', 'strategyId', 'merge-current',
- dpro_strategy_map)
+ ("discover-pr-origin", "strategyId", "merge-current", dpro_strategy_map)
]
- helpers.convert_mapping_to_xml(
- dpro, data, dpro_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(dpro, data, dpro_mapping, fail_required=True)
- if data.get('head-filter-regex', None):
- rshf = XML.SubElement(traits,
- 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
- XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')
+ if data.get("head-filter-regex", None):
+ rshf = XML.SubElement(traits, "jenkins.scm.impl.trait.RegexSCMHeadFilterTrait")
+ XML.SubElement(rshf, "regex").text = data.get("head-filter-regex")
- if data.get('property-strategies', None):
+ if data.get("property-strategies", None):
property_strategies(xml_parent, data)
- if data.get('build-strategies', None):
+ if data.get("build-strategies", None):
build_strategies(xml_parent, data)
- if data.get('notification-context', None):
- rshf = XML.SubElement(traits,
- 'org.jenkinsci.plugins.githubScmTraitNotificationContext.'
- 'NotificationContextTrait')
- XML.SubElement(rshf, 'contextLabel').text = data.get(
- 'notification-context')
- XML.SubElement(rshf, 'typeSuffix').text = 'true'
+ if data.get("notification-context", None):
+ rshf = XML.SubElement(
+ traits,
+ "org.jenkinsci.plugins.githubScmTraitNotificationContext."
+ "NotificationContextTrait",
+ )
+ XML.SubElement(rshf, "contextLabel").text = data.get("notification-context")
+ XML.SubElement(rshf, "typeSuffix").text = "true"
# handle the default git extensions like:
# - clean
@@ -1005,14 +966,13 @@ def github_scm(xml_parent, data):
# github-only extensions
disable_github_status_path_dscore = (
- 'com.adobe.jenkins.disable__github__multibranch__status')
- if data.get('disable-pr-notifications', False):
+ "com.adobe.jenkins.disable__github__multibranch__status"
+ )
+ if data.get("disable-pr-notifications", False):
XML.SubElement(
- traits, ''.join([
- disable_github_status_path_dscore, '.DisableStatusUpdateTrait'
- ]), {
- 'plugin': 'disable-github-multibranch-status'
- }
+ traits,
+ "".join([disable_github_status_path_dscore, ".DisableStatusUpdateTrait"]),
+ {"plugin": "disable-github-multibranch-status"},
)
@@ -1065,101 +1025,128 @@ def build_strategies(xml_parent, data):
"""
- basic_build_strategies = 'jenkins.branch.buildstrategies.basic'
- bbs = XML.SubElement(xml_parent, 'buildStrategies')
- for bbs_list in data.get('build-strategies', None):
- if 'tags' in bbs_list:
- tags = bbs_list['tags']
- tags_elem = XML.SubElement(bbs, ''.join([basic_build_strategies,
- '.TagBuildStrategyImpl']), {
- 'plugin': 'basic-branch-build-strategies',
- })
+ basic_build_strategies = "jenkins.branch.buildstrategies.basic"
+ bbs = XML.SubElement(xml_parent, "buildStrategies")
+ for bbs_list in data.get("build-strategies", None):
+ if "tags" in bbs_list:
+ tags = bbs_list["tags"]
+ tags_elem = XML.SubElement(
+ bbs,
+ "".join([basic_build_strategies, ".TagBuildStrategyImpl"]),
+ {"plugin": "basic-branch-build-strategies"},
+ )
newer_than = -1
- if ('ignore-tags-newer-than' in tags and
- tags['ignore-tags-newer-than'] >= 0):
- newer_than = str(tags['ignore-tags-newer-than'] * 86400000)
- XML.SubElement(tags_elem, 'atMostMillis').text = str(newer_than)
+ if "ignore-tags-newer-than" in tags and tags["ignore-tags-newer-than"] >= 0:
+ newer_than = str(tags["ignore-tags-newer-than"] * 86400000)
+ XML.SubElement(tags_elem, "atMostMillis").text = str(newer_than)
older_than = -1
- if ('ignore-tags-older-than' in tags and
- tags['ignore-tags-older-than'] >= 0):
- older_than = str(tags['ignore-tags-older-than'] * 86400000)
- XML.SubElement(tags_elem, 'atLeastMillis').text = str(older_than)
-
- if bbs_list.get('regular-branches', False):
- XML.SubElement(bbs, ''.join([basic_build_strategies,
- '.BranchBuildStrategyImpl']), {
- 'plugin': 'basic-branch-build-strategies',
- })
-
- if bbs_list.get('skip-initial-build', False):
- XML.SubElement(bbs, ''.join([basic_build_strategies,
- '.SkipInitialBuildOnFirstBranchIndexing']), {
- 'plugin': 'basic-branch-build-strategies',
- })
-
- if 'change-request' in bbs_list:
- cr = bbs_list['change-request']
- cr_elem = XML.SubElement(bbs, ''.join([basic_build_strategies,
- '.ChangeRequestBuildStrategyImpl']), {
- 'plugin': 'basic-branch-build-strategies',
- })
- itoc = cr.get('ignore-target-only-changes', False)
- XML.SubElement(cr_elem, 'ignoreTargetOnlyChanges').text = (
- str(itoc).lower())
-
- if 'named-branches' in bbs_list:
- named_branch_elem = XML.SubElement(bbs, ''.join(
- [basic_build_strategies, '.NamedBranchBuildStrategyImpl']), {
- 'plugin': 'basic-branch-build-strategies',
- })
-
- filters = XML.SubElement(named_branch_elem, 'filters')
-
- for nb in bbs_list['named-branches']:
- if 'exact-name' in nb:
- exact_name_elem = XML.SubElement(filters, ''.join(
- [basic_build_strategies,
- '.NamedBranchBuildStrategyImpl',
- '_-ExactNameFilter']))
+ if "ignore-tags-older-than" in tags and tags["ignore-tags-older-than"] >= 0:
+ older_than = str(tags["ignore-tags-older-than"] * 86400000)
+ XML.SubElement(tags_elem, "atLeastMillis").text = str(older_than)
+
+ if bbs_list.get("regular-branches", False):
+ XML.SubElement(
+ bbs,
+ "".join([basic_build_strategies, ".BranchBuildStrategyImpl"]),
+ {"plugin": "basic-branch-build-strategies"},
+ )
+
+ if bbs_list.get("skip-initial-build", False):
+ XML.SubElement(
+ bbs,
+ "".join(
+ [basic_build_strategies, ".SkipInitialBuildOnFirstBranchIndexing"]
+ ),
+ {"plugin": "basic-branch-build-strategies"},
+ )
+
+ if "change-request" in bbs_list:
+ cr = bbs_list["change-request"]
+ cr_elem = XML.SubElement(
+ bbs,
+ "".join([basic_build_strategies, ".ChangeRequestBuildStrategyImpl"]),
+ {"plugin": "basic-branch-build-strategies"},
+ )
+ itoc = cr.get("ignore-target-only-changes", False)
+ XML.SubElement(cr_elem, "ignoreTargetOnlyChanges").text = str(itoc).lower()
+
+ if "named-branches" in bbs_list:
+ named_branch_elem = XML.SubElement(
+ bbs,
+ "".join([basic_build_strategies, ".NamedBranchBuildStrategyImpl"]),
+ {"plugin": "basic-branch-build-strategies"},
+ )
+
+ filters = XML.SubElement(named_branch_elem, "filters")
+
+ for nb in bbs_list["named-branches"]:
+ if "exact-name" in nb:
+ exact_name_elem = XML.SubElement(
+ filters,
+ "".join(
+ [
+ basic_build_strategies,
+ ".NamedBranchBuildStrategyImpl",
+ "_-ExactNameFilter",
+ ]
+ ),
+ )
exact_name_mapping = [
- ('name', 'name', ''),
- ('case-sensitive', 'caseSensitive', False)
+ ("name", "name", ""),
+ ("case-sensitive", "caseSensitive", False),
]
helpers.convert_mapping_to_xml(
exact_name_elem,
- nb['exact-name'],
+ nb["exact-name"],
exact_name_mapping,
- fail_required=False)
-
- if 'regex-name' in nb:
- regex_name_elem = XML.SubElement(filters, ''.join([
- basic_build_strategies,
- '.NamedBranchBuildStrategyImpl',
- '_-RegexNameFilter']))
+ fail_required=False,
+ )
+
+ if "regex-name" in nb:
+ regex_name_elem = XML.SubElement(
+ filters,
+ "".join(
+ [
+ basic_build_strategies,
+ ".NamedBranchBuildStrategyImpl",
+ "_-RegexNameFilter",
+ ]
+ ),
+ )
regex_name_mapping = [
- ('regex', 'regex', '^.*$'),
- ('case-sensitive', 'caseSensitive', False)
+ ("regex", "regex", "^.*$"),
+ ("case-sensitive", "caseSensitive", False),
]
helpers.convert_mapping_to_xml(
- regex_name_elem, nb['regex-name'],
- regex_name_mapping, fail_required=False)
-
- if 'wildcards-name' in nb:
- wildcards_name_elem = XML.SubElement(filters, ''.join([
- basic_build_strategies,
- '.NamedBranchBuildStrategyImpl',
- '_-WildcardsNameFilter']))
+ regex_name_elem,
+ nb["regex-name"],
+ regex_name_mapping,
+ fail_required=False,
+ )
+
+ if "wildcards-name" in nb:
+ wildcards_name_elem = XML.SubElement(
+ filters,
+ "".join(
+ [
+ basic_build_strategies,
+ ".NamedBranchBuildStrategyImpl",
+ "_-WildcardsNameFilter",
+ ]
+ ),
+ )
wildcards_name_mapping = [
- ('includes', 'includes', '*'),
- ('excludes', 'excludes', '')
+ ("includes", "includes", "*"),
+ ("excludes", "excludes", ""),
]
helpers.convert_mapping_to_xml(
wildcards_name_elem,
- nb['wildcards-name'],
+ nb["wildcards-name"],
wildcards_name_mapping,
- fail_required=False)
+ fail_required=False,
+ )
def property_strategies(xml_parent, data):
@@ -1217,91 +1204,140 @@ def property_strategies(xml_parent, data):
<Pipeline+Multibranch+Plugin>`
"""
- valid_prop_strats = [
- 'all-branches',
- 'named-branches'
- ]
+ valid_prop_strats = ["all-branches", "named-branches"]
- basic_property_strategies = 'jenkins.branch'
+ basic_property_strategies = "jenkins.branch"
- prop_strats = data.get('property-strategies', None)
+ prop_strats = data.get("property-strategies", None)
if prop_strats:
for prop_strat in prop_strats:
if prop_strat not in valid_prop_strats:
- raise InvalidAttributeError('property-strategies',
- prop_strat,
- valid_prop_strats)
+ raise InvalidAttributeError(
+ "property-strategies", prop_strat, valid_prop_strats
+ )
if len(prop_strats) > 1:
- raise JenkinsJobsException(
- 'Only one property strategy may be specified')
+ raise JenkinsJobsException("Only one property strategy may be specified")
- all_branches = prop_strats.get('all-branches', None)
- named_branches = prop_strats.get('named-branches', None)
+ all_branches = prop_strats.get("all-branches", None)
+ named_branches = prop_strats.get("named-branches", None)
if all_branches:
- strat_elem = XML.SubElement(xml_parent, 'strategy', {
- 'class': ''.join([basic_property_strategies,
- '.DefaultBranchPropertyStrategy'])})
- props_elem = XML.SubElement(strat_elem, 'properties', {
- 'class': 'java.util.Arrays$ArrayList'})
- props_elem = XML.SubElement(props_elem, 'a', {
- 'class': ''.join([
- basic_property_strategies, '.BranchProperty-array'])})
+ strat_elem = XML.SubElement(
+ xml_parent,
+ "strategy",
+ {
+ "class": "".join(
+ [basic_property_strategies, ".DefaultBranchPropertyStrategy"]
+ )
+ },
+ )
+ props_elem = XML.SubElement(
+ strat_elem, "properties", {"class": "java.util.Arrays$ArrayList"}
+ )
+ props_elem = XML.SubElement(
+ props_elem,
+ "a",
+ {
+ "class": "".join(
+ [basic_property_strategies, ".BranchProperty-array"]
+ )
+ },
+ )
apply_property_strategies(props_elem, all_branches)
elif named_branches:
- strat_elem = XML.SubElement(xml_parent, 'strategy', {
- 'class': ''.join([basic_property_strategies,
- '.NamedExceptionsBranchPropertyStrategy'])})
-
- nbs_defaults = named_branches.get('defaults', None)
+ strat_elem = XML.SubElement(
+ xml_parent,
+ "strategy",
+ {
+ "class": "".join(
+ [
+ basic_property_strategies,
+ ".NamedExceptionsBranchPropertyStrategy",
+ ]
+ )
+ },
+ )
+
+ nbs_defaults = named_branches.get("defaults", None)
if nbs_defaults:
- props_elem = XML.SubElement(strat_elem, 'defaultProperties', {
- 'class': 'java.util.Arrays$ArrayList'})
- props_elem = XML.SubElement(props_elem, 'a', {
- 'class': ''.join([
- basic_property_strategies, '.BranchProperty-array'])})
+ props_elem = XML.SubElement(
+ strat_elem,
+ "defaultProperties",
+ {"class": "java.util.Arrays$ArrayList"},
+ )
+ props_elem = XML.SubElement(
+ props_elem,
+ "a",
+ {
+ "class": "".join(
+ [basic_property_strategies, ".BranchProperty-array"]
+ )
+ },
+ )
apply_property_strategies(props_elem, nbs_defaults)
- nbs_exceptions = named_branches.get('exceptions', None)
+ nbs_exceptions = named_branches.get("exceptions", None)
if nbs_exceptions:
- props_elem = XML.SubElement(strat_elem, 'namedExceptions', {
- 'class': 'java.util.Arrays$ArrayList'})
- props_elem = XML.SubElement(props_elem, 'a', {
- 'class': ''.join([
- basic_property_strategies,
- '.NamedExceptionsBranchPropertyStrategy$Named-array'
- ])})
+ props_elem = XML.SubElement(
+ strat_elem,
+ "namedExceptions",
+ {"class": "java.util.Arrays$ArrayList"},
+ )
+ props_elem = XML.SubElement(
+ props_elem,
+ "a",
+ {
+ "class": "".join(
+ [
+ basic_property_strategies,
+ ".NamedExceptionsBranchPropertyStrategy$Named-array",
+ ]
+ )
+ },
+ )
for named_exception in nbs_exceptions:
- named_exception = named_exception.get('exception', None)
+ named_exception = named_exception.get("exception", None)
if not named_exception:
continue
- exc_elem = XML.SubElement(props_elem, ''.join([
- basic_property_strategies,
- '.NamedExceptionsBranchPropertyStrategy_-Named']))
+ exc_elem = XML.SubElement(
+ props_elem,
+ "".join(
+ [
+ basic_property_strategies,
+ ".NamedExceptionsBranchPropertyStrategy_-Named",
+ ]
+ ),
+ )
- ne_branch_name = named_exception.get('branch-name', None)
+ ne_branch_name = named_exception.get("branch-name", None)
if ne_branch_name is not None:
- XML.SubElement(exc_elem, 'name').text = ne_branch_name
+ XML.SubElement(exc_elem, "name").text = ne_branch_name
- ne_properties = named_exception.get('properties', None)
+ ne_properties = named_exception.get("properties", None)
if ne_properties:
- exc_elem = XML.SubElement(exc_elem, 'props', {
- 'class': 'java.util.Arrays$ArrayList'})
- exc_elem = XML.SubElement(exc_elem, 'a', {
- 'class': ''.join([
- basic_property_strategies,
- '.BranchProperty-array'])})
+ exc_elem = XML.SubElement(
+ exc_elem, "props", {"class": "java.util.Arrays$ArrayList"}
+ )
+ exc_elem = XML.SubElement(
+ exc_elem,
+ "a",
+ {
+ "class": "".join(
+ [basic_property_strategies, ".BranchProperty-array"]
+ )
+ },
+ )
apply_property_strategies(exc_elem, ne_properties)
@@ -1310,32 +1346,34 @@ def apply_property_strategies(props_elem, props_list):
# globally (all-branches), defaults (named-branches), exceptions
# (also named-branches)
- basic_property_strategies = 'jenkins.branch'
- workflow_multibranch = 'org.jenkinsci.plugins.workflow.multibranch'
+ basic_property_strategies = "jenkins.branch"
+ workflow_multibranch = "org.jenkinsci.plugins.workflow.multibranch"
# Valid options for the pipeline branch durability override.
- pbdo_map = collections.OrderedDict([
- ("max-survivability", "MAX_SURVIVABILITY"),
- ("performance-optimized", "PERFORMANCE_OPTIMIZED"),
- ("survivable-nonatomic", "SURVIVABLE_NONATOMIC"),
- ])
+ pbdo_map = collections.OrderedDict(
+ [
+ ("max-survivability", "MAX_SURVIVABILITY"),
+ ("performance-optimized", "PERFORMANCE_OPTIMIZED"),
+ ("survivable-nonatomic", "SURVIVABLE_NONATOMIC"),
+ ]
+ )
for dbs_list in props_list:
- if dbs_list.get('suppress-scm-triggering', False):
- XML.SubElement(props_elem, ''.join([
- basic_property_strategies, '.NoTriggerBranchProperty']))
+ if dbs_list.get("suppress-scm-triggering", False):
+ XML.SubElement(
+ props_elem,
+ "".join([basic_property_strategies, ".NoTriggerBranchProperty"]),
+ )
- pbdo_val = dbs_list.get(
- 'pipeline-branch-durability-override', None)
+ pbdo_val = dbs_list.get("pipeline-branch-durability-override", None)
if pbdo_val:
if not pbdo_map.get(pbdo_val):
raise InvalidAttributeError(
- 'pipeline-branch-durability-override',
- pbdo_val,
- pbdo_map.keys())
- pbdo_elem = XML.SubElement(props_elem, ''.join([
- workflow_multibranch,
- '.DurabilityHintBranchProperty']), {
- 'plugin': 'workflow-multibranch'})
- XML.SubElement(pbdo_elem, 'hint').text = pbdo_map.get(
- pbdo_val)
+ "pipeline-branch-durability-override", pbdo_val, pbdo_map.keys()
+ )
+ pbdo_elem = XML.SubElement(
+ props_elem,
+ "".join([workflow_multibranch, ".DurabilityHintBranchProperty"]),
+ {"plugin": "workflow-multibranch"},
+ )
+ XML.SubElement(pbdo_elem, "hint").text = pbdo_map.get(pbdo_val)
diff --git a/jenkins_jobs/modules/project_multijob.py b/jenkins_jobs/modules/project_multijob.py
index 63c21e4e..6536432b 100644
--- a/jenkins_jobs/modules/project_multijob.py
+++ b/jenkins_jobs/modules/project_multijob.py
@@ -59,6 +59,7 @@ class MultiJob(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- xml_parent = XML.Element('com.tikal.jenkins.plugins.multijob.'
- 'MultiJobProject')
+ xml_parent = XML.Element(
+ "com.tikal.jenkins.plugins.multijob." "MultiJobProject"
+ )
return xml_parent
diff --git a/jenkins_jobs/modules/project_pipeline.py b/jenkins_jobs/modules/project_pipeline.py
index 6b90860a..3248c30d 100644
--- a/jenkins_jobs/modules/project_pipeline.py
+++ b/jenkins_jobs/modules/project_pipeline.py
@@ -82,31 +82,38 @@ import jenkins_jobs.modules.base
class Pipeline(jenkins_jobs.modules.base.Base):
sequence = 0
- error_msg = ("You cannot declare both 'dsl' and 'pipeline-scm' on a "
- "pipeline job")
+ error_msg = "You cannot declare both 'dsl' and 'pipeline-scm' on a " "pipeline job"
def root_xml(self, data):
- xml_parent = XML.Element('flow-definition',
- {'plugin': 'workflow-job'})
- if 'dsl' in data and 'pipeline-scm' in data:
+ xml_parent = XML.Element("flow-definition", {"plugin": "workflow-job"})
+ if "dsl" in data and "pipeline-scm" in data:
raise JenkinsJobsException(self.error_msg)
- if 'dsl' in data:
- xml_definition = XML.SubElement(xml_parent, 'definition',
- {'plugin': 'workflow-cps',
- 'class': 'org.jenkinsci.plugins.'
- 'workflow.cps.CpsFlowDefinition'})
- XML.SubElement(xml_definition, 'script').text = data['dsl']
- elif 'pipeline-scm' in data:
- xml_definition = XML.SubElement(xml_parent, 'definition', {
- 'plugin': 'workflow-cps',
- 'class': 'org.jenkinsci.plugins.workflow.cps.'
- 'CpsScmFlowDefinition'})
+ if "dsl" in data:
+ xml_definition = XML.SubElement(
+ xml_parent,
+ "definition",
+ {
+ "plugin": "workflow-cps",
+ "class": "org.jenkinsci.plugins." "workflow.cps.CpsFlowDefinition",
+ },
+ )
+ XML.SubElement(xml_definition, "script").text = data["dsl"]
+ elif "pipeline-scm" in data:
+ xml_definition = XML.SubElement(
+ xml_parent,
+ "definition",
+ {
+ "plugin": "workflow-cps",
+ "class": "org.jenkinsci.plugins.workflow.cps."
+ "CpsScmFlowDefinition",
+ },
+ )
else:
- raise JenkinsJobsException("Either 'dsl' or 'pipeline-scm' "
- "is required for pipeline job")
+ raise JenkinsJobsException(
+ "Either 'dsl' or 'pipeline-scm' " "is required for pipeline job"
+ )
- needs_workspace = data.get('sandbox', False)
- XML.SubElement(xml_definition, 'sandbox').text = str(
- needs_workspace).lower()
+ needs_workspace = data.get("sandbox", False)
+ XML.SubElement(xml_definition, "sandbox").text = str(needs_workspace).lower()
return xml_parent
diff --git a/jenkins_jobs/modules/project_workflow.py b/jenkins_jobs/modules/project_workflow.py
index 58d97b33..731f7257 100644
--- a/jenkins_jobs/modules/project_workflow.py
+++ b/jenkins_jobs/modules/project_workflow.py
@@ -59,22 +59,21 @@ class Workflow(jenkins_jobs.modules.base.Base):
def root_xml(self, data):
logger = logging.getLogger(__name__)
- logger.warning(
- "Workflow job type is deprecated, please use Pipeline job type"
+ logger.warning("Workflow job type is deprecated, please use Pipeline job type")
+
+ xml_parent = XML.Element("flow-definition", {"plugin": "workflow-job"})
+ xml_definition = XML.SubElement(
+ xml_parent,
+ "definition",
+ {
+ "plugin": "workflow-cps",
+ "class": "org.jenkinsci.plugins." "workflow.cps.CpsFlowDefinition",
+ },
)
- xml_parent = XML.Element('flow-definition',
- {'plugin': 'workflow-job'})
- xml_definition = XML.SubElement(xml_parent, 'definition',
- {'plugin': 'workflow-cps',
- 'class': 'org.jenkinsci.plugins.'
- 'workflow.cps.CpsFlowDefinition'})
-
- mapping = [
- ('dsl', 'script', None),
- ('sandbox', 'sandbox', False),
- ]
+ mapping = [("dsl", "script", None), ("sandbox", "sandbox", False)]
helpers.convert_mapping_to_xml(
- xml_definition, data, mapping, fail_required=True)
+ xml_definition, data, mapping, fail_required=True
+ )
return xml_parent
diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py
index 2907ec4f..211f5393 100644
--- a/jenkins_jobs/modules/properties.py
+++ b/jenkins_jobs/modules/properties.py
@@ -59,16 +59,17 @@ def builds_chain_fingerprinter(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/fingerprinter.yaml
:language: yaml
"""
- fingerprinter = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.'
- 'buildschainfingerprinter.'
- 'AutomaticFingerprintJobProperty')
+ fingerprinter = XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins."
+ "buildschainfingerprinter."
+ "AutomaticFingerprintJobProperty",
+ )
mapping = [
- ('per-builds-chain', 'isPerBuildsChainEnabled', False),
- ('per-job-chain', 'isPerJobsChainEnabled', False),
+ ("per-builds-chain", "isPerBuildsChainEnabled", False),
+ ("per-job-chain", "isPerJobsChainEnabled", False),
]
- helpers.convert_mapping_to_xml(
- fingerprinter, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(fingerprinter, data, mapping, fail_required=True)
def ownership(registry, xml_parent, data):
@@ -87,16 +88,17 @@ def ownership(registry, xml_parent, data):
"""
ownership_plugin = XML.SubElement(
xml_parent,
- 'com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty')
- ownership = XML.SubElement(ownership_plugin, 'ownership')
- owner = str(data.get('enabled', True)).lower()
- XML.SubElement(ownership, 'ownershipEnabled').text = owner
+ "com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty",
+ )
+ ownership = XML.SubElement(ownership_plugin, "ownership")
+ owner = str(data.get("enabled", True)).lower()
+ XML.SubElement(ownership, "ownershipEnabled").text = owner
- XML.SubElement(ownership, 'primaryOwnerId').text = data.get('owner')
+ XML.SubElement(ownership, "primaryOwnerId").text = data.get("owner")
- coownersIds = XML.SubElement(ownership, 'coownersIds')
- for coowner in data.get('co-owners', []):
- XML.SubElement(coownersIds, 'string').text = coowner
+ coownersIds = XML.SubElement(ownership, "coownersIds")
+ for coowner in data.get("co-owners", []):
+ XML.SubElement(coownersIds, "string").text = coowner
def promoted_build(registry, xml_parent, data):
@@ -115,13 +117,14 @@ def promoted_build(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/promoted_build.yaml
:language: yaml
"""
- promoted = XML.SubElement(xml_parent, 'hudson.plugins.promoted__builds.'
- 'JobPropertyImpl')
- names = data.get('names', [])
+ promoted = XML.SubElement(
+ xml_parent, "hudson.plugins.promoted__builds." "JobPropertyImpl"
+ )
+ names = data.get("names", [])
if names:
- active_processes = XML.SubElement(promoted, 'activeProcessNames')
+ active_processes = XML.SubElement(promoted, "activeProcessNames")
for n in names:
- XML.SubElement(active_processes, 'string').text = str(n)
+ XML.SubElement(active_processes, "string").text = str(n)
def gitbucket(parser, xml_parent, data):
@@ -143,15 +146,12 @@ def gitbucket(parser, xml_parent, data):
:language: yaml
"""
gitbucket = XML.SubElement(
- xml_parent, 'org.jenkinsci.plugins.gitbucket.GitBucketProjectProperty')
- gitbucket.set('plugin', 'gitbucket')
+ xml_parent, "org.jenkinsci.plugins.gitbucket.GitBucketProjectProperty"
+ )
+ gitbucket.set("plugin", "gitbucket")
- mapping = [
- ('url', 'url', None),
- ('link-enabled', 'linkEnabled', False),
- ]
- helpers.convert_mapping_to_xml(
- gitbucket, data, mapping, fail_required=True)
+ mapping = [("url", "url", None), ("link-enabled", "linkEnabled", False)]
+ helpers.convert_mapping_to_xml(gitbucket, data, mapping, fail_required=True)
def github(registry, xml_parent, data):
@@ -174,13 +174,11 @@ def github(registry, xml_parent, data):
:language: yaml
"""
github = XML.SubElement(
- xml_parent, 'com.coravy.hudson.plugins.github.GithubProjectProperty')
- github.set('plugin', 'github')
+ xml_parent, "com.coravy.hudson.plugins.github.GithubProjectProperty"
+ )
+ github.set("plugin", "github")
- mapping = [
- ('url', 'projectUrl', None),
- ('display-name', 'displayName', ''),
- ]
+ mapping = [("url", "projectUrl", None), ("display-name", "displayName", "")]
helpers.convert_mapping_to_xml(github, data, mapping, fail_required=True)
@@ -197,12 +195,11 @@ def gitlab(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/gitlab.yaml
:language: yaml
"""
- gitlab = XML.SubElement(xml_parent,
- 'com.dabsquared.gitlabjenkins.connection.'
- 'GitLabConnectionProperty')
- mapping = [
- ('connection', 'gitLabConnection', None),
- ]
+ gitlab = XML.SubElement(
+ xml_parent,
+ "com.dabsquared.gitlabjenkins.connection." "GitLabConnectionProperty",
+ )
+ mapping = [("connection", "gitLabConnection", None)]
helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
@@ -219,12 +216,10 @@ def gitlab_logo(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/gitlab-logo.yaml
:language: yaml
"""
- logo = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.gitlablogo.'
- 'GitlabLogoProperty')
- mapping = [
- ('repository-name', 'repositoryName', None)
- ]
+ logo = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.gitlablogo." "GitlabLogoProperty"
+ )
+ mapping = [("repository-name", "repositoryName", None)]
helpers.convert_mapping_to_xml(logo, data, mapping, fail_required=True)
@@ -238,9 +233,7 @@ def disk_usage(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/disk-usage.yaml
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'hudson.plugins.disk__usage.'
- 'DiskUsageProperty')
+ XML.SubElement(xml_parent, "hudson.plugins.disk__usage." "DiskUsageProperty")
def least_load(registry, xml_parent, data):
@@ -255,12 +248,11 @@ def least_load(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/least-load002.yaml
:language: yaml
"""
- least = XML.SubElement(xml_parent,
- 'org.bstick12.jenkinsci.plugins.leastload.'
- 'LeastLoadDisabledProperty')
- mapping = [
- ('disabled', 'leastLoadDisabled', True),
- ]
+ least = XML.SubElement(
+ xml_parent,
+ "org.bstick12.jenkinsci.plugins.leastload." "LeastLoadDisabledProperty",
+ )
+ mapping = [("disabled", "leastLoadDisabled", True)]
helpers.convert_mapping_to_xml(least, data, mapping, fail_required=True)
@@ -288,43 +280,41 @@ def throttle(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/throttle001.yaml
:language: yaml
"""
- throttle = XML.SubElement(xml_parent,
- 'hudson.plugins.throttleconcurrents.'
- 'ThrottleJobProperty')
+ throttle = XML.SubElement(
+ xml_parent, "hudson.plugins.throttleconcurrents." "ThrottleJobProperty"
+ )
mapping = [
- ('max-per-node', 'maxConcurrentPerNode', '0'),
- ('max-total', 'maxConcurrentTotal', '0'),
- ('enabled', 'throttleEnabled', True),
+ ("max-per-node", "maxConcurrentPerNode", "0"),
+ ("max-total", "maxConcurrentTotal", "0"),
+ ("enabled", "throttleEnabled", True),
]
helpers.convert_mapping_to_xml(throttle, data, mapping, fail_required=True)
- cat = data.get('categories', [])
+ cat = data.get("categories", [])
if cat:
- cn = XML.SubElement(throttle, 'categories')
+ cn = XML.SubElement(throttle, "categories")
for c in cat:
- XML.SubElement(cn, 'string').text = str(c)
+ XML.SubElement(cn, "string").text = str(c)
- options_list = ('category', 'project')
- option = data.get('option')
+ options_list = ("category", "project")
+ option = data.get("option")
if option not in options_list:
- raise InvalidAttributeError('option', option, options_list)
+ raise InvalidAttributeError("option", option, options_list)
mapping = [
- ('', 'throttleOption', option),
- ('', 'configVersion', '1'),
- ('parameters-limit', 'limitOneJobWithMatchingParams', False),
+ ("", "throttleOption", option),
+ ("", "configVersion", "1"),
+ ("parameters-limit", "limitOneJobWithMatchingParams", False),
]
helpers.convert_mapping_to_xml(throttle, data, mapping, fail_required=True)
- matrixopt = XML.SubElement(throttle, 'matrixOptions')
+ matrixopt = XML.SubElement(throttle, "matrixOptions")
mapping = [
- ('matrix-builds', 'throttleMatrixBuilds', True),
- ('matrix-configs', 'throttleMatrixConfigurations', False),
+ ("matrix-builds", "throttleMatrixBuilds", True),
+ ("matrix-configs", "throttleMatrixConfigurations", False),
]
- helpers.convert_mapping_to_xml(
- matrixopt, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(matrixopt, data, mapping, fail_required=True)
- params_to_use = data.get('parameters-check-list', [])
- XML.SubElement(throttle, 'paramsToUseForLimit').text = ",".join(
- params_to_use)
+ params_to_use = data.get("parameters-check-list", [])
+ XML.SubElement(throttle, "paramsToUseForLimit").text = ",".join(params_to_use)
def branch_api(registry, xml_parent, data):
@@ -354,16 +344,17 @@ def branch_api(registry, xml_parent, data):
/../../tests/properties/fixtures/branch-api-full.yaml
:language: yaml
"""
- branch = XML.SubElement(xml_parent, 'jenkins.branch.'
- 'RateLimitBranchProperty_-JobPropertyImpl')
- branch.set('plugin', 'branch-api')
+ branch = XML.SubElement(
+ xml_parent, "jenkins.branch." "RateLimitBranchProperty_-JobPropertyImpl"
+ )
+ branch.set("plugin", "branch-api")
- valid_time_periods = ['Hour', 'Day', 'Week', 'Month', 'Year']
+ valid_time_periods = ["Hour", "Day", "Week", "Month", "Year"]
mapping = [
- ('time-period', 'durationName', 'Hour', valid_time_periods),
- ('number-of-builds', 'count', 1),
- ('skip-rate-limit', 'userBoost', False),
+ ("time-period", "durationName", "Hour", valid_time_periods),
+ ("number-of-builds", "count", 1),
+ ("skip-rate-limit", "userBoost", False),
]
helpers.convert_mapping_to_xml(branch, data, mapping, fail_required=True)
@@ -383,19 +374,16 @@ def sidebar(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/sidebar02.yaml
:language: yaml
"""
- sidebar = xml_parent.find('hudson.plugins.sidebar__link.ProjectLinks')
+ sidebar = xml_parent.find("hudson.plugins.sidebar__link.ProjectLinks")
if sidebar is None:
- sidebar = XML.SubElement(xml_parent,
- 'hudson.plugins.sidebar__link.ProjectLinks')
- links = XML.SubElement(sidebar, 'links')
+ sidebar = XML.SubElement(
+ xml_parent, "hudson.plugins.sidebar__link.ProjectLinks"
+ )
+ links = XML.SubElement(sidebar, "links")
else:
- links = sidebar.find('links')
- action = XML.SubElement(links, 'hudson.plugins.sidebar__link.LinkAction')
- mapping = [
- ('url', 'url', ''),
- ('text', 'text', ''),
- ('icon', 'icon', ''),
- ]
+ links = sidebar.find("links")
+ action = XML.SubElement(links, "hudson.plugins.sidebar__link.LinkAction")
+ mapping = [("url", "url", ""), ("text", "text", ""), ("icon", "icon", "")]
helpers.convert_mapping_to_xml(action, data, mapping, fail_required=True)
@@ -423,43 +411,40 @@ def inject(registry, xml_parent, data):
:language: yaml
"""
- inject = XML.SubElement(xml_parent,
- 'EnvInjectJobProperty')
- info = XML.SubElement(inject, 'info')
+ inject = XML.SubElement(xml_parent, "EnvInjectJobProperty")
+ info = XML.SubElement(inject, "info")
mapping = [
- ('properties-file', 'propertiesFilePath', None),
- ('properties-content', 'propertiesContent', None),
- ('script-file', 'scriptFilePath', None),
- ('script-content', 'scriptContent', None),
- ('load-from-master', 'loadFilesFromMaster', False),
+ ("properties-file", "propertiesFilePath", None),
+ ("properties-content", "propertiesContent", None),
+ ("script-file", "scriptFilePath", None),
+ ("script-content", "scriptContent", None),
+ ("load-from-master", "loadFilesFromMaster", False),
]
helpers.convert_mapping_to_xml(info, data, mapping, fail_required=False)
# determine version of plugin
plugin_info = registry.get_plugin_info("Groovy")
- version = pkg_resources.parse_version(plugin_info.get('version', '0'))
+ version = pkg_resources.parse_version(plugin_info.get("version", "0"))
if version >= pkg_resources.parse_version("2.0.0"):
- secure_groovy_script = XML.SubElement(info, 'secureGroovyScript')
+ secure_groovy_script = XML.SubElement(info, "secureGroovyScript")
mapping = [
- ('groovy-content', 'script', None),
- ('groovy-sandbox', 'sandbox', False),
+ ("groovy-content", "script", None),
+ ("groovy-sandbox", "sandbox", False),
]
- helpers.convert_mapping_to_xml(secure_groovy_script, data, mapping,
- fail_required=False)
+ helpers.convert_mapping_to_xml(
+ secure_groovy_script, data, mapping, fail_required=False
+ )
else:
- mapping = [
- ('groovy-content', 'groovyScriptContent', None),
- ]
- helpers.convert_mapping_to_xml(info, data, mapping,
- fail_required=False)
+ mapping = [("groovy-content", "groovyScriptContent", None)]
+ helpers.convert_mapping_to_xml(info, data, mapping, fail_required=False)
mapping = [
- ('enabled', 'on', True),
- ('keep-system-variables', 'keepJenkinsSystemVariables', True),
- ('keep-build-variables', 'keepBuildVariables', True),
- ('override-build-parameters', 'overrideBuildParameters', False),
+ ("enabled", "on", True),
+ ("keep-system-variables", "keepJenkinsSystemVariables", True),
+ ("keep-build-variables", "keepBuildVariables", True),
+ ("override-build-parameters", "overrideBuildParameters", False),
]
helpers.convert_mapping_to_xml(inject, data, mapping, fail_required=True)
@@ -479,11 +464,12 @@ def authenticated_build(registry, xml_parent, data):
"""
# TODO: generalize this
- security = XML.SubElement(xml_parent,
- 'hudson.security.'
- 'AuthorizationMatrixProperty')
- XML.SubElement(security, 'permission').text = (
- 'hudson.model.Item.Build:authenticated')
+ security = XML.SubElement(
+ xml_parent, "hudson.security." "AuthorizationMatrixProperty"
+ )
+ XML.SubElement(
+ security, "permission"
+ ).text = "hudson.model.Item.Build:authenticated"
def authorization(registry, xml_parent, data):
@@ -523,38 +509,39 @@ def authorization(registry, xml_parent, data):
:language: yaml
"""
- credentials = 'com.cloudbees.plugins.credentials.CredentialsProvider.'
- ownership = 'com.synopsys.arc.jenkins.plugins.ownership.OwnershipPlugin.'
+ credentials = "com.cloudbees.plugins.credentials.CredentialsProvider."
+ ownership = "com.synopsys.arc.jenkins.plugins.ownership.OwnershipPlugin."
mapping = {
- 'credentials-create': ''.join((credentials, 'Create')),
- 'credentials-delete': ''.join((credentials, 'Delete')),
- 'credentials-manage-domains': ''.join((credentials, 'ManageDomains')),
- 'credentials-update': ''.join((credentials, 'Update')),
- 'credentials-view': ''.join((credentials, 'View')),
- 'job-build': 'hudson.model.Item.Build',
- 'job-cancel': 'hudson.model.Item.Cancel',
- 'job-configure': 'hudson.model.Item.Configure',
- 'job-delete': 'hudson.model.Item.Delete',
- 'job-discover': 'hudson.model.Item.Discover',
- 'job-extended-read': 'hudson.model.Item.ExtendedRead',
- 'job-move': 'hudson.model.Item.Move',
- 'job-read': 'hudson.model.Item.Read',
- 'job-status': 'hudson.model.Item.ViewStatus',
- 'job-workspace': 'hudson.model.Item.Workspace',
- 'ownership-jobs': ''.join((ownership, 'Jobs')),
- 'run-delete': 'hudson.model.Run.Delete',
- 'run-replay': 'hudson.model.Run.Replay',
- 'run-update': 'hudson.model.Run.Update',
- 'scm-tag': 'hudson.scm.SCM.Tag',
+ "credentials-create": "".join((credentials, "Create")),
+ "credentials-delete": "".join((credentials, "Delete")),
+ "credentials-manage-domains": "".join((credentials, "ManageDomains")),
+ "credentials-update": "".join((credentials, "Update")),
+ "credentials-view": "".join((credentials, "View")),
+ "job-build": "hudson.model.Item.Build",
+ "job-cancel": "hudson.model.Item.Cancel",
+ "job-configure": "hudson.model.Item.Configure",
+ "job-delete": "hudson.model.Item.Delete",
+ "job-discover": "hudson.model.Item.Discover",
+ "job-extended-read": "hudson.model.Item.ExtendedRead",
+ "job-move": "hudson.model.Item.Move",
+ "job-read": "hudson.model.Item.Read",
+ "job-status": "hudson.model.Item.ViewStatus",
+ "job-workspace": "hudson.model.Item.Workspace",
+ "ownership-jobs": "".join((ownership, "Jobs")),
+ "run-delete": "hudson.model.Run.Delete",
+ "run-replay": "hudson.model.Run.Replay",
+ "run-update": "hudson.model.Run.Update",
+ "scm-tag": "hudson.scm.SCM.Tag",
}
if data:
- matrix = XML.SubElement(xml_parent,
- 'hudson.security.AuthorizationMatrixProperty')
+ matrix = XML.SubElement(
+ xml_parent, "hudson.security.AuthorizationMatrixProperty"
+ )
for (username, perms) in data.items():
for perm in perms:
- pe = XML.SubElement(matrix, 'permission')
+ pe = XML.SubElement(matrix, "permission")
try:
pe.text = "{0}:{1}".format(mapping[perm], username)
except KeyError:
@@ -577,39 +564,32 @@ def priority_sorter(registry, xml_parent, data):
/../../tests/properties/fixtures/priority_sorter002.yaml
:language: yaml
"""
- plugin_info = registry.get_plugin_info('PrioritySorter')
- version = pkg_resources.parse_version(plugin_info.get('version', '0'))
+ plugin_info = registry.get_plugin_info("PrioritySorter")
+ version = pkg_resources.parse_version(plugin_info.get("version", "0"))
if version >= pkg_resources.parse_version("3.0"):
priority_sorter_tag = XML.SubElement(
xml_parent,
- 'jenkins.advancedqueue.jobinclusion.'
- 'strategy.JobInclusionJobProperty')
+ "jenkins.advancedqueue.jobinclusion." "strategy.JobInclusionJobProperty",
+ )
- mapping = [
- ('use', 'useJobGroup', True),
- ('priority', 'jobGroupName', None)
- ]
+ mapping = [("use", "useJobGroup", True), ("priority", "jobGroupName", None)]
elif version >= pkg_resources.parse_version("2.0"):
- priority_sorter_tag = XML.SubElement(xml_parent,
- 'jenkins.advancedqueue.priority.'
- 'strategy.PriorityJobProperty')
+ priority_sorter_tag = XML.SubElement(
+ xml_parent, "jenkins.advancedqueue.priority." "strategy.PriorityJobProperty"
+ )
- mapping = [
- ('use', 'useJobPriority', True),
- ('priority', 'priority', None)
- ]
+ mapping = [("use", "useJobPriority", True), ("priority", "priority", None)]
else:
- priority_sorter_tag = XML.SubElement(xml_parent,
- 'hudson.queueSorter.'
- 'PrioritySorterJobProperty')
+ priority_sorter_tag = XML.SubElement(
+ xml_parent, "hudson.queueSorter." "PrioritySorterJobProperty"
+ )
- mapping = [
- ('priority', 'priority', None),
- ]
+ mapping = [("priority", "priority", None)]
helpers.convert_mapping_to_xml(
- priority_sorter_tag, data, mapping, fail_required=True)
+ priority_sorter_tag, data, mapping, fail_required=True
+ )
def build_blocker(registry, xml_parent, data):
@@ -643,25 +623,25 @@ def build_blocker(registry, xml_parent, data):
/../../tests/properties/fixtures/build-blocker-full.yaml
:language: yaml
"""
- blocker = XML.SubElement(xml_parent,
- 'hudson.plugins.'
- 'buildblocker.BuildBlockerProperty')
- if data is None or 'blocking-jobs' not in data:
- raise JenkinsJobsException('blocking-jobs field is missing')
- elif data.get('blocking-jobs', None) is None:
- raise JenkinsJobsException('blocking-jobs list must not be empty')
-
- jobs = ''
+ blocker = XML.SubElement(
+ xml_parent, "hudson.plugins." "buildblocker.BuildBlockerProperty"
+ )
+ if data is None or "blocking-jobs" not in data:
+ raise JenkinsJobsException("blocking-jobs field is missing")
+ elif data.get("blocking-jobs", None) is None:
+ raise JenkinsJobsException("blocking-jobs list must not be empty")
+
+ jobs = ""
for setting, value in data.items():
- if setting == 'blocking-jobs':
- jobs = '\n'.join(value)
- block_level_types = ['GLOBAL', 'NODE']
- queue_scan_types = ['DISABLED', 'ALL', 'BUILDABLE']
+ if setting == "blocking-jobs":
+ jobs = "\n".join(value)
+ block_level_types = ["GLOBAL", "NODE"]
+ queue_scan_types = ["DISABLED", "ALL", "BUILDABLE"]
mapping = [
- ('use-build-blocker', 'useBuildBlocker', True),
- ('', 'blockingJobs', jobs),
- ('block-level', 'blockLevel', 'GLOBAL', block_level_types),
- ('queue-scanning', 'scanQueueFor', 'DISABLED', queue_scan_types),
+ ("use-build-blocker", "useBuildBlocker", True),
+ ("", "blockingJobs", jobs),
+ ("block-level", "blockLevel", "GLOBAL", block_level_types),
+ ("queue-scanning", "scanQueueFor", "DISABLED", queue_scan_types),
]
helpers.convert_mapping_to_xml(blocker, data, mapping, fail_required=True)
@@ -684,17 +664,16 @@ def copyartifact(registry, xml_parent, data):
:language: yaml
"""
- copyartifact = XML.SubElement(xml_parent,
- 'hudson.plugins.'
- 'copyartifact.'
- 'CopyArtifactPermissionProperty',
- plugin='copyartifact')
- if not data or not data.get('projects', None):
- raise JenkinsJobsException("projects string must exist and "
- "not be empty")
- projectlist = XML.SubElement(copyartifact, 'projectNameList')
- for project in str(data.get('projects')).split(','):
- XML.SubElement(projectlist, 'string').text = project
+ copyartifact = XML.SubElement(
+ xml_parent,
+ "hudson.plugins." "copyartifact." "CopyArtifactPermissionProperty",
+ plugin="copyartifact",
+ )
+ if not data or not data.get("projects", None):
+ raise JenkinsJobsException("projects string must exist and " "not be empty")
+ projectlist = XML.SubElement(copyartifact, "projectNameList")
+ for project in str(data.get("projects")).split(","):
+ XML.SubElement(projectlist, "string").text = project
def batch_tasks(registry, xml_parent, data):
@@ -722,18 +701,12 @@ def batch_tasks(registry, xml_parent, data):
:language: yaml
"""
- pdef = XML.SubElement(xml_parent,
- 'hudson.plugins.batch__task.BatchTaskProperty')
- tasks = XML.SubElement(pdef, 'tasks')
+ pdef = XML.SubElement(xml_parent, "hudson.plugins.batch__task.BatchTaskProperty")
+ tasks = XML.SubElement(pdef, "tasks")
for task in data:
- batch_task = XML.SubElement(tasks,
- 'hudson.plugins.batch__task.BatchTask')
- mapping = [
- ('name', 'name', None),
- ('script', 'script', None),
- ]
- helpers.convert_mapping_to_xml(
- batch_task, task, mapping, fail_required=True)
+ batch_task = XML.SubElement(tasks, "hudson.plugins.batch__task.BatchTask")
+ mapping = [("name", "name", None), ("script", "script", None)]
+ helpers.convert_mapping_to_xml(batch_task, task, mapping, fail_required=True)
def heavy_job(registry, xml_parent, data):
@@ -752,12 +725,10 @@ def heavy_job(registry, xml_parent, data):
:language: yaml
"""
- heavyjob = XML.SubElement(xml_parent,
- 'hudson.plugins.'
- 'heavy__job.HeavyJobProperty')
- mapping = [
- ('weight', 'weight', 1),
- ]
+ heavyjob = XML.SubElement(
+ xml_parent, "hudson.plugins." "heavy__job.HeavyJobProperty"
+ )
+ mapping = [("weight", "weight", 1)]
helpers.convert_mapping_to_xml(heavyjob, data, mapping, fail_required=True)
@@ -782,18 +753,18 @@ def slave_utilization(registry, xml_parent, data):
:language: yaml
"""
utilization = XML.SubElement(
- xml_parent, 'com.suryagaddipati.jenkins.SlaveUtilizationProperty')
+ xml_parent, "com.suryagaddipati.jenkins.SlaveUtilizationProperty"
+ )
- percent = int(data.get('slave-percentage', 0))
+ percent = int(data.get("slave-percentage", 0))
exclusive_node_access = True if percent else False
mapping = [
- ('', 'needsExclusiveAccessToNode', exclusive_node_access),
- ('', 'slaveUtilizationPercentage', percent),
- ('single-instance-per-slave', 'singleInstancePerSlave', False),
+ ("", "needsExclusiveAccessToNode", exclusive_node_access),
+ ("", "slaveUtilizationPercentage", percent),
+ ("single-instance-per-slave", "singleInstancePerSlave", False),
]
- helpers.convert_mapping_to_xml(
- utilization, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(utilization, data, mapping, fail_required=True)
def delivery_pipeline(registry, xml_parent, data):
@@ -818,14 +789,13 @@ def delivery_pipeline(registry, xml_parent, data):
/../../tests/properties/fixtures/delivery-pipeline-full.yaml
:language: yaml
"""
- pipeline = XML.SubElement(
- xml_parent, 'se.diabol.jenkins.pipeline.PipelineProperty')
- pipeline.set('plugin', 'delivery-pipeline-plugin')
+ pipeline = XML.SubElement(xml_parent, "se.diabol.jenkins.pipeline.PipelineProperty")
+ pipeline.set("plugin", "delivery-pipeline-plugin")
mapping = [
- ('stage', 'stageName', ''),
- ('task', 'taskName', ''),
- ('description', 'descriptionTemplate', ''),
+ ("stage", "stageName", ""),
+ ("task", "taskName", ""),
+ ("description", "descriptionTemplate", ""),
]
helpers.convert_mapping_to_xml(pipeline, data, mapping, fail_required=True)
@@ -846,14 +816,12 @@ def zeromq_event(registry, xml_parent, data):
"""
- zmq_event = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.'
- 'ZMQEventPublisher.HudsonNotificationProperty')
- mapping = [
- ('', 'enabled', True),
- ]
- helpers.convert_mapping_to_xml(
- zmq_event, data, mapping, fail_required=True)
+ zmq_event = XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins." "ZMQEventPublisher.HudsonNotificationProperty",
+ )
+ mapping = [("", "enabled", True)]
+ helpers.convert_mapping_to_xml(zmq_event, data, mapping, fail_required=True)
def slack(registry, xml_parent, data):
@@ -896,39 +864,36 @@ def slack(registry, xml_parent, data):
"""
logger = logging.getLogger(__name__)
- plugin_info = registry.get_plugin_info('Slack Notification Plugin')
- plugin_ver = pkg_resources.parse_version(plugin_info.get('version', "0"))
+ plugin_info = registry.get_plugin_info("Slack Notification Plugin")
+ plugin_ver = pkg_resources.parse_version(plugin_info.get("version", "0"))
if plugin_ver >= pkg_resources.parse_version("2.0"):
- logger.warning(
- "properties section is not used with plugin version >= 2.0",
- )
+ logger.warning("properties section is not used with plugin version >= 2.0")
mapping = (
- ('notify-start', 'startNotification', False),
- ('notify-success', 'notifySuccess', False),
- ('notify-aborted', 'notifyAborted', False),
- ('notify-not-built', 'notifyNotBuilt', False),
- ('notify-unstable', 'notifyUnstable', False),
- ('notify-failure', 'notifyFailure', False),
- ('notify-back-to-normal', 'notifyBackToNormal', False),
- ('notify-repeated-failure', 'notifyRepeatedFailure', False),
- ('include-test-summary', 'includeTestSummary', False),
- ('include-custom-message', 'includeCustomMessage', False),
- ('custom-message', 'customMessage', ''),
- ('room', 'room', ''),
+ ("notify-start", "startNotification", False),
+ ("notify-success", "notifySuccess", False),
+ ("notify-aborted", "notifyAborted", False),
+ ("notify-not-built", "notifyNotBuilt", False),
+ ("notify-unstable", "notifyUnstable", False),
+ ("notify-failure", "notifyFailure", False),
+ ("notify-back-to-normal", "notifyBackToNormal", False),
+ ("notify-repeated-failure", "notifyRepeatedFailure", False),
+ ("include-test-summary", "includeTestSummary", False),
+ ("include-custom-message", "includeCustomMessage", False),
+ ("custom-message", "customMessage", ""),
+ ("room", "room", ""),
)
slack = XML.SubElement(
- xml_parent,
- 'jenkins.plugins.slack.SlackNotifier_-SlackJobProperty',
+ xml_parent, "jenkins.plugins.slack.SlackNotifier_-SlackJobProperty"
)
# Ensure that custom-message is set when include-custom-message is set
# to true.
- if data.get('include-custom-message', False):
- if not data.get('custom-message', ''):
- raise MissingAttributeError('custom-message')
+ if data.get("include-custom-message", False):
+ if not data.get("custom-message", ""):
+ raise MissingAttributeError("custom-message")
helpers.convert_mapping_to_xml(slack, data, mapping, fail_required=True)
@@ -955,16 +920,14 @@ def rebuild(registry, xml_parent, data):
.. literalinclude:: /../../tests/properties/fixtures/rebuild-full.yaml
:language: yaml
"""
- sub_element = XML.SubElement(xml_parent,
- 'com.sonyericsson.rebuild.RebuildSettings')
- sub_element.set('plugin', 'rebuild')
+ sub_element = XML.SubElement(xml_parent, "com.sonyericsson.rebuild.RebuildSettings")
+ sub_element.set("plugin", "rebuild")
mapping = [
- ('auto-rebuild', 'autoRebuild', False),
- ('rebuild-disabled', 'rebuildDisabled', False),
+ ("auto-rebuild", "autoRebuild", False),
+ ("rebuild-disabled", "rebuildDisabled", False),
]
- helpers.convert_mapping_to_xml(
- sub_element, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(sub_element, data, mapping, fail_required=True)
def build_discarder(registry, xml_parent, data):
@@ -987,19 +950,17 @@ def build_discarder(registry, xml_parent, data):
/../../tests/properties/fixtures/build-discarder-002.yaml
:language: yaml
"""
- base_sub = XML.SubElement(xml_parent,
- 'jenkins.model.BuildDiscarderProperty')
- strategy = XML.SubElement(base_sub, 'strategy')
- strategy.set('class', 'hudson.tasks.LogRotator')
+ base_sub = XML.SubElement(xml_parent, "jenkins.model.BuildDiscarderProperty")
+ strategy = XML.SubElement(base_sub, "strategy")
+ strategy.set("class", "hudson.tasks.LogRotator")
mappings = [
- ('days-to-keep', 'daysToKeep', -1),
- ('num-to-keep', 'numToKeep', -1),
- ('artifact-days-to-keep', 'artifactDaysToKeep', -1),
- ('artifact-num-to-keep', 'artifactNumToKeep', -1),
+ ("days-to-keep", "daysToKeep", -1),
+ ("num-to-keep", "numToKeep", -1),
+ ("artifact-days-to-keep", "artifactDaysToKeep", -1),
+ ("artifact-num-to-keep", "artifactNumToKeep", -1),
]
- helpers.convert_mapping_to_xml(
- strategy, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(strategy, data, mappings, fail_required=True)
def slave_prerequisites(registry, xml_parent, data):
@@ -1027,14 +988,16 @@ def slave_prerequisites(registry, xml_parent, data):
/../../tests/properties/fixtures/slave-prerequisites-full.yaml
:language: yaml
"""
- prereqs = XML.SubElement(xml_parent,
- 'com.cloudbees.plugins.JobPrerequisites')
+ prereqs = XML.SubElement(xml_parent, "com.cloudbees.plugins.JobPrerequisites")
mappings = [
- ('script', 'script', None),
- ('interpreter', 'interpreter', 'shell', {
- 'cmd': 'windows batch command',
- 'shell': 'shell script'}),
+ ("script", "script", None),
+ (
+ "interpreter",
+ "interpreter",
+ "shell",
+ {"cmd": "windows batch command", "shell": "shell script"},
+ ),
]
helpers.convert_mapping_to_xml(prereqs, data, mappings, fail_required=True)
@@ -1077,24 +1040,23 @@ def groovy_label(registry, xml_parent, data):
/../../tests/properties/fixtures/groovy-label-full.yaml
:language: yaml
"""
- sub_element = XML.SubElement(xml_parent,
- 'jp.ikedam.jenkins.plugins.'
- 'groovy__label__assignment.'
- 'GroovyLabelAssignmentProperty')
- sub_element.set('plugin', 'groovy-label-assignment')
- security = XML.SubElement(sub_element, 'secureGroovyScript')
- security.set('plugin', 'script-security')
- mapping = [
- ('script', 'script', ''),
- ('sandbox', 'sandbox', False),
- ]
+ sub_element = XML.SubElement(
+ xml_parent,
+ "jp.ikedam.jenkins.plugins."
+ "groovy__label__assignment."
+ "GroovyLabelAssignmentProperty",
+ )
+ sub_element.set("plugin", "groovy-label-assignment")
+ security = XML.SubElement(sub_element, "secureGroovyScript")
+ security.set("plugin", "script-security")
+ mapping = [("script", "script", ""), ("sandbox", "sandbox", False)]
helpers.convert_mapping_to_xml(security, data, mapping, fail_required=True)
- if data and 'classpath' in data:
- classpath = XML.SubElement(security, 'classpath')
- for value in data['classpath']:
- entry = XML.SubElement(classpath, 'entry')
- XML.SubElement(entry, 'url').text = value
+ if data and "classpath" in data:
+ classpath = XML.SubElement(security, "classpath")
+ for value in data["classpath"]:
+ entry = XML.SubElement(classpath, "entry")
+ XML.SubElement(entry, "url").text = value
def lockable_resources(registry, xml_parent, data):
@@ -1137,26 +1099,24 @@ def lockable_resources(registry, xml_parent, data):
:language: yaml
"""
lockable_resources = XML.SubElement(
- xml_parent,
- 'org.jenkins.plugins.lockableresources.RequiredResourcesProperty')
- if data.get('resources') and data.get('label'):
- raise AttributeConflictError('resources', ('label',))
+ xml_parent, "org.jenkins.plugins.lockableresources.RequiredResourcesProperty"
+ )
+ if data.get("resources") and data.get("label"):
+ raise AttributeConflictError("resources", ("label",))
mapping = [
- ('resources', 'resourceNames', ''),
- ('var-name', 'resourceNamesVar', ''),
- ('number', 'resourceNumber', 0),
- ('label', 'labelName', ''),
+ ("resources", "resourceNames", ""),
+ ("var-name", "resourceNamesVar", ""),
+ ("number", "resourceNumber", 0),
+ ("label", "labelName", ""),
]
helpers.convert_mapping_to_xml(
- lockable_resources, data, mapping, fail_required=True)
- secure_groovy_script = XML.SubElement(lockable_resources,
- 'resourceMatchScript')
- mapping = [
- ('match-script', 'script', None),
- ('groovy-sandbox', 'sandbox', False),
- ]
- helpers.convert_mapping_to_xml(secure_groovy_script, data, mapping,
- fail_required=False)
+ lockable_resources, data, mapping, fail_required=True
+ )
+ secure_groovy_script = XML.SubElement(lockable_resources, "resourceMatchScript")
+ mapping = [("match-script", "script", None), ("groovy-sandbox", "sandbox", False)]
+ helpers.convert_mapping_to_xml(
+ secure_groovy_script, data, mapping, fail_required=False
+ )
def docker_container(registry, xml_parent, data):
@@ -1189,24 +1149,25 @@ def docker_container(registry, xml_parent, data):
:language: yaml
"""
xml_docker = XML.SubElement(
- xml_parent, 'com.nirima.jenkins.plugins.docker.DockerJobProperty')
+ xml_parent, "com.nirima.jenkins.plugins.docker.DockerJobProperty"
+ )
- registry = XML.SubElement(xml_docker, 'registry')
- registry.set('plugin', 'docker-commons')
+ registry = XML.SubElement(xml_docker, "registry")
+ registry.set("plugin", "docker-commons")
registry_mapping = [
- ('docker-registry-url', 'url', ''),
- ('credentials-id', 'credentialsId', ''),
+ ("docker-registry-url", "url", ""),
+ ("credentials-id", "credentialsId", ""),
]
helpers.convert_mapping_to_xml(
- registry, data, registry_mapping, fail_required=False)
+ registry, data, registry_mapping, fail_required=False
+ )
mapping = [
- ('commit-on-success', 'tagOnCompletion', False),
- ('additional-tag', 'additionalTag', ''),
- ('push-on-success', 'pushOnSuccess', False),
- ('clean-local-images', 'cleanImages', True),
+ ("commit-on-success", "tagOnCompletion", False),
+ ("additional-tag", "additionalTag", ""),
+ ("push-on-success", "pushOnSuccess", False),
+ ("clean-local-images", "cleanImages", True),
]
- helpers.convert_mapping_to_xml(
- xml_docker, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(xml_docker, data, mapping, fail_required=True)
def disable_resume(registry, xml_parent, data):
@@ -1222,9 +1183,10 @@ def disable_resume(registry, xml_parent, data):
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.workflow.job.properties.'
- 'DisableResumeJobProperty')
+ XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins.workflow.job.properties." "DisableResumeJobProperty",
+ )
def cachet_gating(registry, xml_parent, data):
@@ -1246,32 +1208,30 @@ def cachet_gating(registry, xml_parent, data):
:language: yaml
"""
cachet = XML.SubElement(
- xml_parent, 'com.redhat.jenkins.plugins.cachet.CachetJobProperty')
- cachet.set('plugin', 'cachet-gating')
+ xml_parent, "com.redhat.jenkins.plugins.cachet.CachetJobProperty"
+ )
+ cachet.set("plugin", "cachet-gating")
- mapping = [
- ('required-resources', 'requiredResources', True),
- ]
- helpers.convert_mapping_to_xml(
- cachet, data, mapping, fail_required=True)
+ mapping = [("required-resources", "requiredResources", True)]
+ helpers.convert_mapping_to_xml(cachet, data, mapping, fail_required=True)
- resources_data = data.get('resources', [])
+ resources_data = data.get("resources", [])
if resources_data:
- resources = XML.SubElement(cachet, 'resources')
+ resources = XML.SubElement(cachet, "resources")
for resource in resources_data:
- XML.SubElement(resources, 'string').text = str(resource)
+ XML.SubElement(resources, "string").text = str(resource)
class Properties(jenkins_jobs.modules.base.Base):
sequence = 20
- component_type = 'property'
- component_list_type = 'properties'
+ component_type = "property"
+ component_list_type = "properties"
def gen_xml(self, xml_parent, data):
- properties = xml_parent.find('properties')
+ properties = xml_parent.find("properties")
if properties is None:
- properties = XML.SubElement(xml_parent, 'properties')
+ properties = XML.SubElement(xml_parent, "properties")
- for prop in data.get('properties', []):
- self.registry.dispatch('property', properties, prop)
+ for prop in data.get("properties", []):
+ self.registry.dispatch("property", properties, prop)
diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py
index c165d7d4..6c079ed9 100644
--- a/jenkins_jobs/modules/publishers.py
+++ b/jenkins_jobs/modules/publishers.py
@@ -46,20 +46,21 @@ def influx_db(registry, xml_parent, data):
<Influx+DB+Plugin>`.
"""
- influx_db = XML.SubElement(xml_parent,
- 'jenkinsci.plugins.influxdb.InfluxDbPublisher',
- {'plugin': 'influx-db'})
+ influx_db = XML.SubElement(
+ xml_parent,
+ "jenkinsci.plugins.influxdb.InfluxDbPublisher",
+ {"plugin": "influx-db"},
+ )
mapping = [
- ('selected-target', 'selectedTarget', ''),
- ('custom-project-name', 'customProjectName', ''),
- ('custom-prefix', 'customPrefix', ''),
- ('jenkins-env-parameter-field', 'jenkinsEnvParameterField', ''),
- ('jenkins-env-parameter-tag', 'jenkinsEnvParameterTag', '')
+ ("selected-target", "selectedTarget", ""),
+ ("custom-project-name", "customProjectName", ""),
+ ("custom-prefix", "customPrefix", ""),
+ ("jenkins-env-parameter-field", "jenkinsEnvParameterField", ""),
+ ("jenkins-env-parameter-tag", "jenkinsEnvParameterTag", ""),
]
- helpers.convert_mapping_to_xml(
- influx_db, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(influx_db, data, mapping, fail_required=True)
def allure(registry, xml_parent, data):
@@ -90,44 +91,45 @@ def allure(registry, xml_parent, data):
:language: yaml
"""
- publisher_class = 'ru.yandex.qatools.allure.jenkins.AllureReportPublisher'
- property_class = 'ru.yandex.qatools.allure.jenkins.config.PropertyConfig'
- results_class = 'ru.yandex.qatools.allure.jenkins.config.ResultsConfig'
+ publisher_class = "ru.yandex.qatools.allure.jenkins.AllureReportPublisher"
+ property_class = "ru.yandex.qatools.allure.jenkins.config.PropertyConfig"
+ results_class = "ru.yandex.qatools.allure.jenkins.config.ResultsConfig"
allure_publisher = XML.SubElement(xml_parent, publisher_class)
- allure_publisher.set('plugin', 'allure-jenkins-plugin')
- config = XML.SubElement(allure_publisher, 'config')
+ allure_publisher.set("plugin", "allure-jenkins-plugin")
+ config = XML.SubElement(allure_publisher, "config")
- results = XML.SubElement(config, 'results')
- if 'results-paths' in data:
- for results_path in data['results-paths']:
+ results = XML.SubElement(config, "results")
+ if "results-paths" in data:
+ for results_path in data["results-paths"]:
entry = XML.SubElement(results, results_class)
- path = XML.SubElement(entry, 'path')
- path.text = results_path['path']
-
- properties = XML.SubElement(config, 'properties')
- if 'properties' in data:
- property_mapping = [
- ('key', 'key', None),
- ('value', 'value', None)
- ]
- for prop in data['properties']:
+ path = XML.SubElement(entry, "path")
+ path.text = results_path["path"]
+
+ properties = XML.SubElement(config, "properties")
+ if "properties" in data:
+ property_mapping = [("key", "key", None), ("value", "value", None)]
+ for prop in data["properties"]:
entry = XML.SubElement(properties, property_class)
- helpers.convert_mapping_to_xml(entry, prop, property_mapping,
- fail_required=True)
+ helpers.convert_mapping_to_xml(
+ entry, prop, property_mapping, fail_required=True
+ )
else:
- properties.set('class', 'empty-list')
+ properties.set("class", "empty-list")
mapping = [
- ('jdk', 'jdk', ''),
- ('commandline', 'commandline', ''),
- ('report-build-policy', 'reportBuildPolicy', 'ALWAYS',
- ['ALWAYS', 'UNSTABLE', 'UNSUCCESSFUL']),
- ('include-properties', 'includeProperties', False)
+ ("jdk", "jdk", ""),
+ ("commandline", "commandline", ""),
+ (
+ "report-build-policy",
+ "reportBuildPolicy",
+ "ALWAYS",
+ ["ALWAYS", "UNSTABLE", "UNSUCCESSFUL"],
+ ),
+ ("include-properties", "includeProperties", False),
]
- helpers.convert_mapping_to_xml(config, data, mapping,
- fail_required=True)
+ helpers.convert_mapping_to_xml(config, data, mapping, fail_required=True)
def archive(registry, xml_parent, data):
@@ -153,18 +155,19 @@ def archive(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/archive001.yaml
:language: yaml
"""
- archiver = XML.SubElement(xml_parent, 'hudson.tasks.ArtifactArchiver')
+ archiver = XML.SubElement(xml_parent, "hudson.tasks.ArtifactArchiver")
mapping = [
- ('artifacts', 'artifacts', None),
- ('allow-empty', 'allowEmptyArchive', False),
- ('only-if-success', 'onlyIfSuccessful', False),
- ('fingerprint', 'fingerprint', False),
- ('default-excludes', 'defaultExcludes', True),
- ('case-sensitive', 'caseSensitive', True),
- ('latest-only', 'latestOnly', False)]
-
- if 'excludes' in data:
- mapping.append(('excludes', 'excludes', None))
+ ("artifacts", "artifacts", None),
+ ("allow-empty", "allowEmptyArchive", False),
+ ("only-if-success", "onlyIfSuccessful", False),
+ ("fingerprint", "fingerprint", False),
+ ("default-excludes", "defaultExcludes", True),
+ ("case-sensitive", "caseSensitive", True),
+ ("latest-only", "latestOnly", False),
+ ]
+
+ if "excludes" in data:
+ mapping.append(("excludes", "excludes", None))
helpers.convert_mapping_to_xml(archiver, data, mapping, fail_required=True)
@@ -180,9 +183,10 @@ def blame_upstream(registry, xml_parent, data):
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'hudson.plugins.blame__upstream__commiters.'
- 'BlameUpstreamCommitersPublisher')
+ XML.SubElement(
+ xml_parent,
+ "hudson.plugins.blame__upstream__commiters." "BlameUpstreamCommitersPublisher",
+ )
def jclouds(registry, xml_parent, data):
@@ -205,30 +209,27 @@ def jclouds(registry, xml_parent, data):
"""
- deployer = XML.SubElement(xml_parent,
- 'jenkins.plugins.jclouds.blobstore.'
- 'BlobStorePublisher')
- entries = XML.SubElement(deployer, 'entries')
- deployer_entry = XML.SubElement(entries,
- 'jenkins.plugins.jclouds.blobstore.'
- 'BlobStoreEntry')
- deployer_mapping = [
- ('profile', 'profileName', None),
- ]
- helpers.convert_mapping_to_xml(
- deployer, data, deployer_mapping, fail_required=True)
+ deployer = XML.SubElement(
+ xml_parent, "jenkins.plugins.jclouds.blobstore." "BlobStorePublisher"
+ )
+ entries = XML.SubElement(deployer, "entries")
+ deployer_entry = XML.SubElement(
+ entries, "jenkins.plugins.jclouds.blobstore." "BlobStoreEntry"
+ )
+ deployer_mapping = [("profile", "profileName", None)]
+ helpers.convert_mapping_to_xml(deployer, data, deployer_mapping, fail_required=True)
try:
- XML.SubElement(deployer_entry, 'container').text = data['container']
- XML.SubElement(deployer_entry, 'sourceFile').text = data['files']
+ XML.SubElement(deployer_entry, "container").text = data["container"]
+ XML.SubElement(deployer_entry, "sourceFile").text = data["files"]
except KeyError as e:
- raise JenkinsJobsException("blobstore requires '%s' to be set"
- % e.args[0])
+ raise JenkinsJobsException("blobstore requires '%s' to be set" % e.args[0])
deployer_entry_mapping = [
- ('hierarchy', 'keepHierarchy', False),
- ('basedir', 'path', ''),
+ ("hierarchy", "keepHierarchy", False),
+ ("basedir", "path", ""),
]
helpers.convert_mapping_to_xml(
- deployer_entry, data, deployer_entry_mapping, fail_required=True)
+ deployer_entry, data, deployer_entry_mapping, fail_required=True
+ )
def javadoc(registry, xml_parent, data):
@@ -250,11 +251,11 @@ def javadoc(registry, xml_parent, data):
:language: yaml
"""
- root = XML.SubElement(xml_parent, 'hudson.tasks.JavadocArchiver')
+ root = XML.SubElement(xml_parent, "hudson.tasks.JavadocArchiver")
mapping = [
- ('directory', 'javadocDir', None),
- ('keep-all-successful', 'keepAll', False),
+ ("directory", "javadocDir", None),
+ ("keep-all-successful", "keepAll", False),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
@@ -271,12 +272,8 @@ def jdepend(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/jdepend001.yaml
:language: yaml
"""
- jdepend = XML.SubElement(
- xml_parent,
- 'hudson.plugins.jdepend.JDependRecorder')
- mapping = [
- ('file', 'configuredJDependFile', None),
- ]
+ jdepend = XML.SubElement(xml_parent, "hudson.plugins.jdepend.JDependRecorder")
+ mapping = [("file", "configuredJDependFile", None)]
helpers.convert_mapping_to_xml(jdepend, data, mapping, fail_required=True)
@@ -309,24 +306,21 @@ def hue_light(registry, xml_parent, data):
"""
hue_light = XML.SubElement(
- xml_parent, 'org.jenkinsci.plugins.hue__light.LightNotifier')
- hue_light.set('plugin', 'hue-light')
- lightId = XML.SubElement(hue_light, 'lightId')
+ xml_parent, "org.jenkinsci.plugins.hue__light.LightNotifier"
+ )
+ hue_light.set("plugin", "hue-light")
+ lightId = XML.SubElement(hue_light, "lightId")
- id_mapping = [
- ('light-id', 'string', None),
- ]
- helpers.convert_mapping_to_xml(
- lightId, data, id_mapping, fail_required=True)
+ id_mapping = [("light-id", "string", None)]
+ helpers.convert_mapping_to_xml(lightId, data, id_mapping, fail_required=True)
build_mapping = [
- ('pre-build', 'preBuild', 'blue'),
- ('good-build', 'goodBuild', 'green'),
- ('unstable-build', 'unstableBuild', 'yellow'),
- ('bad-build', 'badBuild', 'red'),
+ ("pre-build", "preBuild", "blue"),
+ ("good-build", "goodBuild", "green"),
+ ("unstable-build", "unstableBuild", "yellow"),
+ ("bad-build", "badBuild", "red"),
]
- helpers.convert_mapping_to_xml(
- hue_light, data, build_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(hue_light, data, build_mapping, fail_required=True)
def campfire(registry, xml_parent, data):
@@ -349,22 +343,19 @@ def campfire(registry, xml_parent, data):
:language: yaml
"""
- root = XML.SubElement(xml_parent,
- 'hudson.plugins.campfire.'
- 'CampfireNotifier')
- campfire = XML.SubElement(root, 'campfire')
+ root = XML.SubElement(xml_parent, "hudson.plugins.campfire." "CampfireNotifier")
+ campfire = XML.SubElement(root, "campfire")
mapping = [
- ('subdomain', 'subdomain', None),
- ('token', 'token', None),
- ('ssl', 'ssl', None),
+ ("subdomain", "subdomain", None),
+ ("token", "token", None),
+ ("ssl", "ssl", None),
]
- helpers.convert_mapping_to_xml(
- campfire, data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(campfire, data, mapping, fail_required=False)
- if 'room' in data:
- room = XML.SubElement(root, 'room')
- mapping = [('room', 'name', None)]
+ if "room" in data:
+ room = XML.SubElement(root, "room")
+ mapping = [("room", "name", None)]
helpers.convert_mapping_to_xml(room, data, mapping, fail_required=True)
XML.SubElement(room, 'campfire reference="../../campfire"')
@@ -397,24 +388,23 @@ def mqtt(registry, xml_parent, data):
:language: yaml
"""
- mqtt = XML.SubElement(xml_parent,
- 'jenkins.plugins.mqttnotification.MqttNotifier')
- mqtt.set('plugin', 'mqtt-notification-plugin')
- mqtt_mapping = [
- ('broker-url', 'brokerUrl', None), ]
- helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping,
- fail_required=True)
+ mqtt = XML.SubElement(xml_parent, "jenkins.plugins.mqttnotification.MqttNotifier")
+ mqtt.set("plugin", "mqtt-notification-plugin")
+ mqtt_mapping = [("broker-url", "brokerUrl", None)]
+ helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping, fail_required=True)
mqtt_mapping = [
- ('credentials-id', 'credentialsId', None),
- ('topic', 'topic', 'jenkins/$PROJECT_URL'),
- ('message', 'message', '$BUILD_RESULT'),
- ('qos', 'qos', 'AT_MOST_ONCE', {'AT_MOST_ONCE': '0',
- 'AT_LEAST_ONCE': '1',
- 'EXACTLY_ONCE': '2'}),
- ('retain-message', 'retainMessage', False)
+ ("credentials-id", "credentialsId", None),
+ ("topic", "topic", "jenkins/$PROJECT_URL"),
+ ("message", "message", "$BUILD_RESULT"),
+ (
+ "qos",
+ "qos",
+ "AT_MOST_ONCE",
+ {"AT_MOST_ONCE": "0", "AT_LEAST_ONCE": "1", "EXACTLY_ONCE": "2"},
+ ),
+ ("retain-message", "retainMessage", False),
]
- helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping,
- fail_required=False)
+ helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping, fail_required=False)
def codecover(registry, xml_parent, data):
@@ -448,24 +438,24 @@ def codecover(registry, xml_parent, data):
"""
codecover = XML.SubElement(
- xml_parent, 'hudson.plugins.codecover.CodeCoverPublisher')
- codecover.set('plugin', 'codecover')
+ xml_parent, "hudson.plugins.codecover.CodeCoverPublisher"
+ )
+ codecover.set("plugin", "codecover")
- XML.SubElement(codecover, 'includes').text = str(data.get('include', ''))
+ XML.SubElement(codecover, "includes").text = str(data.get("include", ""))
- health_report = XML.SubElement(codecover, 'healthReports')
+ health_report = XML.SubElement(codecover, "healthReports")
mapping = [
- ('min-statement', 'minStatement', 0),
- ('max-statement', 'maxStatement', 90),
- ('min-branch', 'minBranch', 0),
- ('max-branch', 'maxBranch', 80),
- ('min-loop', 'minLoop', 0),
- ('max-loop', 'maxLoop', 50),
- ('min-condition', 'minCondition', 0),
- ('max-condition', 'maxCondition', 50),
+ ("min-statement", "minStatement", 0),
+ ("max-statement", "maxStatement", 90),
+ ("min-branch", "minBranch", 0),
+ ("max-branch", "maxBranch", 80),
+ ("min-loop", "minLoop", 0),
+ ("max-loop", "maxLoop", 50),
+ ("min-condition", "minCondition", 0),
+ ("max-condition", "maxCondition", 50),
]
- helpers.convert_mapping_to_xml(
- health_report, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(health_report, data, mapping, fail_required=True)
def emotional_jenkins(registry, xml_parent, data):
@@ -482,9 +472,10 @@ def emotional_jenkins(registry, xml_parent, data):
/../../tests/publishers/fixtures/emotional-jenkins.yaml
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.emotional__jenkins.'
- 'EmotionalJenkinsPublisher')
+ XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins.emotional__jenkins." "EmotionalJenkinsPublisher",
+ )
def trigger_parameterized_builds(registry, xml_parent, data):
@@ -562,38 +553,40 @@ def trigger_parameterized_builds(registry, xml_parent, data):
/../../tests/publishers/fixtures/trigger_parameterized_builds003.yaml
:language: yaml
"""
- pt_prefix = 'hudson.plugins.parameterizedtrigger.'
- tbuilder = XML.SubElement(xml_parent, pt_prefix + 'BuildTrigger')
- configs = XML.SubElement(tbuilder, 'configs')
+ pt_prefix = "hudson.plugins.parameterizedtrigger."
+ tbuilder = XML.SubElement(xml_parent, pt_prefix + "BuildTrigger")
+ configs = XML.SubElement(tbuilder, "configs")
param_order = helpers.trigger_get_parameter_order(
- registry, 'trigger-parameterized-builds')
+ registry, "trigger-parameterized-builds"
+ )
for project_def in data:
- tconfig = XML.SubElement(configs, pt_prefix + 'BuildTriggerConfig')
- tconfigs = XML.SubElement(tconfig, 'configs')
+ tconfig = XML.SubElement(configs, pt_prefix + "BuildTriggerConfig")
+ tconfigs = XML.SubElement(tconfig, "configs")
helpers.trigger_project(tconfigs, project_def, param_order)
if not list(tconfigs):
# no child parameter tags added
- tconfigs.set('class', 'java.util.Collections$EmptyList')
+ tconfigs.set("class", "java.util.Collections$EmptyList")
- projects = XML.SubElement(tconfig, 'projects')
+ projects = XML.SubElement(tconfig, "projects")
- if isinstance(project_def['project'], list):
- projects.text = ",".join(project_def['project'])
+ if isinstance(project_def["project"], list):
+ projects.text = ",".join(project_def["project"])
else:
- projects.text = project_def['project']
+ projects.text = project_def["project"]
- condition = XML.SubElement(tconfig, 'condition')
- condition.text = project_def.get('condition', 'ALWAYS')
+ condition = XML.SubElement(tconfig, "condition")
+ condition.text = project_def.get("condition", "ALWAYS")
mapping = [
- ('trigger-from-child-projects', 'triggerFromChildProjects', False),
- ('trigger-with-no-params', 'triggerWithNoParameters', False),
+ ("trigger-from-child-projects", "triggerFromChildProjects", False),
+ ("trigger-with-no-params", "triggerWithNoParameters", False),
]
helpers.convert_mapping_to_xml(
- tconfig, project_def, mapping, fail_required=False)
+ tconfig, project_def, mapping, fail_required=False
+ )
def trigger(registry, xml_parent, data):
@@ -609,22 +602,23 @@ def trigger(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/trigger_success.yaml
:language: yaml
"""
- tconfig = XML.SubElement(xml_parent, 'hudson.tasks.BuildTrigger')
- childProjects = XML.SubElement(tconfig, 'childProjects')
- childProjects.text = data['project']
- tthreshold = XML.SubElement(tconfig, 'threshold')
+ tconfig = XML.SubElement(xml_parent, "hudson.tasks.BuildTrigger")
+ childProjects = XML.SubElement(tconfig, "childProjects")
+ childProjects.text = data["project"]
+ tthreshold = XML.SubElement(tconfig, "threshold")
- threshold = data.get('threshold', 'SUCCESS')
- supported_thresholds = ['SUCCESS', 'UNSTABLE', 'FAILURE']
+ threshold = data.get("threshold", "SUCCESS")
+ supported_thresholds = ["SUCCESS", "UNSTABLE", "FAILURE"]
if threshold not in supported_thresholds:
- raise JenkinsJobsException("threshold must be one of %s" %
- ", ".join(supported_thresholds))
- tname = XML.SubElement(tthreshold, 'name')
- tname.text = hudson_model.THRESHOLDS[threshold]['name']
- tordinal = XML.SubElement(tthreshold, 'ordinal')
- tordinal.text = hudson_model.THRESHOLDS[threshold]['ordinal']
- tcolor = XML.SubElement(tthreshold, 'color')
- tcolor.text = hudson_model.THRESHOLDS[threshold]['color']
+ raise JenkinsJobsException(
+ "threshold must be one of %s" % ", ".join(supported_thresholds)
+ )
+ tname = XML.SubElement(tthreshold, "name")
+ tname.text = hudson_model.THRESHOLDS[threshold]["name"]
+ tordinal = XML.SubElement(tthreshold, "ordinal")
+ tordinal.text = hudson_model.THRESHOLDS[threshold]["ordinal"]
+ tcolor = XML.SubElement(tthreshold, "color")
+ tcolor.text = hudson_model.THRESHOLDS[threshold]["color"]
def clone_workspace(registry, xml_parent, data):
@@ -657,27 +651,23 @@ def clone_workspace(registry, xml_parent, data):
"""
cloneworkspace = XML.SubElement(
- xml_parent,
- 'hudson.plugins.cloneworkspace.CloneWorkspacePublisher')
- cloneworkspace.set('plugin', 'clone-workspace-scm')
+ xml_parent, "hudson.plugins.cloneworkspace.CloneWorkspacePublisher"
+ )
+ cloneworkspace.set("plugin", "clone-workspace-scm")
- criteria_valid_types = ['Any', 'Not Failed', 'Successful']
- archive_valid_types = ['TAR', 'ZIP']
+ criteria_valid_types = ["Any", "Not Failed", "Successful"]
+ archive_valid_types = ["TAR", "ZIP"]
mappings = [
- ('workspace-glob', 'workspaceGlob', ''),
- ('override-default-excludes', 'overrideDefaultExcludes', False),
- ('criteria', 'criteria', 'Any', criteria_valid_types),
- ('archive-method', 'archiveMethod', 'TAR', archive_valid_types),
+ ("workspace-glob", "workspaceGlob", ""),
+ ("override-default-excludes", "overrideDefaultExcludes", False),
+ ("criteria", "criteria", "Any", criteria_valid_types),
+ ("archive-method", "archiveMethod", "TAR", archive_valid_types),
]
- helpers.convert_mapping_to_xml(
- cloneworkspace, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(cloneworkspace, data, mappings, fail_required=True)
- mappings = [
- ('workspace-exclude-glob', 'workspaceExcludeGlob', ''),
- ]
- helpers.convert_mapping_to_xml(
- cloneworkspace, data, mappings, fail_required=False)
+ mappings = [("workspace-exclude-glob", "workspaceExcludeGlob", "")]
+ helpers.convert_mapping_to_xml(cloneworkspace, data, mappings, fail_required=False)
def cloud_foundry(parser, xml_parent, data):
@@ -753,82 +743,81 @@ def cloud_foundry(parser, xml_parent, data):
:language: yaml
"""
cloud_foundry = XML.SubElement(
- xml_parent, 'com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher')
- cloud_foundry.set('plugin', 'cloudfoundry')
+ xml_parent, "com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher"
+ )
+ cloud_foundry.set("plugin", "cloudfoundry")
mapping = [
- ('target', 'target', None),
- ('organization', 'organization', None),
- ('space', 'cloudSpace', None),
- ('credentials-id', 'credentialsId', None),
- ('self-signed', 'selfSigned', False),
- ('reset-app', 'resetIfExists', False),
- ('timeout', 'pluginTimeout', 120),
+ ("target", "target", None),
+ ("organization", "organization", None),
+ ("space", "cloudSpace", None),
+ ("credentials-id", "credentialsId", None),
+ ("self-signed", "selfSigned", False),
+ ("reset-app", "resetIfExists", False),
+ ("timeout", "pluginTimeout", 120),
]
- helpers.convert_mapping_to_xml(
- cloud_foundry, data, mapping, fail_required=True)
- XML.SubElement(cloud_foundry, 'appURIs').text = ''
+ helpers.convert_mapping_to_xml(cloud_foundry, data, mapping, fail_required=True)
+ XML.SubElement(cloud_foundry, "appURIs").text = ""
- create_services = XML.SubElement(cloud_foundry, 'servicesToCreate')
+ create_services = XML.SubElement(cloud_foundry, "servicesToCreate")
create_services_mapping = [
- ('name', 'name', ''),
- ('type', 'type', ''),
- ('plan', 'plan', ''),
- ('reset-service', 'resetService', '')]
- for service in data.get('create-services', ''):
+ ("name", "name", ""),
+ ("type", "type", ""),
+ ("plan", "plan", ""),
+ ("reset-service", "resetService", ""),
+ ]
+ for service in data.get("create-services", ""):
create_services_sub = XML.SubElement(
create_services,
- 'com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher_-Service')
- helpers.convert_mapping_to_xml(create_services_sub,
- service,
- create_services_mapping,
- fail_required=True)
-
- manifest = XML.SubElement(cloud_foundry, 'manifestChoice')
- valid_values = ['manifestFile', 'jenkinsConfig']
+ "com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher_-Service",
+ )
+ helpers.convert_mapping_to_xml(
+ create_services_sub, service, create_services_mapping, fail_required=True
+ )
+
+ manifest = XML.SubElement(cloud_foundry, "manifestChoice")
+ valid_values = ["manifestFile", "jenkinsConfig"]
manifest_mapping = [
- ('value', 'value', 'manifestFile', valid_values),
- ('manifest-file', 'manifestFile', 'manifest.yml'),
- ('app-name', 'appName', ''),
- ('memory', 'memory', 512),
- ('host-name', 'hostname', ''),
- ('instances', 'instances', 1),
- ('manifest-timeout', 'timeout', 60),
- ('no-route', 'noRoute', False),
- ('app-path', 'appPath', ''),
- ('build-pack', 'buildpack', ''),
- ('stack', 'stack', ''),
- ('command', 'command', ''),
- ('domain', 'domain', ''),
+ ("value", "value", "manifestFile", valid_values),
+ ("manifest-file", "manifestFile", "manifest.yml"),
+ ("app-name", "appName", ""),
+ ("memory", "memory", 512),
+ ("host-name", "hostname", ""),
+ ("instances", "instances", 1),
+ ("manifest-timeout", "timeout", 60),
+ ("no-route", "noRoute", False),
+ ("app-path", "appPath", ""),
+ ("build-pack", "buildpack", ""),
+ ("stack", "stack", ""),
+ ("command", "command", ""),
+ ("domain", "domain", ""),
]
- helpers.convert_mapping_to_xml(
- manifest, data, manifest_mapping, fail_required=True)
-
- if 'environment-variables' in data:
- env_vars = XML.SubElement(manifest, 'envVars')
- env_vars_mapping = [
- ('key', 'key', ''),
- ('value', 'value', '')]
- for var in data['environment-variables']:
+ helpers.convert_mapping_to_xml(manifest, data, manifest_mapping, fail_required=True)
+
+ if "environment-variables" in data:
+ env_vars = XML.SubElement(manifest, "envVars")
+ env_vars_mapping = [("key", "key", ""), ("value", "value", "")]
+ for var in data["environment-variables"]:
env_vars_sub = XML.SubElement(
env_vars,
- 'com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher_-'
- 'EnvironmentVariable')
+ "com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher_-"
+ "EnvironmentVariable",
+ )
helpers.convert_mapping_to_xml(
- env_vars_sub, var, env_vars_mapping, fail_required=True)
+ env_vars_sub, var, env_vars_mapping, fail_required=True
+ )
- if 'services-names' in data:
- services_names = XML.SubElement(manifest, 'servicesNames')
- service_name_mapping = [('name', 'name', '')]
- for name in data['services-names']:
+ if "services-names" in data:
+ services_names = XML.SubElement(manifest, "servicesNames")
+ service_name_mapping = [("name", "name", "")]
+ for name in data["services-names"]:
services_names_sub = XML.SubElement(
services_names,
- 'com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher_-'
- 'ServiceName')
- helpers.convert_mapping_to_xml(services_names_sub,
- name,
- service_name_mapping,
- fail_required=True)
+ "com.hpe.cloudfoundryjenkins.CloudFoundryPushPublisher_-" "ServiceName",
+ )
+ helpers.convert_mapping_to_xml(
+ services_names_sub, name, service_name_mapping, fail_required=True
+ )
def cloverphp(registry, xml_parent, data):
@@ -873,13 +862,13 @@ def cloverphp(registry, xml_parent, data):
:language: yaml
"""
cloverphp = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.cloverphp.CloverPHPPublisher')
- cloverphp.set('plugin', 'cloverphp')
+ xml_parent, "org.jenkinsci.plugins.cloverphp.CloverPHPPublisher"
+ )
+ cloverphp.set("plugin", "cloverphp")
# The plugin requires clover XML file to parse
- if 'xml-location' not in data:
- raise JenkinsJobsException('xml-location must be set')
+ if "xml-location" not in data:
+ raise JenkinsJobsException("xml-location must be set")
# Whether HTML publishing has been checked
html_publish = False
@@ -887,32 +876,28 @@ def cloverphp(registry, xml_parent, data):
# reversed logic.
html_archive = True
- if 'html' in data:
+ if "html" in data:
html_publish = True
- html_dir = data['html'].get('dir', None)
- html_archive = data['html'].get('archive', html_archive)
+ html_dir = data["html"].get("dir", None)
+ html_archive = data["html"].get("archive", html_archive)
if html_dir is None:
# No point in going further, the plugin would not work
- raise JenkinsJobsException('htmldir is required in a html block')
+ raise JenkinsJobsException("htmldir is required in a html block")
- XML.SubElement(cloverphp, 'publishHtmlReport').text = str(
- html_publish).lower()
+ XML.SubElement(cloverphp, "publishHtmlReport").text = str(html_publish).lower()
if html_publish:
- XML.SubElement(cloverphp, 'reportDir').text = html_dir
- XML.SubElement(cloverphp, 'xmlLocation').text = data.get('xml-location')
- XML.SubElement(cloverphp, 'disableArchiving').text = str(
- not html_archive).lower()
+ XML.SubElement(cloverphp, "reportDir").text = html_dir
+ XML.SubElement(cloverphp, "xmlLocation").text = data.get("xml-location")
+ XML.SubElement(cloverphp, "disableArchiving").text = str(not html_archive).lower()
# Handle targets
# Plugin v0.3.3 will fill defaults for us whenever healthy targets are both
# blanks.
- default_metrics = {
- 'healthy': {'method': 70, 'statement': 80}
- }
- allowed_metrics = ['healthy', 'unhealthy', 'failing']
+ default_metrics = {"healthy": {"method": 70, "statement": 80}}
+ allowed_metrics = ["healthy", "unhealthy", "failing"]
- metrics = data.get('metric-targets', [])
+ metrics = data.get("metric-targets", [])
# list of dicts to dict
metrics = dict(kv for m in metrics for kv in m.items())
@@ -925,17 +910,18 @@ def cloverphp(registry, xml_parent, data):
# we output them all in the XML regardless of what the user
# has or has not entered.
for target in allowed_metrics:
- cur_target = XML.SubElement(cloverphp, target + 'Target')
+ cur_target = XML.SubElement(cloverphp, target + "Target")
- for t_type in ['method', 'statement']:
+ for t_type in ["method", "statement"]:
val = metrics.get(target, {}).get(t_type)
if val is None or type(val) != int:
continue
if val < 0 or val > 100:
raise JenkinsJobsException(
"Publisher cloverphp metric target %s:%s = %s "
- "is not in valid range 0-100." % (target, t_type, val))
- XML.SubElement(cur_target, t_type + 'Coverage').text = str(val)
+ "is not in valid range 0-100." % (target, t_type, val)
+ )
+ XML.SubElement(cur_target, t_type + "Coverage").text = str(val)
def coverage(registry, xml_parent, data):
@@ -953,59 +939,84 @@ def coverage(registry, xml_parent, data):
logger = logging.getLogger(__name__)
logger.warning("Coverage function is deprecated. Switch to cobertura.")
- cobertura = XML.SubElement(xml_parent,
- 'hudson.plugins.cobertura.CoberturaPublisher')
- XML.SubElement(cobertura, 'coberturaReportFile').text = '**/coverage.xml'
- XML.SubElement(cobertura, 'onlyStable').text = 'false'
- healthy = XML.SubElement(cobertura, 'healthyTarget')
- targets = XML.SubElement(healthy, 'targets', {
- 'class': 'enum-map',
- 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'CONDITIONAL'
- XML.SubElement(entry, 'int').text = '70'
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'LINE'
- XML.SubElement(entry, 'int').text = '80'
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'METHOD'
- XML.SubElement(entry, 'int').text = '80'
- unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
- targets = XML.SubElement(unhealthy, 'targets', {
- 'class': 'enum-map',
- 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'CONDITIONAL'
- XML.SubElement(entry, 'int').text = '0'
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'LINE'
- XML.SubElement(entry, 'int').text = '0'
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'METHOD'
- XML.SubElement(entry, 'int').text = '0'
- failing = XML.SubElement(cobertura, 'failingTarget')
- targets = XML.SubElement(failing, 'targets', {
- 'class': 'enum-map',
- 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'CONDITIONAL'
- XML.SubElement(entry, 'int').text = '0'
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'LINE'
- XML.SubElement(entry, 'int').text = '0'
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.CoverageMetric'
- ).text = 'METHOD'
- XML.SubElement(entry, 'int').text = '0'
- XML.SubElement(cobertura, 'sourceEncoding').text = 'ASCII'
+ cobertura = XML.SubElement(
+ xml_parent, "hudson.plugins.cobertura.CoberturaPublisher"
+ )
+ XML.SubElement(cobertura, "coberturaReportFile").text = "**/coverage.xml"
+ XML.SubElement(cobertura, "onlyStable").text = "false"
+ healthy = XML.SubElement(cobertura, "healthyTarget")
+ targets = XML.SubElement(
+ healthy,
+ "targets",
+ {
+ "class": "enum-map",
+ "enum-type": "hudson.plugins.cobertura.targets.CoverageMetric",
+ },
+ )
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "CONDITIONAL"
+ XML.SubElement(entry, "int").text = "70"
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "LINE"
+ XML.SubElement(entry, "int").text = "80"
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "METHOD"
+ XML.SubElement(entry, "int").text = "80"
+ unhealthy = XML.SubElement(cobertura, "unhealthyTarget")
+ targets = XML.SubElement(
+ unhealthy,
+ "targets",
+ {
+ "class": "enum-map",
+ "enum-type": "hudson.plugins.cobertura.targets.CoverageMetric",
+ },
+ )
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "CONDITIONAL"
+ XML.SubElement(entry, "int").text = "0"
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "LINE"
+ XML.SubElement(entry, "int").text = "0"
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "METHOD"
+ XML.SubElement(entry, "int").text = "0"
+ failing = XML.SubElement(cobertura, "failingTarget")
+ targets = XML.SubElement(
+ failing,
+ "targets",
+ {
+ "class": "enum-map",
+ "enum-type": "hudson.plugins.cobertura.targets.CoverageMetric",
+ },
+ )
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "CONDITIONAL"
+ XML.SubElement(entry, "int").text = "0"
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "LINE"
+ XML.SubElement(entry, "int").text = "0"
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets.CoverageMetric"
+ ).text = "METHOD"
+ XML.SubElement(entry, "int").text = "0"
+ XML.SubElement(cobertura, "sourceEncoding").text = "ASCII"
def cobertura(registry, xml_parent, data):
@@ -1042,58 +1053,75 @@ def cobertura(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/cobertura001.yaml
:language: yaml
"""
- cobertura = XML.SubElement(xml_parent,
- 'hudson.plugins.cobertura.CoberturaPublisher')
+ cobertura = XML.SubElement(
+ xml_parent, "hudson.plugins.cobertura.CoberturaPublisher"
+ )
mapping = [
- ('report-file', 'coberturaReportFile', '**/coverage.xml'),
- ('only-stable', 'onlyStable', False),
- ('fail-unhealthy', 'failUnhealthy', False),
- ('fail-unstable', 'failUnstable', False),
- ('health-auto-update', 'autoUpdateHealth', False),
- ('stability-auto-update', 'autoUpdateStability', False),
- ('zoom-coverage-chart', 'zoomCoverageChart', False),
- ('fail-no-reports', 'failNoReports', False),
+ ("report-file", "coberturaReportFile", "**/coverage.xml"),
+ ("only-stable", "onlyStable", False),
+ ("fail-unhealthy", "failUnhealthy", False),
+ ("fail-unstable", "failUnstable", False),
+ ("health-auto-update", "autoUpdateHealth", False),
+ ("stability-auto-update", "autoUpdateStability", False),
+ ("zoom-coverage-chart", "zoomCoverageChart", False),
+ ("fail-no-reports", "failNoReports", False),
]
- helpers.convert_mapping_to_xml(
- cobertura, data, mapping, fail_required=True)
-
- healthy = XML.SubElement(cobertura, 'healthyTarget')
- targets = XML.SubElement(healthy, 'targets', {
- 'class': 'enum-map',
- 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
- for item in data['targets']:
+ helpers.convert_mapping_to_xml(cobertura, data, mapping, fail_required=True)
+
+ healthy = XML.SubElement(cobertura, "healthyTarget")
+ targets = XML.SubElement(
+ healthy,
+ "targets",
+ {
+ "class": "enum-map",
+ "enum-type": "hudson.plugins.cobertura.targets.CoverageMetric",
+ },
+ )
+ for item in data["targets"]:
item_name = next(iter(item.keys()))
item_values = item.get(item_name, 0)
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry,
- 'hudson.plugins.cobertura.targets.'
- 'CoverageMetric').text = str(item_name).upper()
- XML.SubElement(entry, 'int').text = str(item_values.get('healthy', 0))
- unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
- targets = XML.SubElement(unhealthy, 'targets', {
- 'class': 'enum-map',
- 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
- for item in data['targets']:
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets." "CoverageMetric"
+ ).text = str(item_name).upper()
+ XML.SubElement(entry, "int").text = str(item_values.get("healthy", 0))
+ unhealthy = XML.SubElement(cobertura, "unhealthyTarget")
+ targets = XML.SubElement(
+ unhealthy,
+ "targets",
+ {
+ "class": "enum-map",
+ "enum-type": "hudson.plugins.cobertura.targets.CoverageMetric",
+ },
+ )
+ for item in data["targets"]:
item_name = next(iter(item.keys()))
item_values = item.get(item_name, 0)
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
- 'CoverageMetric').text = str(item_name).upper()
- XML.SubElement(entry, 'int').text = str(item_values.get('unhealthy',
- 0))
- failing = XML.SubElement(cobertura, 'failingTarget')
- targets = XML.SubElement(failing, 'targets', {
- 'class': 'enum-map',
- 'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
- for item in data['targets']:
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets." "CoverageMetric"
+ ).text = str(item_name).upper()
+ XML.SubElement(entry, "int").text = str(item_values.get("unhealthy", 0))
+ failing = XML.SubElement(cobertura, "failingTarget")
+ targets = XML.SubElement(
+ failing,
+ "targets",
+ {
+ "class": "enum-map",
+ "enum-type": "hudson.plugins.cobertura.targets.CoverageMetric",
+ },
+ )
+ for item in data["targets"]:
item_name = next(iter(item.keys()))
item_values = item.get(item_name, 0)
- entry = XML.SubElement(targets, 'entry')
- XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
- 'CoverageMetric').text = str(item_name).upper()
- XML.SubElement(entry, 'int').text = str(item_values.get('failing', 0))
- XML.SubElement(cobertura, 'sourceEncoding').text = data.get(
- 'source-encoding', 'ASCII')
+ entry = XML.SubElement(targets, "entry")
+ XML.SubElement(
+ entry, "hudson.plugins.cobertura.targets." "CoverageMetric"
+ ).text = str(item_name).upper()
+ XML.SubElement(entry, "int").text = str(item_values.get("failing", 0))
+ XML.SubElement(cobertura, "sourceEncoding").text = data.get(
+ "source-encoding", "ASCII"
+ )
def jacoco(registry, xml_parent, data):
@@ -1133,50 +1161,40 @@ def jacoco(registry, xml_parent, data):
:language: yaml
"""
- jacoco = XML.SubElement(xml_parent,
- 'hudson.plugins.jacoco.JacocoPublisher')
- jacoco.set('plugin', 'jacoco')
+ jacoco = XML.SubElement(xml_parent, "hudson.plugins.jacoco.JacocoPublisher")
+ jacoco.set("plugin", "jacoco")
mappings = [
- ('exec-pattern', 'execPattern', '**/**.exec'),
- ('class-pattern', 'classPattern', '**/classes'),
- ('source-pattern', 'sourcePattern', '**/src/main/java'),
- ('source-inclusion-pattern', 'sourceInclusionPattern', '**/*.java'),
- ('update-build-status', 'changeBuildStatus', False),
- ('inclusion-pattern', 'inclusionPattern', ''),
- ('exclusion-pattern', 'exclusionPattern', ''),
+ ("exec-pattern", "execPattern", "**/**.exec"),
+ ("class-pattern", "classPattern", "**/classes"),
+ ("source-pattern", "sourcePattern", "**/src/main/java"),
+ ("source-inclusion-pattern", "sourceInclusionPattern", "**/*.java"),
+ ("update-build-status", "changeBuildStatus", False),
+ ("inclusion-pattern", "inclusionPattern", ""),
+ ("exclusion-pattern", "exclusionPattern", ""),
]
helpers.convert_mapping_to_xml(jacoco, data, mappings, fail_required=True)
- itemsList = ['instruction',
- 'branch',
- 'complexity',
- 'line',
- 'method',
- 'class']
+ itemsList = ["instruction", "branch", "complexity", "line", "method", "class"]
- if 'targets' in data:
- for item in data['targets']:
+ if "targets" in data:
+ for item in data["targets"]:
item_name = next(iter(item.keys()))
if item_name not in itemsList:
- raise InvalidAttributeError('targets', item_name, itemsList)
+ raise InvalidAttributeError("targets", item_name, itemsList)
item_values = item[item_name]
if item_values:
- XML.SubElement(jacoco,
- 'maximum' +
- item_name.capitalize() +
- 'Coverage').text = str(
- item_values.get('healthy', 0))
- XML.SubElement(jacoco,
- 'minimum' +
- item_name.capitalize() +
- 'Coverage').text = str(
- item_values.get('unhealthy', 0))
+ XML.SubElement(
+ jacoco, "maximum" + item_name.capitalize() + "Coverage"
+ ).text = str(item_values.get("healthy", 0))
+ XML.SubElement(
+ jacoco, "minimum" + item_name.capitalize() + "Coverage"
+ ).text = str(item_values.get("unhealthy", 0))
else:
raise MissingAttributeError(
- ['healthy', 'unhealthy'],
- 'publishers.jacoco.targets.' + item_name)
+ ["healthy", "unhealthy"], "publishers.jacoco.targets." + item_name
+ )
def ftp(registry, xml_parent, data):
@@ -1216,24 +1234,24 @@ def ftp(registry, xml_parent, data):
:language: yaml
"""
- console_prefix = 'FTP: '
- plugin_tag = 'jenkins.plugins.publish__over__ftp.BapFtpPublisherPlugin'
- publisher_tag = 'jenkins.plugins.publish__over__ftp.BapFtpPublisher'
- transfer_tag = 'jenkins.plugins.publish__over__ftp.BapFtpTransfer'
- retry_tag = 'jenkins.plugins.publish_over_ftp.BapFtpRetry'
- plugin_reference_tag = 'jenkins.plugins.publish_over_ftp.' \
- 'BapFtpPublisherPlugin'
- (_, transfer_node) = base_publish_over(xml_parent,
- data,
- console_prefix,
- plugin_tag,
- publisher_tag,
- transfer_tag,
- retry_tag,
- plugin_reference_tag)
- mapping = [('', 'asciiMode', 'false')]
- helpers.convert_mapping_to_xml(
- transfer_node, data, mapping, fail_required=True)
+ console_prefix = "FTP: "
+ plugin_tag = "jenkins.plugins.publish__over__ftp.BapFtpPublisherPlugin"
+ publisher_tag = "jenkins.plugins.publish__over__ftp.BapFtpPublisher"
+ transfer_tag = "jenkins.plugins.publish__over__ftp.BapFtpTransfer"
+ retry_tag = "jenkins.plugins.publish_over_ftp.BapFtpRetry"
+ plugin_reference_tag = "jenkins.plugins.publish_over_ftp." "BapFtpPublisherPlugin"
+ (_, transfer_node) = base_publish_over(
+ xml_parent,
+ data,
+ console_prefix,
+ plugin_tag,
+ publisher_tag,
+ transfer_tag,
+ retry_tag,
+ plugin_reference_tag,
+ )
+ mapping = [("", "asciiMode", "false")]
+ helpers.convert_mapping_to_xml(transfer_node, data, mapping, fail_required=True)
def ftp_publisher(registry, xml_parent, data):
@@ -1269,25 +1287,26 @@ def ftp_publisher(registry, xml_parent, data):
/../../tests/publishers/fixtures/ftp-publisher-full.yaml
:language: yaml
"""
- ftp = XML.SubElement(xml_parent, 'com.zanox.hudson.plugins.FTPPublisher')
- ftp.set('plugin', 'ftppublisher')
+ ftp = XML.SubElement(xml_parent, "com.zanox.hudson.plugins.FTPPublisher")
+ ftp.set("plugin", "ftppublisher")
- entries = XML.SubElement(ftp, 'entries')
- if 'uploads' in data:
+ entries = XML.SubElement(ftp, "entries")
+ if "uploads" in data:
upload_mapping = [
- ('file-path', 'filePath', ''),
- ('source-file', 'sourceFile', ''),
+ ("file-path", "filePath", ""),
+ ("source-file", "sourceFile", ""),
]
- for upload in data['uploads']:
- entry = XML.SubElement(entries, 'com.zanox.hudson.plugins.Entry')
+ for upload in data["uploads"]:
+ entry = XML.SubElement(entries, "com.zanox.hudson.plugins.Entry")
helpers.convert_mapping_to_xml(
- entry, upload, upload_mapping, fail_required=True)
+ entry, upload, upload_mapping, fail_required=True
+ )
mapping = [
- ('site-name', 'siteName', None),
- ('use-timestamps', 'useTimestamps', False),
- ('flatten-files', 'flatten', False),
- ('skip-publishing', 'skip', False),
+ ("site-name", "siteName", None),
+ ("use-timestamps", "useTimestamps", False),
+ ("flatten-files", "flatten", False),
+ ("skip-publishing", "skip", False),
]
helpers.convert_mapping_to_xml(ftp, data, mapping, fail_required=True)
@@ -1349,74 +1368,82 @@ def rocket(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/rocket002.yaml
:language: yaml
"""
- rocketchat = XML.SubElement(xml_parent,
- 'jenkins.plugins.rocketchatnotifier.RocketChatNotifier')
- rocketchat.set('plugin', 'rocketchatnotifier')
+ rocketchat = XML.SubElement(
+ xml_parent, "jenkins.plugins.rocketchatnotifier.RocketChatNotifier"
+ )
+ rocketchat.set("plugin", "rocketchatnotifier")
required_mapping = [
- ('channel', 'channel', ''),
- ('start', 'startNotification', False),
- ('success', 'notifySuccess', False),
- ('abort', 'notifyAborted', False),
- ('not-built', 'notifyNotBuilt', False),
- ('unstable', 'notifyUnstable', False),
- ('failure', 'notifyFailure', False),
- ('back-to-normal', 'notifyBackToNormal', False),
- ('repeated-failure', 'notifyRepeatedFailure', False),
- ('include-test-summary', 'includeTestSummary', False),
- ('include-test-log', 'includeTestLog', False),
- ('include-custom-message', 'includeCustomMessage', False),
- ('commit-info', 'commitInfoChoice', 'none',
+ ("channel", "channel", ""),
+ ("start", "startNotification", False),
+ ("success", "notifySuccess", False),
+ ("abort", "notifyAborted", False),
+ ("not-built", "notifyNotBuilt", False),
+ ("unstable", "notifyUnstable", False),
+ ("failure", "notifyFailure", False),
+ ("back-to-normal", "notifyBackToNormal", False),
+ ("repeated-failure", "notifyRepeatedFailure", False),
+ ("include-test-summary", "includeTestSummary", False),
+ ("include-test-log", "includeTestLog", False),
+ ("include-custom-message", "includeCustomMessage", False),
+ (
+ "commit-info",
+ "commitInfoChoice",
+ "none",
{
- 'none': 'NONE',
- 'authors': 'AUTHORS',
- 'authors-and-titles': 'AUTHORS_AND_TITLES'
- }),
- ('raw-message', 'rawMessage', False),
- ('webhook-token', 'webhookToken', ''),
- ('webhook-token-credential-id', 'webhookTokenCredentialId', ''),
+ "none": "NONE",
+ "authors": "AUTHORS",
+ "authors-and-titles": "AUTHORS_AND_TITLES",
+ },
+ ),
+ ("raw-message", "rawMessage", False),
+ ("webhook-token", "webhookToken", ""),
+ ("webhook-token-credential-id", "webhookTokenCredentialId", ""),
]
optional_mapping = [
- ('trust-ssl', 'trustSSL', None),
- ('build-server', 'buildServerUrl', None),
+ ("trust-ssl", "trustSSL", None),
+ ("build-server", "buildServerUrl", None),
]
helpers.convert_mapping_to_xml(
- rocketchat, data, optional_mapping, fail_required=False)
+ rocketchat, data, optional_mapping, fail_required=False
+ )
helpers.convert_mapping_to_xml(
- rocketchat, data, required_mapping, fail_required=True)
+ rocketchat, data, required_mapping, fail_required=True
+ )
- attach_required_mapping = [
- ('title', 'title', None),
- ]
+ attach_required_mapping = [("title", "title", None)]
attach_optional_mapping = [
- ('title-link', 'titleLink', None),
- ('title-link-download', 'titleLinkDownload', None),
- ('color', 'color', None),
- ('text', 'text', None),
- ('collapsed', 'collapsed', None), # false | true
- ('message-link', 'messageLink', None),
- ('author-name', 'authorName', None),
- ('author-link', 'authorLink', None),
- ('author-icon', 'authorIcon', None),
- ('thumb', 'thumbUrl', None),
- ('image', 'imageUrl', None),
- ('audio', 'audioUrl', None),
- ('video', 'videoUrl', None),
+ ("title-link", "titleLink", None),
+ ("title-link-download", "titleLinkDownload", None),
+ ("color", "color", None),
+ ("text", "text", None),
+ ("collapsed", "collapsed", None), # false | true
+ ("message-link", "messageLink", None),
+ ("author-name", "authorName", None),
+ ("author-link", "authorLink", None),
+ ("author-icon", "authorIcon", None),
+ ("thumb", "thumbUrl", None),
+ ("image", "imageUrl", None),
+ ("audio", "audioUrl", None),
+ ("video", "videoUrl", None),
]
- attach_list = data.get('attachments', None)
+ attach_list = data.get("attachments", None)
- attachments = XML.SubElement(rocketchat, 'attachments')
+ attachments = XML.SubElement(rocketchat, "attachments")
if attach_list is not None:
for attach_data in attach_list:
- item = XML.SubElement(attachments,
- 'jenkins.plugins.rocketchatnotifier.model.MessageAttachment')
- helpers.convert_mapping_to_xml(item, attach_data,
- attach_required_mapping, fail_required=True)
- helpers.convert_mapping_to_xml(item, attach_data,
- attach_optional_mapping, fail_required=False)
+ item = XML.SubElement(
+ attachments,
+ "jenkins.plugins.rocketchatnotifier.model.MessageAttachment",
+ )
+ helpers.convert_mapping_to_xml(
+ item, attach_data, attach_required_mapping, fail_required=True
+ )
+ helpers.convert_mapping_to_xml(
+ item, attach_data, attach_optional_mapping, fail_required=False
+ )
- XML.SubElement(rocketchat, 'customMessage').text = \
- data.get('custom-message', '')
+ XML.SubElement(rocketchat, "customMessage").text = data.get("custom-message", "")
def hp_alm(registry, xml_parent, data):
@@ -1468,25 +1495,26 @@ def hp_alm(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/hp-alm002.yaml
:language: yaml
"""
- alm_uploader = XML.SubElement(xml_parent,
- 'com.microfocus.application.automation.'
- 'tools.results.TestResultToALMUploader')
- alm_uploader.set('plugin', 'hp-application-automation-tools-plugin')
+ alm_uploader = XML.SubElement(
+ xml_parent,
+ "com.microfocus.application.automation."
+ "tools.results.TestResultToALMUploader",
+ )
+ alm_uploader.set("plugin", "hp-application-automation-tools-plugin")
mapping = [
- ('server-name', 'almServerName', None),
- ('credentials-id', 'credentialsId', ''),
- ('domain', 'almDomain', None),
- ('project', 'almProject', None),
- ('client-type', 'clientType', ''),
- ('testing-framework', 'testingFramework', 'JUnit'),
- ('testing-tool', 'testingTool', ''),
- ('folder', 'almTestFolder', None),
- ('set-folder', 'almTestSetFolder', None),
- ('testing-result-file', 'testingResultFile', None),
- ('jenkins-server-url', 'jenkinsServerUrl', ''),
+ ("server-name", "almServerName", None),
+ ("credentials-id", "credentialsId", ""),
+ ("domain", "almDomain", None),
+ ("project", "almProject", None),
+ ("client-type", "clientType", ""),
+ ("testing-framework", "testingFramework", "JUnit"),
+ ("testing-tool", "testingTool", ""),
+ ("folder", "almTestFolder", None),
+ ("set-folder", "almTestSetFolder", None),
+ ("testing-result-file", "testingResultFile", None),
+ ("jenkins-server-url", "jenkinsServerUrl", ""),
]
- helpers.convert_mapping_to_xml(
- alm_uploader, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(alm_uploader, data, mapping, fail_required=True)
def junit(registry, xml_parent, data):
@@ -1528,36 +1556,37 @@ def junit(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/junit002.yaml
:language: yaml
"""
- junitresult = XML.SubElement(xml_parent,
- 'hudson.tasks.junit.JUnitResultArchiver')
- junitresult.set('plugin', 'junit')
+ junitresult = XML.SubElement(xml_parent, "hudson.tasks.junit.JUnitResultArchiver")
+ junitresult.set("plugin", "junit")
mapping = [
- ('results', 'testResults', None),
- ('keep-long-stdio', 'keepLongStdio', True),
- ('health-scale-factor', 'healthScaleFactor', '1.0'),
- ('allow-empty-results', 'allowEmptyResults', False),
+ ("results", "testResults", None),
+ ("keep-long-stdio", "keepLongStdio", True),
+ ("health-scale-factor", "healthScaleFactor", "1.0"),
+ ("allow-empty-results", "allowEmptyResults", False),
]
- helpers.convert_mapping_to_xml(
- junitresult, data, mapping, fail_required=True)
-
- datapublisher = XML.SubElement(junitresult, 'testDataPublishers')
- if str(data.get('test-stability', False)).lower() == 'true':
- XML.SubElement(datapublisher,
- 'de.esailors.jenkins.teststability'
- '.StabilityTestDataPublisher')
- if str(data.get('claim-build', False)).lower() == 'true':
- XML.SubElement(datapublisher,
- 'hudson.plugins.claim.ClaimTestDataPublisher')
- if str(data.get('measurement-plots', False)).lower() == 'true':
- XML.SubElement(datapublisher,
- 'hudson.plugins.measurement__plots.TestDataPublisher')
- if str(data.get('flaky-test-reports', False)).lower() == 'true':
- XML.SubElement(datapublisher,
- 'com.google.jenkins.flakyTestHandler.plugin'
- '.JUnitFlakyTestDataPublisher')
- if str(data.get('junit-attachments', False)).lower() == 'true':
- XML.SubElement(datapublisher,
- 'hudson.plugins.junitattachments.AttachmentPublisher')
+ helpers.convert_mapping_to_xml(junitresult, data, mapping, fail_required=True)
+
+ datapublisher = XML.SubElement(junitresult, "testDataPublishers")
+ if str(data.get("test-stability", False)).lower() == "true":
+ XML.SubElement(
+ datapublisher,
+ "de.esailors.jenkins.teststability" ".StabilityTestDataPublisher",
+ )
+ if str(data.get("claim-build", False)).lower() == "true":
+ XML.SubElement(datapublisher, "hudson.plugins.claim.ClaimTestDataPublisher")
+ if str(data.get("measurement-plots", False)).lower() == "true":
+ XML.SubElement(
+ datapublisher, "hudson.plugins.measurement__plots.TestDataPublisher"
+ )
+ if str(data.get("flaky-test-reports", False)).lower() == "true":
+ XML.SubElement(
+ datapublisher,
+ "com.google.jenkins.flakyTestHandler.plugin" ".JUnitFlakyTestDataPublisher",
+ )
+ if str(data.get("junit-attachments", False)).lower() == "true":
+ XML.SubElement(
+ datapublisher, "hudson.plugins.junitattachments.AttachmentPublisher"
+ )
def cucumber_reports(registry, xml_parent, data):
@@ -1619,54 +1648,54 @@ def cucumber_reports(registry, xml_parent, data):
/../../tests/publishers/fixtures/cucumber-reports-minimal.yaml
:language: yaml
"""
- cucumber_reports = XML.SubElement(xml_parent,
- 'net.masterthought.jenkins.'
- 'CucumberReportPublisher')
- cucumber_reports.set('plugin', 'cucumber-reports')
+ cucumber_reports = XML.SubElement(
+ xml_parent, "net.masterthought.jenkins." "CucumberReportPublisher"
+ )
+ cucumber_reports.set("plugin", "cucumber-reports")
- valid_build_status = ['', 'UNSTABLE', 'FAILURE']
- valid_sorting_method = ['NATURAL', 'ALPHABETICAL']
+ valid_build_status = ["", "UNSTABLE", "FAILURE"]
+ valid_sorting_method = ["NATURAL", "ALPHABETICAL"]
mappings = [
- ('json-reports-path', 'jsonReportDirectory', ''),
- ('plugin-url-path', 'pluginUrlPath', ''),
- ('file-include-pattern', 'fileIncludePattern', ''),
- ('file-exclude-pattern', 'fileExcludePattern', ''),
- ('skipped-fails', 'skippedFails', False),
- ('pending-fails', 'pendingFails', False),
- ('undefined-fails', 'undefinedFails', False),
- ('missing-fails', 'missingFails', False),
- ('no-flash-charts', 'noFlashCharts', False),
- ('ignore-failed-tests', 'ignoreFailedTests', False),
- ('parallel-testing', 'parallelTesting', False),
- ('failed-steps-number', 'failedStepsNumber', 0),
- ('skipped-steps-number', 'skippedStepsNumber', 0),
- ('pending-steps-number', 'pendingStepsNumber', 0),
- ('undefined-steps-number', 'undefinedStepsNumber', 0),
- ('failed-scenarios-number', 'failedScenariosNumber', 0),
- ('failed-features-number', 'failedFeaturesNumber', 0),
- ('build-status', 'buildStatus', '', valid_build_status),
- ('trends-limit', 'trendsLimit', 0),
- ('sorting-method', 'sortingMethod', 'NATURAL', valid_sorting_method),
+ ("json-reports-path", "jsonReportDirectory", ""),
+ ("plugin-url-path", "pluginUrlPath", ""),
+ ("file-include-pattern", "fileIncludePattern", ""),
+ ("file-exclude-pattern", "fileExcludePattern", ""),
+ ("skipped-fails", "skippedFails", False),
+ ("pending-fails", "pendingFails", False),
+ ("undefined-fails", "undefinedFails", False),
+ ("missing-fails", "missingFails", False),
+ ("no-flash-charts", "noFlashCharts", False),
+ ("ignore-failed-tests", "ignoreFailedTests", False),
+ ("parallel-testing", "parallelTesting", False),
+ ("failed-steps-number", "failedStepsNumber", 0),
+ ("skipped-steps-number", "skippedStepsNumber", 0),
+ ("pending-steps-number", "pendingStepsNumber", 0),
+ ("undefined-steps-number", "undefinedStepsNumber", 0),
+ ("failed-scenarios-number", "failedScenariosNumber", 0),
+ ("failed-features-number", "failedFeaturesNumber", 0),
+ ("build-status", "buildStatus", "", valid_build_status),
+ ("trends-limit", "trendsLimit", 0),
+ ("sorting-method", "sortingMethod", "NATURAL", valid_sorting_method),
]
- helpers.convert_mapping_to_xml(
- cucumber_reports, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(cucumber_reports, data, mappings, fail_required=True)
- if 'sorting-values' in data:
+ if "sorting-values" in data:
format_dict = {
- 'classifications': 'net.masterthought.jenkins'
- '.CucumberReportPublisher_-Classification'
+ "classifications": "net.masterthought.jenkins"
+ ".CucumberReportPublisher_-Classification"
}
- classifications_tag = XML.SubElement(
- cucumber_reports, 'classifications')
- for values in data['sorting-values']:
+ classifications_tag = XML.SubElement(cucumber_reports, "classifications")
+ for values in data["sorting-values"]:
for value, params in values.items():
cucumber_report_publisher = XML.SubElement(
- classifications_tag, format_dict.get('classifications'))
- XML.SubElement(
- cucumber_report_publisher, 'key').text = params.get('key')
- XML.SubElement(
- cucumber_report_publisher, 'value').text = params.get(
- 'value')
+ classifications_tag, format_dict.get("classifications")
+ )
+ XML.SubElement(cucumber_report_publisher, "key").text = params.get(
+ "key"
+ )
+ XML.SubElement(cucumber_report_publisher, "value").text = params.get(
+ "value"
+ )
def cucumber_testresult(registry, xml_parent, data):
@@ -1690,18 +1719,19 @@ def cucumber_testresult(registry, xml_parent, data):
/../../tests/publishers/fixtures/cucumber-testresult-full.yaml
:language: yaml
"""
- cucumber_result = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.cucumber.'
- 'jsontestsupport.'
- 'CucumberTestResultArchiver')
- cucumber_result.set('plugin', 'cucumber-testresult-plugin')
+ cucumber_result = XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins.cucumber."
+ "jsontestsupport."
+ "CucumberTestResultArchiver",
+ )
+ cucumber_result.set("plugin", "cucumber-testresult-plugin")
mappings = [
- ('results', 'testResults', None),
- ('ignore-bad-steps', 'ignoreBadSteps', False)
+ ("results", "testResults", None),
+ ("ignore-bad-steps", "ignoreBadSteps", False),
]
- helpers.convert_mapping_to_xml(
- cucumber_result, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(cucumber_result, data, mappings, fail_required=True)
def xunit(registry, xml_parent, data):
@@ -1754,28 +1784,28 @@ def xunit(registry, xml_parent, data):
"""
logger = logging.getLogger(__name__)
- xunit = XML.SubElement(xml_parent, 'xunit')
- xunit.set('plugin', 'xunit')
+ xunit = XML.SubElement(xml_parent, "xunit")
+ xunit.set("plugin", "xunit")
# Map our internal types to the XML element names used by Jenkins plugin
types_to_plugin_types = {
- 'aunit': 'AUnitJunitHudsonTestType',
- 'boosttest': 'BoostTestJunitHudsonTestType',
- 'checktype': 'CheckType',
- 'cpptest': 'CppTestJunitHudsonTestType',
- 'cppunit': 'CppUnitJunitHudsonTestType',
- 'ctest': 'CTestType',
- 'dotnettest': 'XUnitDotNetTestType', # since plugin v1.93
- 'embunit': 'EmbUnitType', # since plugin v1.84
- 'fpcunit': 'FPCUnitJunitHudsonTestType',
- 'gtest': 'GoogleTestType',
- 'junit': 'JUnitType',
- 'mstest': 'MSTestJunitHudsonTestType',
- 'nunit': 'NUnitJunitHudsonTestType',
- 'phpunit': 'PHPUnitJunitHudsonTestType',
- 'tusar': 'TUSARJunitHudsonTestType',
- 'unittest': 'UnitTestJunitHudsonTestType',
- 'valgrind': 'ValgrindJunitHudsonTestType',
+ "aunit": "AUnitJunitHudsonTestType",
+ "boosttest": "BoostTestJunitHudsonTestType",
+ "checktype": "CheckType",
+ "cpptest": "CppTestJunitHudsonTestType",
+ "cppunit": "CppUnitJunitHudsonTestType",
+ "ctest": "CTestType",
+ "dotnettest": "XUnitDotNetTestType", # since plugin v1.93
+ "embunit": "EmbUnitType", # since plugin v1.84
+ "fpcunit": "FPCUnitJunitHudsonTestType",
+ "gtest": "GoogleTestType",
+ "junit": "JUnitType",
+ "mstest": "MSTestJunitHudsonTestType",
+ "nunit": "NUnitJunitHudsonTestType",
+ "phpunit": "PHPUnitJunitHudsonTestType",
+ "tusar": "TUSARJunitHudsonTestType",
+ "unittest": "UnitTestJunitHudsonTestType",
+ "valgrind": "ValgrindJunitHudsonTestType",
# FIXME should implement the 'custom' type
}
implemented_types = types_to_plugin_types.keys() # shortcut
@@ -1783,87 +1813,85 @@ def xunit(registry, xml_parent, data):
# Unit framework we are going to generate xml for
supported_types = []
- for configured_type in data['types']:
+ for configured_type in data["types"]:
type_name = next(iter(configured_type.keys()))
if type_name not in implemented_types:
- logger.warning("Requested xUnit type '%s' is not yet supported",
- type_name)
+ logger.warning("Requested xUnit type '%s' is not yet supported", type_name)
else:
# Append for generation
supported_types.append(configured_type)
# Generate XML for each of the supported framework types
- xmltypes = XML.SubElement(xunit, 'types')
+ xmltypes = XML.SubElement(xunit, "types")
for supported_type in supported_types:
framework_name = next(iter(supported_type.keys()))
- xmlframework = XML.SubElement(xmltypes,
- types_to_plugin_types[framework_name])
+ xmlframework = XML.SubElement(xmltypes, types_to_plugin_types[framework_name])
mappings = [
- ('pattern', 'pattern', ''),
- ('requireupdate', 'failIfNotNew', True),
- ('deleteoutput', 'deleteOutputFiles', True),
- ('skip-if-no-test-files', 'skipNoTestFiles', False),
- ('stoponerror', 'stopProcessingIfError', True),
+ ("pattern", "pattern", ""),
+ ("requireupdate", "failIfNotNew", True),
+ ("deleteoutput", "deleteOutputFiles", True),
+ ("skip-if-no-test-files", "skipNoTestFiles", False),
+ ("stoponerror", "stopProcessingIfError", True),
]
- helpers.convert_mapping_to_xml(xmlframework,
- supported_type[framework_name],
- mappings,
- fail_required=True)
-
- xmlthresholds = XML.SubElement(xunit, 'thresholds')
- for t in data.get('thresholds', []):
- if not ('failed' in t or 'skipped' in t):
- logger.warning(
- "Unrecognized threshold, should be 'failed' or 'skipped'")
+ helpers.convert_mapping_to_xml(
+ xmlframework, supported_type[framework_name], mappings, fail_required=True
+ )
+
+ xmlthresholds = XML.SubElement(xunit, "thresholds")
+ for t in data.get("thresholds", []):
+ if not ("failed" in t or "skipped" in t):
+ logger.warning("Unrecognized threshold, should be 'failed' or 'skipped'")
continue
- elname = ("org.jenkinsci.plugins.xunit.threshold.%sThreshold" %
- next(iter(t.keys())).title())
+ elname = (
+ "org.jenkinsci.plugins.xunit.threshold.%sThreshold"
+ % next(iter(t.keys())).title()
+ )
el = XML.SubElement(xmlthresholds, elname)
for threshold_name, threshold_value in next(iter(t.values())).items():
# Normalize and craft the element name for this threshold
- elname = "%sThreshold" % threshold_name.lower().replace(
- 'new', 'New')
+ elname = "%sThreshold" % threshold_name.lower().replace("new", "New")
XML.SubElement(el, elname).text = str(threshold_value)
# Whether to use percent of exact number of tests.
# Thresholdmode is either:
# - 1 : absolute (number of tests), default.
# - 2 : relative (percentage of tests)
- thresholdmode = '1'
- if 'percent' == data.get('thresholdmode', 'number'):
- thresholdmode = '2'
- XML.SubElement(xunit, 'thresholdMode').text = thresholdmode
-
- extra_config = XML.SubElement(xunit, 'extraConfiguration')
- XML.SubElement(extra_config, 'testTimeMargin').text = str(
- data.get('test-time-margin', '3000'))
+ thresholdmode = "1"
+ if "percent" == data.get("thresholdmode", "number"):
+ thresholdmode = "2"
+ XML.SubElement(xunit, "thresholdMode").text = thresholdmode
+
+ extra_config = XML.SubElement(xunit, "extraConfiguration")
+ XML.SubElement(extra_config, "testTimeMargin").text = str(
+ data.get("test-time-margin", "3000")
+ )
def _violations_add_entry(xml_parent, name, data):
- vmin = data.get('min', 10)
- vmax = data.get('max', 999)
- vunstable = data.get('unstable', 999)
- pattern = data.get('pattern', None)
+ vmin = data.get("min", 10)
+ vmax = data.get("max", 999)
+ vunstable = data.get("unstable", 999)
+ pattern = data.get("pattern", None)
- entry = XML.SubElement(xml_parent, 'entry')
- mapping = [('', 'string', name)]
+ entry = XML.SubElement(xml_parent, "entry")
+ mapping = [("", "string", name)]
helpers.convert_mapping_to_xml(entry, data, mapping, fail_required=True)
- tconfig = XML.SubElement(entry, 'hudson.plugins.violations.TypeConfig')
+ tconfig = XML.SubElement(entry, "hudson.plugins.violations.TypeConfig")
mapping = [
- ('', 'type', name),
- ('', 'min', str(vmin)),
- ('', 'max', str(vmax)),
- ('', 'unstable', str(vunstable)),
- ('', 'usePattern', 'false'),
+ ("", "type", name),
+ ("", "min", str(vmin)),
+ ("", "max", str(vmax)),
+ ("", "unstable", str(vunstable)),
+ ("", "usePattern", "false"),
]
helpers.convert_mapping_to_xml(tconfig, data, mapping, fail_required=True)
if pattern:
- XML.SubElement(tconfig, 'pattern').text = pattern
+ XML.SubElement(tconfig, "pattern").text = pattern
else:
- XML.SubElement(tconfig, 'pattern')
+ XML.SubElement(tconfig, "pattern")
def violations(registry, xml_parent, data):
@@ -1893,38 +1921,39 @@ def violations(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/violations001.yaml
:language: yaml
"""
- violations = XML.SubElement(xml_parent,
- 'hudson.plugins.violations.'
- 'ViolationsPublisher')
- config = XML.SubElement(violations, 'config')
- suppressions = XML.SubElement(config, 'suppressions',
- {'class': 'tree-set'})
- XML.SubElement(suppressions, 'no-comparator')
- configs = XML.SubElement(config, 'typeConfigs')
- XML.SubElement(configs, 'no-comparator')
-
- for name in ['checkstyle',
- 'codenarc',
- 'cpd',
- 'cpplint',
- 'csslint',
- 'findbugs',
- 'fxcop',
- 'gendarme',
- 'jcreport',
- 'jslint',
- 'pep8',
- 'perlcritic',
- 'pmd',
- 'pylint',
- 'simian',
- 'stylecop']:
+ violations = XML.SubElement(
+ xml_parent, "hudson.plugins.violations." "ViolationsPublisher"
+ )
+ config = XML.SubElement(violations, "config")
+ suppressions = XML.SubElement(config, "suppressions", {"class": "tree-set"})
+ XML.SubElement(suppressions, "no-comparator")
+ configs = XML.SubElement(config, "typeConfigs")
+ XML.SubElement(configs, "no-comparator")
+
+ for name in [
+ "checkstyle",
+ "codenarc",
+ "cpd",
+ "cpplint",
+ "csslint",
+ "findbugs",
+ "fxcop",
+ "gendarme",
+ "jcreport",
+ "jslint",
+ "pep8",
+ "perlcritic",
+ "pmd",
+ "pylint",
+ "simian",
+ "stylecop",
+ ]:
_violations_add_entry(configs, name, data.get(name, {}))
mapping = [
- ('', 'limit', '100'),
- ('', 'sourcePathPattern', ''),
- ('', 'fauxProjectPath', ''),
- ('', 'encoding', 'default'),
+ ("", "limit", "100"),
+ ("", "sourcePathPattern", ""),
+ ("", "fauxProjectPath", ""),
+ ("", "encoding", "default"),
]
helpers.convert_mapping_to_xml(config, data, mapping, fail_required=True)
@@ -1990,12 +2019,11 @@ def findbugs(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/findbugs-full.yaml
"""
- findbugs = XML.SubElement(xml_parent,
- 'hudson.plugins.findbugs.FindBugsPublisher')
- findbugs.set('plugin', 'findbugs')
+ findbugs = XML.SubElement(xml_parent, "hudson.plugins.findbugs.FindBugsPublisher")
+ findbugs.set("plugin", "findbugs")
helpers.findbugs_settings(findbugs, data)
- helpers.build_trends_publisher('[FINDBUGS] ', findbugs, data)
+ helpers.build_trends_publisher("[FINDBUGS] ", findbugs, data)
def checkstyle(registry, xml_parent, data):
@@ -2062,6 +2090,7 @@ def checkstyle(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/checkstyle006.yaml
:language: yaml
"""
+
def convert_settings(lookup, data):
"""Helper to convert settings from one key to another
"""
@@ -2071,30 +2100,36 @@ def checkstyle(registry, xml_parent, data):
data.setdefault(lookup[old_key], data[old_key])
del data[old_key]
- checkstyle = XML.SubElement(xml_parent,
- 'hudson.plugins.checkstyle.'
- 'CheckStylePublisher')
- checkstyle.set('plugin', 'checkstyle')
+ checkstyle = XML.SubElement(
+ xml_parent, "hudson.plugins.checkstyle." "CheckStylePublisher"
+ )
+ checkstyle.set("plugin", "checkstyle")
# Convert old style yaml to new style
- convert_settings({
- 'unHealthy': 'unhealthy',
- 'healthThreshold': 'health-threshold',
- 'defaultEncoding': 'default-encoding',
- 'canRunOnFailed': 'can-run-on-failed',
- 'shouldDetectModules': 'should-detect-modules'
- }, data)
-
- threshold_data = data.get('thresholds', {})
- for threshold in ['unstable', 'failed']:
- convert_settings({
- 'totalAll': 'total-all',
- 'totalHigh': 'total-high',
- 'totalNormal': 'total-normal',
- 'totalLow': 'total-low'
- }, threshold_data.get(threshold, {}))
-
- helpers.build_trends_publisher('[CHECKSTYLE] ', checkstyle, data)
+ convert_settings(
+ {
+ "unHealthy": "unhealthy",
+ "healthThreshold": "health-threshold",
+ "defaultEncoding": "default-encoding",
+ "canRunOnFailed": "can-run-on-failed",
+ "shouldDetectModules": "should-detect-modules",
+ },
+ data,
+ )
+
+ threshold_data = data.get("thresholds", {})
+ for threshold in ["unstable", "failed"]:
+ convert_settings(
+ {
+ "totalAll": "total-all",
+ "totalHigh": "total-high",
+ "totalNormal": "total-normal",
+ "totalLow": "total-low",
+ },
+ threshold_data.get(threshold, {}),
+ )
+
+ helpers.build_trends_publisher("[CHECKSTYLE] ", checkstyle, data)
def scp(registry, xml_parent, data):
@@ -2140,27 +2175,25 @@ def scp(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/scp001.yaml
:language: yaml
"""
- scp = XML.SubElement(xml_parent,
- 'be.certipost.hudson.plugin.SCPRepositoryPublisher')
- scp.set('plugin', 'scp')
+ scp = XML.SubElement(
+ xml_parent, "be.certipost.hudson.plugin.SCPRepositoryPublisher"
+ )
+ scp.set("plugin", "scp")
- mappings = [
- ('site', 'siteName', None),
- ]
+ mappings = [("site", "siteName", None)]
helpers.convert_mapping_to_xml(scp, data, mappings, fail_required=True)
- entries = XML.SubElement(scp, 'entries')
- for entry in data['files']:
- entry_e = XML.SubElement(entries, 'be.certipost.hudson.plugin.Entry')
+ entries = XML.SubElement(scp, "entries")
+ for entry in data["files"]:
+ entry_e = XML.SubElement(entries, "be.certipost.hudson.plugin.Entry")
mappings = [
- ('target', 'filePath', None),
- ('source', 'sourceFile', ''),
- ('keep-hierarchy', 'keepHierarchy', False),
- ('copy-console', 'copyConsoleLog', False),
- ('copy-after-failure', 'copyAfterFailure', False),
+ ("target", "filePath", None),
+ ("source", "sourceFile", ""),
+ ("keep-hierarchy", "keepHierarchy", False),
+ ("copy-console", "copyConsoleLog", False),
+ ("copy-after-failure", "copyAfterFailure", False),
]
- helpers.convert_mapping_to_xml(
- entry_e, entry, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(entry_e, entry, mappings, fail_required=True)
def ssh(registry, xml_parent, data):
@@ -2204,23 +2237,31 @@ def ssh(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/ssh-full.yaml
:language: yaml
"""
- console_prefix = 'SSH: '
- tag_prefix = 'jenkins.plugins.publish'
- publisher_tag = '%s__over__ssh.BapSshPublisher' % tag_prefix
- transfer_tag = '%s__over__ssh.BapSshTransfer' % tag_prefix
- retry_tag = '%s_over_ssh.BapSshRetry' % tag_prefix
- reference_tag = '%s_over_ssh.BapSshPublisherPlugin' % tag_prefix
-
- if xml_parent.tag == 'publishers':
- plugin_tag = '%s__over__ssh.BapSshPublisherPlugin' % tag_prefix
+ console_prefix = "SSH: "
+ tag_prefix = "jenkins.plugins.publish"
+ publisher_tag = "%s__over__ssh.BapSshPublisher" % tag_prefix
+ transfer_tag = "%s__over__ssh.BapSshTransfer" % tag_prefix
+ retry_tag = "%s_over_ssh.BapSshRetry" % tag_prefix
+ reference_tag = "%s_over_ssh.BapSshPublisherPlugin" % tag_prefix
+
+ if xml_parent.tag == "publishers":
+ plugin_tag = "%s__over__ssh.BapSshPublisherPlugin" % tag_prefix
is_builder = False
else:
- plugin_tag = '%s__over__ssh.BapSshBuilderPlugin' % tag_prefix
+ plugin_tag = "%s__over__ssh.BapSshBuilderPlugin" % tag_prefix
is_builder = True
- base_publish_over(xml_parent, data, console_prefix, plugin_tag,
- publisher_tag, transfer_tag, retry_tag, reference_tag,
- is_builder)
+ base_publish_over(
+ xml_parent,
+ data,
+ console_prefix,
+ plugin_tag,
+ publisher_tag,
+ transfer_tag,
+ retry_tag,
+ reference_tag,
+ is_builder,
+ )
def pipeline(registry, xml_parent, data):
@@ -2284,25 +2325,28 @@ def pipeline(registry, xml_parent, data):
See 'samples/pipeline.yaml' for an example pipeline implementation.
"""
logger = logging.getLogger("%s:pipeline" % __name__)
- param_order = helpers.trigger_get_parameter_order(registry, 'pipeline')
+ param_order = helpers.trigger_get_parameter_order(registry, "pipeline")
- if 'project' in data:
+ if "project" in data:
logger.warning(
"Using 'project' for pipeline definition is deprecated. Please "
- "update your job definition to use 'projects' with a list format.")
+ "update your job definition to use 'projects' with a list format."
+ )
- projects = ",".join(data.get('projects', [data.get('project', '')]))
- if projects != '':
+ projects = ",".join(data.get("projects", [data.get("project", "")]))
+ if projects != "":
- pippub = XML.SubElement(xml_parent,
- 'au.com.centrumsystems.hudson.plugin.'
- 'buildpipeline.trigger.BuildPipelineTrigger')
+ pippub = XML.SubElement(
+ xml_parent,
+ "au.com.centrumsystems.hudson.plugin."
+ "buildpipeline.trigger.BuildPipelineTrigger",
+ )
- configs = XML.SubElement(pippub, 'configs')
+ configs = XML.SubElement(pippub, "configs")
helpers.trigger_project(configs, data, param_order)
- XML.SubElement(pippub, 'downstreamProjectNames').text = projects
+ XML.SubElement(pippub, "downstreamProjectNames").text = projects
def email(registry, xml_parent, data):
@@ -2330,21 +2374,19 @@ def email(registry, xml_parent, data):
"""
# TODO: raise exception if this is applied to a maven job
- mailer = XML.SubElement(xml_parent,
- 'hudson.tasks.Mailer')
- mailer.set('plugin', 'mailer')
- mapping = [
- ('recipients', 'recipients', None)
- ]
+ mailer = XML.SubElement(xml_parent, "hudson.tasks.Mailer")
+ mailer.set("plugin", "mailer")
+ mapping = [("recipients", "recipients", None)]
helpers.convert_mapping_to_xml(mailer, data, mapping, fail_required=True)
# Note the logic reversal (included here to match the GUI
- if data.get('notify-every-unstable-build', True):
- XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false'
+ if data.get("notify-every-unstable-build", True):
+ XML.SubElement(mailer, "dontNotifyEveryUnstableBuild").text = "false"
else:
- XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true'
- XML.SubElement(mailer, 'sendToIndividuals').text = str(
- data.get('send-to-individuals', False)).lower()
+ XML.SubElement(mailer, "dontNotifyEveryUnstableBuild").text = "true"
+ XML.SubElement(mailer, "sendToIndividuals").text = str(
+ data.get("send-to-individuals", False)
+ ).lower()
def claim_build(registry, xml_parent, data):
@@ -2358,33 +2400,37 @@ def claim_build(registry, xml_parent, data):
:language: yaml
"""
- XML.SubElement(xml_parent, 'hudson.plugins.claim.ClaimPublisher')
+ XML.SubElement(xml_parent, "hudson.plugins.claim.ClaimPublisher")
def base_email_ext(registry, xml_parent, data, ttype):
- trigger = XML.SubElement(xml_parent,
- 'hudson.plugins.emailext.plugins.trigger.' +
- ttype)
- email = XML.SubElement(trigger, 'email')
- XML.SubElement(email, 'recipientList').text = ''
- XML.SubElement(email, 'subject').text = '$PROJECT_DEFAULT_SUBJECT'
- XML.SubElement(email, 'body').text = '$PROJECT_DEFAULT_CONTENT'
- if 'send-to' in data:
- XML.SubElement(email, 'sendToDevelopers').text = str(
- 'developers' in data['send-to']).lower()
- XML.SubElement(email, 'sendToRequester').text = str(
- 'requester' in data['send-to']).lower()
- XML.SubElement(email, 'includeCulprits').text = str(
- 'culprits' in data['send-to']).lower()
- XML.SubElement(email, 'sendToRecipientList').text = str(
- 'recipients' in data['send-to']).lower()
+ trigger = XML.SubElement(
+ xml_parent, "hudson.plugins.emailext.plugins.trigger." + ttype
+ )
+ email = XML.SubElement(trigger, "email")
+ XML.SubElement(email, "recipientList").text = ""
+ XML.SubElement(email, "subject").text = "$PROJECT_DEFAULT_SUBJECT"
+ XML.SubElement(email, "body").text = "$PROJECT_DEFAULT_CONTENT"
+ if "send-to" in data:
+ XML.SubElement(email, "sendToDevelopers").text = str(
+ "developers" in data["send-to"]
+ ).lower()
+ XML.SubElement(email, "sendToRequester").text = str(
+ "requester" in data["send-to"]
+ ).lower()
+ XML.SubElement(email, "includeCulprits").text = str(
+ "culprits" in data["send-to"]
+ ).lower()
+ XML.SubElement(email, "sendToRecipientList").text = str(
+ "recipients" in data["send-to"]
+ ).lower()
else:
- XML.SubElement(email, 'sendToRequester').text = 'false'
- XML.SubElement(email, 'sendToDevelopers').text = 'false'
- XML.SubElement(email, 'includeCulprits').text = 'false'
- XML.SubElement(email, 'sendToRecipientList').text = 'true'
- if ttype == 'ScriptTrigger':
- XML.SubElement(trigger, 'triggerScript').text = data['trigger-script']
+ XML.SubElement(email, "sendToRequester").text = "false"
+ XML.SubElement(email, "sendToDevelopers").text = "false"
+ XML.SubElement(email, "includeCulprits").text = "false"
+ XML.SubElement(email, "sendToRecipientList").text = "true"
+ if ttype == "ScriptTrigger":
+ XML.SubElement(trigger, "triggerScript").text = data["trigger-script"]
def email_ext(registry, xml_parent, data):
@@ -2468,87 +2514,89 @@ def email_ext(registry, xml_parent, data):
:language: yaml
"""
- emailext = XML.SubElement(xml_parent,
- 'hudson.plugins.emailext.ExtendedEmailPublisher')
- if 'recipients' in data:
- XML.SubElement(emailext, 'recipientList').text = data['recipients']
+ emailext = XML.SubElement(
+ xml_parent, "hudson.plugins.emailext.ExtendedEmailPublisher"
+ )
+ if "recipients" in data:
+ XML.SubElement(emailext, "recipientList").text = data["recipients"]
else:
- XML.SubElement(emailext, 'recipientList').text = '$DEFAULT_RECIPIENTS'
- ctrigger = XML.SubElement(emailext, 'configuredTriggers')
- if data.get('always', False):
- base_email_ext(registry, ctrigger, data, 'AlwaysTrigger')
- if data.get('unstable', False):
- base_email_ext(registry, ctrigger, data, 'UnstableTrigger')
- if data.get('first-failure', False):
- base_email_ext(registry, ctrigger, data, 'FirstFailureTrigger')
- if data.get('first-unstable', False):
- base_email_ext(registry, ctrigger, data, 'FirstUnstableTrigger')
- if data.get('not-built', False):
- base_email_ext(registry, ctrigger, data, 'NotBuiltTrigger')
- if data.get('aborted', False):
- base_email_ext(registry, ctrigger, data, 'AbortedTrigger')
- if data.get('regression', False):
- base_email_ext(registry, ctrigger, data, 'RegressionTrigger')
- if data.get('failure', True):
- base_email_ext(registry, ctrigger, data, 'FailureTrigger')
- if data.get('second-failure', False):
- base_email_ext(registry, ctrigger, data, 'SecondFailureTrigger')
- if data.get('improvement', False):
- base_email_ext(registry, ctrigger, data, 'ImprovementTrigger')
- if data.get('still-failing', False):
- base_email_ext(registry, ctrigger, data, 'StillFailingTrigger')
- if data.get('success', False):
- base_email_ext(registry, ctrigger, data, 'SuccessTrigger')
- if data.get('fixed', False):
- base_email_ext(registry, ctrigger, data, 'FixedTrigger')
- if data.get('fixed-unhealthy', False):
- base_email_ext(registry, ctrigger, data, 'FixedUnhealthyTrigger')
- if data.get('still-unstable', False):
- base_email_ext(registry, ctrigger, data, 'StillUnstableTrigger')
- if data.get('pre-build', False):
- base_email_ext(registry, ctrigger, data, 'PreBuildTrigger')
- if data.get('trigger-script', False):
- base_email_ext(registry, ctrigger, data, 'ScriptTrigger')
+ XML.SubElement(emailext, "recipientList").text = "$DEFAULT_RECIPIENTS"
+ ctrigger = XML.SubElement(emailext, "configuredTriggers")
+ if data.get("always", False):
+ base_email_ext(registry, ctrigger, data, "AlwaysTrigger")
+ if data.get("unstable", False):
+ base_email_ext(registry, ctrigger, data, "UnstableTrigger")
+ if data.get("first-failure", False):
+ base_email_ext(registry, ctrigger, data, "FirstFailureTrigger")
+ if data.get("first-unstable", False):
+ base_email_ext(registry, ctrigger, data, "FirstUnstableTrigger")
+ if data.get("not-built", False):
+ base_email_ext(registry, ctrigger, data, "NotBuiltTrigger")
+ if data.get("aborted", False):
+ base_email_ext(registry, ctrigger, data, "AbortedTrigger")
+ if data.get("regression", False):
+ base_email_ext(registry, ctrigger, data, "RegressionTrigger")
+ if data.get("failure", True):
+ base_email_ext(registry, ctrigger, data, "FailureTrigger")
+ if data.get("second-failure", False):
+ base_email_ext(registry, ctrigger, data, "SecondFailureTrigger")
+ if data.get("improvement", False):
+ base_email_ext(registry, ctrigger, data, "ImprovementTrigger")
+ if data.get("still-failing", False):
+ base_email_ext(registry, ctrigger, data, "StillFailingTrigger")
+ if data.get("success", False):
+ base_email_ext(registry, ctrigger, data, "SuccessTrigger")
+ if data.get("fixed", False):
+ base_email_ext(registry, ctrigger, data, "FixedTrigger")
+ if data.get("fixed-unhealthy", False):
+ base_email_ext(registry, ctrigger, data, "FixedUnhealthyTrigger")
+ if data.get("still-unstable", False):
+ base_email_ext(registry, ctrigger, data, "StillUnstableTrigger")
+ if data.get("pre-build", False):
+ base_email_ext(registry, ctrigger, data, "PreBuildTrigger")
+ if data.get("trigger-script", False):
+ base_email_ext(registry, ctrigger, data, "ScriptTrigger")
content_type_mime = {
- 'text': 'text/plain',
- 'html': 'text/html',
- 'default': 'default',
- 'both-html-text': 'both',
+ "text": "text/plain",
+ "html": "text/html",
+ "default": "default",
+ "both-html-text": "both",
}
- ctype = data.get('content-type', 'default')
+ ctype = data.get("content-type", "default")
if ctype not in content_type_mime:
raise InvalidAttributeError(ctype, ctype, content_type_mime.keys())
- XML.SubElement(emailext, 'contentType').text = content_type_mime[ctype]
+ XML.SubElement(emailext, "contentType").text = content_type_mime[ctype]
mappings = [
- ('subject', 'defaultSubject', '$DEFAULT_SUBJECT'),
- ('body', 'defaultContent', '$DEFAULT_CONTENT'),
- ('attachments', 'attachmentsPattern', ''),
- ('presend-script', 'presendScript', ''),
- ('postsend-script', 'postsendScript', ''),
- ('attach-build-log', 'attachBuildLog', False),
- ('compress-log', 'compressBuildLog', False),
- ('save-output', 'saveOutput', False),
- ('disable-publisher', 'disabled', False),
- ('reply-to', 'replyTo', '$DEFAULT_REPLYTO'),
+ ("subject", "defaultSubject", "$DEFAULT_SUBJECT"),
+ ("body", "defaultContent", "$DEFAULT_CONTENT"),
+ ("attachments", "attachmentsPattern", ""),
+ ("presend-script", "presendScript", ""),
+ ("postsend-script", "postsendScript", ""),
+ ("attach-build-log", "attachBuildLog", False),
+ ("compress-log", "compressBuildLog", False),
+ ("save-output", "saveOutput", False),
+ ("disable-publisher", "disabled", False),
+ ("reply-to", "replyTo", "$DEFAULT_REPLYTO"),
]
- helpers.convert_mapping_to_xml(
- emailext, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(emailext, data, mappings, fail_required=True)
matrix_dict = {
- 'both': 'BOTH',
- 'only-configurations': 'ONLY_CONFIGURATIONS',
- 'only-parent': 'ONLY_PARENT'
+ "both": "BOTH",
+ "only-configurations": "ONLY_CONFIGURATIONS",
+ "only-parent": "ONLY_PARENT",
}
- matrix_trigger = data.get('matrix-trigger', None)
+ matrix_trigger = data.get("matrix-trigger", None)
# If none defined, then do not create entry
if matrix_trigger is not None:
if matrix_trigger not in matrix_dict:
- raise InvalidAttributeError(matrix_trigger, matrix_trigger,
- matrix_dict.keys())
- XML.SubElement(emailext, 'matrixTriggerMode').text = matrix_dict.get(
- matrix_trigger)
+ raise InvalidAttributeError(
+ matrix_trigger, matrix_trigger, matrix_dict.keys()
+ )
+ XML.SubElement(emailext, "matrixTriggerMode").text = matrix_dict.get(
+ matrix_trigger
+ )
def fingerprint(registry, xml_parent, data):
@@ -2566,10 +2614,10 @@ def fingerprint(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/fingerprint001.yaml
:language: yaml
"""
- finger = XML.SubElement(xml_parent, 'hudson.tasks.Fingerprinter')
+ finger = XML.SubElement(xml_parent, "hudson.tasks.Fingerprinter")
mappings = [
- ('files', 'targets', ''),
- ('record-artifacts', 'recordBuildArtifacts', False)
+ ("files", "targets", ""),
+ ("record-artifacts", "recordBuildArtifacts", False),
]
helpers.convert_mapping_to_xml(finger, data, mappings, fail_required=True)
@@ -2587,9 +2635,8 @@ def aggregate_tests(registry, xml_parent, data):
/../../tests/publishers/fixtures/aggregate-tests001.yaml
:language: yaml
"""
- agg = XML.SubElement(xml_parent,
- 'hudson.tasks.test.AggregatedTestResultPublisher')
- mapping = [('include-failed-builds', 'includeFailedBuilds', False)]
+ agg = XML.SubElement(xml_parent, "hudson.tasks.test.AggregatedTestResultPublisher")
+ mapping = [("include-failed-builds", "includeFailedBuilds", False)]
helpers.convert_mapping_to_xml(agg, data, mapping, fail_required=True)
@@ -2609,9 +2656,11 @@ def aggregate_flow_tests(registry, xml_parent, data):
:language: yaml
"""
- agg_flow = XML.SubElement(xml_parent, 'org.zeroturnaround.jenkins.'
- 'flowbuildtestaggregator.FlowTestAggregator')
- mapping = [('show-test-results-trend', 'showTestResultTrend', True)]
+ agg_flow = XML.SubElement(
+ xml_parent,
+ "org.zeroturnaround.jenkins." "flowbuildtestaggregator.FlowTestAggregator",
+ )
+ mapping = [("show-test-results-trend", "showTestResultTrend", True)]
helpers.convert_mapping_to_xml(agg_flow, data, mapping, fail_required=True)
@@ -2682,68 +2731,64 @@ def cppcheck(registry, xml_parent, data):
:language: yaml
"""
- cppextbase = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.cppcheck.'
- 'CppcheckPublisher')
- cppextbase.set('plugin', 'cppcheck')
- cppext = XML.SubElement(cppextbase, 'cppcheckConfig')
+ cppextbase = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.cppcheck." "CppcheckPublisher"
+ )
+ cppextbase.set("plugin", "cppcheck")
+ cppext = XML.SubElement(cppextbase, "cppcheckConfig")
mappings = [
- ('pattern', 'pattern', None),
- ('ignoreblankfiles', 'ignoreBlankFiles', False),
- ('allow-no-report', 'allowNoReport', False)
+ ("pattern", "pattern", None),
+ ("ignoreblankfiles", "ignoreBlankFiles", False),
+ ("allow-no-report", "allowNoReport", False),
]
helpers.convert_mapping_to_xml(cppext, data, mappings, fail_required=True)
- csev = XML.SubElement(cppext, 'configSeverityEvaluation')
- thrsh = data.get('thresholds', {})
+ csev = XML.SubElement(cppext, "configSeverityEvaluation")
+ thrsh = data.get("thresholds", {})
thrsh_mappings = [
- ('unstable', 'threshold', ''),
- ('new-unstable', 'newThreshold', ''),
- ('failure', 'failureThreshold', ''),
- ('new-failure', 'newFailureThreshold', ''),
- ('healthy', 'healthy', ''),
- ('unhealthy', 'unHealthy', '')
+ ("unstable", "threshold", ""),
+ ("new-unstable", "newThreshold", ""),
+ ("failure", "failureThreshold", ""),
+ ("new-failure", "newFailureThreshold", ""),
+ ("healthy", "healthy", ""),
+ ("unhealthy", "unHealthy", ""),
]
- helpers.convert_mapping_to_xml(
- csev, thrsh, thrsh_mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(csev, thrsh, thrsh_mappings, fail_required=True)
- sev = thrsh.get('severity', {})
+ sev = thrsh.get("severity", {})
sev_mappings = [
- ('error', 'severityError', True),
- ('warning', 'severityWarning', True),
- ('style', 'severityStyle', True),
- ('performance', 'severityPerformance', True),
- ('information', 'severityInformation', True),
- ('nocategory', 'severityNoCategory', True),
- ('portability', 'severityPortability', True)
- ]
- helpers.convert_mapping_to_xml(
- csev, sev, sev_mappings, fail_required=True)
-
- graph = data.get('graph', {})
- cgraph = XML.SubElement(cppext, 'configGraph')
- x, y = graph.get('xysize', [500, 200])
- XML.SubElement(cgraph, 'xSize').text = str(x)
- XML.SubElement(cgraph, 'ySize').text = str(y)
- graph_mapping = [
- ('num-builds-in-graph', 'numBuildsInGraph', 0)
+ ("error", "severityError", True),
+ ("warning", "severityWarning", True),
+ ("style", "severityStyle", True),
+ ("performance", "severityPerformance", True),
+ ("information", "severityInformation", True),
+ ("nocategory", "severityNoCategory", True),
+ ("portability", "severityPortability", True),
]
- helpers.convert_mapping_to_xml(
- cgraph, graph, graph_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(csev, sev, sev_mappings, fail_required=True)
+
+ graph = data.get("graph", {})
+ cgraph = XML.SubElement(cppext, "configGraph")
+ x, y = graph.get("xysize", [500, 200])
+ XML.SubElement(cgraph, "xSize").text = str(x)
+ XML.SubElement(cgraph, "ySize").text = str(y)
+ graph_mapping = [("num-builds-in-graph", "numBuildsInGraph", 0)]
+ helpers.convert_mapping_to_xml(cgraph, graph, graph_mapping, fail_required=True)
- gdisplay = graph.get('display', {})
+ gdisplay = graph.get("display", {})
gdisplay_mappings = [
- ('sum', 'displayAllErrors', True),
- ('error', 'displayErrorSeverity', False),
- ('warning', 'displayWarningSeverity', False),
- ('style', 'displayStyleSeverity', False),
- ('performance', 'displayPerformanceSeverity', False),
- ('information', 'displayInformationSeverity', False),
- ('nocategory', 'displayNoCategorySeverity', False),
- ('portability', 'displayPortabilitySeverity', False)
+ ("sum", "displayAllErrors", True),
+ ("error", "displayErrorSeverity", False),
+ ("warning", "displayWarningSeverity", False),
+ ("style", "displayStyleSeverity", False),
+ ("performance", "displayPerformanceSeverity", False),
+ ("information", "displayInformationSeverity", False),
+ ("nocategory", "displayNoCategorySeverity", False),
+ ("portability", "displayPortabilitySeverity", False),
]
helpers.convert_mapping_to_xml(
- cgraph, gdisplay, gdisplay_mappings, fail_required=True)
+ cgraph, gdisplay, gdisplay_mappings, fail_required=True
+ )
def logparser(registry, xml_parent, data):
@@ -2771,18 +2816,17 @@ def logparser(registry, xml_parent, data):
:language: yaml
"""
- clog = XML.SubElement(xml_parent,
- 'hudson.plugins.logparser.LogParserPublisher')
- clog.set('plugin', 'log-parser')
- rules_path_element = ("projectRulePath"
- if data.get("use-project-rules", True)
- else "parsingRulesPath")
+ clog = XML.SubElement(xml_parent, "hudson.plugins.logparser.LogParserPublisher")
+ clog.set("plugin", "log-parser")
+ rules_path_element = (
+ "projectRulePath" if data.get("use-project-rules", True) else "parsingRulesPath"
+ )
mappings = [
- ('unstable-on-warning', 'unstableOnWarning', False),
- ('fail-on-error', 'failBuildOnError', False),
- ('show-graphs', 'showGraphs', True),
- ('use-project-rules', 'useProjectRule', True),
- ('parse-rules', rules_path_element, ''),
+ ("unstable-on-warning", "unstableOnWarning", False),
+ ("fail-on-error", "failBuildOnError", False),
+ ("show-graphs", "showGraphs", True),
+ ("use-project-rules", "useProjectRule", True),
+ ("parse-rules", rules_path_element, ""),
]
helpers.convert_mapping_to_xml(clog, data, mappings, fail_required=True)
@@ -2807,20 +2851,22 @@ def copy_to_master(registry, xml_parent, data):
/../../tests/publishers/fixtures/copy-to-master001.yaml
:language: yaml
"""
- cm = XML.SubElement(xml_parent, 'com.michelin.'
- 'cio.hudson.plugins.copytoslave.CopyToMasterNotifier')
- cm.set('plugin', 'copy-to-slave')
+ cm = XML.SubElement(
+ xml_parent,
+ "com.michelin." "cio.hudson.plugins.copytoslave.CopyToMasterNotifier",
+ )
+ cm.set("plugin", "copy-to-slave")
- XML.SubElement(cm, 'includes').text = ','.join(data.get('includes', ['']))
- XML.SubElement(cm, 'excludes').text = ','.join(data.get('excludes', ['']))
+ XML.SubElement(cm, "includes").text = ",".join(data.get("includes", [""]))
+ XML.SubElement(cm, "excludes").text = ",".join(data.get("excludes", [""]))
mappings = [
- ('run-after-result', 'runAfterResultFinalised', True),
- ('destination', 'destinationFolder', '')
+ ("run-after-result", "runAfterResultFinalised", True),
+ ("destination", "destinationFolder", ""),
]
helpers.convert_mapping_to_xml(cm, data, mappings, fail_required=True)
- if data.get('destination', ''):
- XML.SubElement(cm, 'overrideDestinationFolder').text = 'true'
+ if data.get("destination", ""):
+ XML.SubElement(cm, "overrideDestinationFolder").text = "true"
def jira(registry, xml_parent, data):
@@ -2833,7 +2879,7 @@ def jira(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/jira001.yaml
:language: yaml
"""
- XML.SubElement(xml_parent, 'hudson.plugins.jira.JiraIssueUpdater')
+ XML.SubElement(xml_parent, "hudson.plugins.jira.JiraIssueUpdater")
def growl(registry, xml_parent, data):
@@ -2855,12 +2901,12 @@ def growl(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/growl-full.yaml
:language: yaml
"""
- growl = XML.SubElement(xml_parent, 'hudson.plugins.growl.GrowlPublisher')
- growl.set('plugin', 'growl')
+ growl = XML.SubElement(xml_parent, "hudson.plugins.growl.GrowlPublisher")
+ growl.set("plugin", "growl")
mapping = [
- ('ip', 'IP', None),
- ('notify-only-on-fail-or-recovery', 'onlyOnFailureOrRecovery', False),
+ ("ip", "IP", None),
+ ("notify-only-on-fail-or-recovery", "onlyOnFailureOrRecovery", False),
]
helpers.convert_mapping_to_xml(growl, data, mapping, fail_required=True)
@@ -2901,118 +2947,121 @@ def groovy_postbuild(registry, xml_parent, data):
"to change configuration. It is not going to be supported in "
"future releases!"
)
- data = {
- 'script': data,
- }
+ data = {"script": data}
# There are incompatible changes, we need to know version
- info = registry.get_plugin_info('groovy-postbuild')
+ info = registry.get_plugin_info("groovy-postbuild")
# Note: Assume latest version of plugin is preferred config format
- version = pkg_resources.parse_version(
- info.get('version', str(sys.maxsize)))
+ version = pkg_resources.parse_version(info.get("version", str(sys.maxsize)))
# Version specific predicates
matrix_parent_support = version >= pkg_resources.parse_version("1.9")
security_plugin_support = version >= pkg_resources.parse_version("2.0")
extra_classpath_support = version >= pkg_resources.parse_version("1.6")
- root_tag = (
- 'org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder'
- )
+ root_tag = "org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder"
groovy = XML.SubElement(xml_parent, root_tag)
- behavior = data.get('on-failure')
- XML.SubElement(groovy, 'behavior').text = {
- 'unstable': '1',
- 'failed': '2',
- }.get(behavior, '0')
+ behavior = data.get("on-failure")
+ XML.SubElement(groovy, "behavior").text = {"unstable": "1", "failed": "2"}.get(
+ behavior, "0"
+ )
if matrix_parent_support:
- XML.SubElement(
- groovy,
- 'runForMatrixParent',
- ).text = str(data.get('matrix-parent', False)).lower()
+ XML.SubElement(groovy, "runForMatrixParent").text = str(
+ data.get("matrix-parent", False)
+ ).lower()
- classpaths = data.get('classpath', list())
+ classpaths = data.get("classpath", list())
if security_plugin_support:
- script = XML.SubElement(groovy, 'script')
- XML.SubElement(script, 'script').text = data.get('script')
- XML.SubElement(script, 'sandbox').text = str(
- data.get('sandbox', False)
- ).lower()
+ script = XML.SubElement(groovy, "script")
+ XML.SubElement(script, "script").text = data.get("script")
+ XML.SubElement(script, "sandbox").text = str(data.get("sandbox", False)).lower()
if classpaths:
- classpath = XML.SubElement(script, 'classpath')
+ classpath = XML.SubElement(script, "classpath")
for path in classpaths:
- script_path = XML.SubElement(classpath, 'entry')
- XML.SubElement(script_path, 'url').text = path
+ script_path = XML.SubElement(classpath, "entry")
+ XML.SubElement(script_path, "url").text = path
else:
- XML.SubElement(groovy, 'groovyScript').text = data.get('script')
+ XML.SubElement(groovy, "groovyScript").text = data.get("script")
if extra_classpath_support and classpaths:
- classpath = XML.SubElement(groovy, 'classpath')
+ classpath = XML.SubElement(groovy, "classpath")
for path in classpaths:
script_path = XML.SubElement(
classpath,
- 'org.jvnet.hudson.plugins.groovypostbuild.'
- 'GroovyScriptPath',
+ "org.jvnet.hudson.plugins.groovypostbuild." "GroovyScriptPath",
)
- XML.SubElement(script_path, 'path').text = path
-
-
-def base_publish_over(xml_parent, data, console_prefix,
- plugin_tag, publisher_tag,
- transferset_tag, retry_tag,
- reference_plugin_tag, is_builder=False):
+ XML.SubElement(script_path, "path").text = path
+
+
+def base_publish_over(
+ xml_parent,
+ data,
+ console_prefix,
+ plugin_tag,
+ publisher_tag,
+ transferset_tag,
+ retry_tag,
+ reference_plugin_tag,
+ is_builder=False,
+):
outer = XML.SubElement(xml_parent, plugin_tag)
# 'Publish over SSH' builder has an extra top delegate element
- if xml_parent.tag == 'builders' or is_builder:
- outer = XML.SubElement(outer, 'delegate')
+ if xml_parent.tag == "builders" or is_builder:
+ outer = XML.SubElement(outer, "delegate")
- XML.SubElement(outer, 'consolePrefix').text = console_prefix
- delegate = XML.SubElement(outer, 'delegate')
- publishers = XML.SubElement(delegate, 'publishers')
+ XML.SubElement(outer, "consolePrefix").text = console_prefix
+ delegate = XML.SubElement(outer, "delegate")
+ publishers = XML.SubElement(delegate, "publishers")
inner = XML.SubElement(publishers, publisher_tag)
- XML.SubElement(inner, 'configName').text = data['site']
- XML.SubElement(inner, 'verbose').text = str(
- data.get('verbose', False)).lower()
+ XML.SubElement(inner, "configName").text = data["site"]
+ XML.SubElement(inner, "verbose").text = str(data.get("verbose", False)).lower()
- transfers = XML.SubElement(inner, 'transfers')
+ transfers = XML.SubElement(inner, "transfers")
transfersset = XML.SubElement(transfers, transferset_tag)
- XML.SubElement(transfersset, 'remoteDirectory').text = data['target']
- XML.SubElement(transfersset, 'sourceFiles').text = data['source']
- XML.SubElement(transfersset, 'excludes').text = data.get('excludes', '')
- XML.SubElement(transfersset, 'removePrefix').text = data.get(
- 'remove-prefix', '')
- XML.SubElement(transfersset, 'remoteDirectorySDF').text = str(
- data.get('target-is-date-format', False)).lower()
- XML.SubElement(transfersset, 'flatten').text = str(
- data.get('flatten', False)).lower()
- XML.SubElement(transfersset, 'cleanRemote').text = str(
- data.get('clean-remote', False)).lower()
-
- if 'command' in data:
- XML.SubElement(transfersset, 'execCommand').text = data['command']
- if 'timeout' in data:
- XML.SubElement(transfersset, 'execTimeout').text = str(data['timeout'])
- if 'use-pty' in data:
- XML.SubElement(transfersset, 'usePty').text = str(
- data.get('use-pty', False)).lower()
-
- XML.SubElement(inner, 'useWorkspaceInPromotion').text = 'false'
- XML.SubElement(inner, 'usePromotionTimestamp').text = 'false'
-
- if 'retries' in data:
- retry = XML.SubElement(inner, 'retry', {'class': retry_tag})
- XML.SubElement(retry, 'retries').text = str(data.get('retries', 0))
- XML.SubElement(retry, 'retryDelay').text = str(
- data.get('retry-delay', 10000))
-
- XML.SubElement(delegate, 'continueOnError').text = 'false'
- XML.SubElement(delegate, 'failOnError').text = str(
- data.get('fail-on-error', False)).lower()
- XML.SubElement(delegate, 'alwaysPublishFromMaster').text = str(
- data.get('always-publish-from-master', False)).lower()
- XML.SubElement(delegate, 'hostConfigurationAccess',
- {'class': reference_plugin_tag, 'reference': '../..'})
+ XML.SubElement(transfersset, "remoteDirectory").text = data["target"]
+ XML.SubElement(transfersset, "sourceFiles").text = data["source"]
+ XML.SubElement(transfersset, "excludes").text = data.get("excludes", "")
+ XML.SubElement(transfersset, "removePrefix").text = data.get("remove-prefix", "")
+ XML.SubElement(transfersset, "remoteDirectorySDF").text = str(
+ data.get("target-is-date-format", False)
+ ).lower()
+ XML.SubElement(transfersset, "flatten").text = str(
+ data.get("flatten", False)
+ ).lower()
+ XML.SubElement(transfersset, "cleanRemote").text = str(
+ data.get("clean-remote", False)
+ ).lower()
+
+ if "command" in data:
+ XML.SubElement(transfersset, "execCommand").text = data["command"]
+ if "timeout" in data:
+ XML.SubElement(transfersset, "execTimeout").text = str(data["timeout"])
+ if "use-pty" in data:
+ XML.SubElement(transfersset, "usePty").text = str(
+ data.get("use-pty", False)
+ ).lower()
+
+ XML.SubElement(inner, "useWorkspaceInPromotion").text = "false"
+ XML.SubElement(inner, "usePromotionTimestamp").text = "false"
+
+ if "retries" in data:
+ retry = XML.SubElement(inner, "retry", {"class": retry_tag})
+ XML.SubElement(retry, "retries").text = str(data.get("retries", 0))
+ XML.SubElement(retry, "retryDelay").text = str(data.get("retry-delay", 10000))
+
+ XML.SubElement(delegate, "continueOnError").text = "false"
+ XML.SubElement(delegate, "failOnError").text = str(
+ data.get("fail-on-error", False)
+ ).lower()
+ XML.SubElement(delegate, "alwaysPublishFromMaster").text = str(
+ data.get("always-publish-from-master", False)
+ ).lower()
+ XML.SubElement(
+ delegate,
+ "hostConfigurationAccess",
+ {"class": reference_plugin_tag, "reference": "../.."},
+ )
return (outer, transfersset)
@@ -3054,27 +3103,28 @@ def cifs(registry, xml_parent, data):
:language: yaml
"""
- console_prefix = 'CIFS: '
- if xml_parent.tag == 'publishers':
- plugin_tag = 'jenkins.plugins.publish__over__cifs.CifsPublisherPlugin'
+ console_prefix = "CIFS: "
+ if xml_parent.tag == "publishers":
+ plugin_tag = "jenkins.plugins.publish__over__cifs.CifsPublisherPlugin"
is_builder = False
else:
- plugin_tag = 'jenkins.plugins.publish__over__cifs.CifsBuilderPlugin'
+ plugin_tag = "jenkins.plugins.publish__over__cifs.CifsBuilderPlugin"
is_builder = True
- publisher_tag = 'jenkins.plugins.publish__over__cifs.CifsPublisher'
- transfer_tag = 'jenkins.plugins.publish__over__cifs.CifsTransfer'
- retry_tag = 'jenkins.plugins.publish_over_cifs.CifsRetry'
- plugin_reference_tag = ('jenkins.plugins.publish_over_cifs.'
- 'CifsPublisherPlugin')
- base_publish_over(xml_parent,
- data,
- console_prefix,
- plugin_tag,
- publisher_tag,
- transfer_tag,
- retry_tag,
- plugin_reference_tag,
- is_builder)
+ publisher_tag = "jenkins.plugins.publish__over__cifs.CifsPublisher"
+ transfer_tag = "jenkins.plugins.publish__over__cifs.CifsTransfer"
+ retry_tag = "jenkins.plugins.publish_over_cifs.CifsRetry"
+ plugin_reference_tag = "jenkins.plugins.publish_over_cifs." "CifsPublisherPlugin"
+ base_publish_over(
+ xml_parent,
+ data,
+ console_prefix,
+ plugin_tag,
+ publisher_tag,
+ transfer_tag,
+ retry_tag,
+ plugin_reference_tag,
+ is_builder,
+ )
def cigame(registry, xml_parent, data):
@@ -3089,7 +3139,7 @@ def cigame(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/cigame.yaml
:language: yaml
"""
- XML.SubElement(xml_parent, 'hudson.plugins.cigame.GamePublisher')
+ XML.SubElement(xml_parent, "hudson.plugins.cigame.GamePublisher")
def sonar(registry, xml_parent, data):
@@ -3143,37 +3193,38 @@ def sonar(registry, xml_parent, data):
:language: yaml
"""
- sonar = XML.SubElement(xml_parent, 'hudson.plugins.sonar.SonarPublisher')
- sonar.set('plugin', 'sonar')
- if 'installation-name' in data:
- XML.SubElement(sonar, 'installationName').text = data[
- 'installation-name']
- if 'jdk' in data:
- XML.SubElement(sonar, 'jdk').text = data['jdk']
- if 'maven-installation-name' in data:
- XML.SubElement(sonar, 'mavenInstallationName').text = data[
- 'maven-installation-name']
+ sonar = XML.SubElement(xml_parent, "hudson.plugins.sonar.SonarPublisher")
+ sonar.set("plugin", "sonar")
+ if "installation-name" in data:
+ XML.SubElement(sonar, "installationName").text = data["installation-name"]
+ if "jdk" in data:
+ XML.SubElement(sonar, "jdk").text = data["jdk"]
+ if "maven-installation-name" in data:
+ XML.SubElement(sonar, "mavenInstallationName").text = data[
+ "maven-installation-name"
+ ]
mappings = [
- ('branch', 'branch', ''),
- ('language', 'language', ''),
- ('root-pom', 'rootPom', 'pom.xml'),
- ('private-maven-repo', 'usePrivateRepository', False),
- ('maven-opts', 'mavenOpts', ''),
- ('additional-properties', 'jobAdditionalProperties', '')
+ ("branch", "branch", ""),
+ ("language", "language", ""),
+ ("root-pom", "rootPom", "pom.xml"),
+ ("private-maven-repo", "usePrivateRepository", False),
+ ("maven-opts", "mavenOpts", ""),
+ ("additional-properties", "jobAdditionalProperties", ""),
]
helpers.convert_mapping_to_xml(sonar, data, mappings, fail_required=True)
- if 'skip-global-triggers' in data:
- data_triggers = data['skip-global-triggers']
- triggers = XML.SubElement(sonar, 'triggers')
+ if "skip-global-triggers" in data:
+ data_triggers = data["skip-global-triggers"]
+ triggers = XML.SubElement(sonar, "triggers")
triggers_mappings = [
- ('skip-when-scm-change', 'skipScmCause', False),
- ('skip-when-upstream-build', 'skipUpstreamCause', False),
- ('skip-when-envvar-defined', 'envVar', '')
+ ("skip-when-scm-change", "skipScmCause", False),
+ ("skip-when-upstream-build", "skipUpstreamCause", False),
+ ("skip-when-envvar-defined", "envVar", ""),
]
helpers.convert_mapping_to_xml(
- triggers, data_triggers, triggers_mappings, fail_required=True)
+ triggers, data_triggers, triggers_mappings, fail_required=True
+ )
helpers.config_file_provider_settings(sonar, data)
@@ -3221,43 +3272,46 @@ def sounds(parser, xml_parent, data):
:language: yaml
"""
- mapping_dict = {'success': hudson_model.SUCCESS,
- 'unstable': hudson_model.UNSTABLE,
- 'failure': hudson_model.FAILURE,
- 'not_build': hudson_model.NOTBUILD,
- 'aborted': hudson_model.ABORTED}
- sounds = XML.SubElement(xml_parent, 'net.hurstfrost.hudson.'
- 'sounds.HudsonSoundsNotifier')
- events = XML.SubElement(sounds, 'soundEvents')
+ mapping_dict = {
+ "success": hudson_model.SUCCESS,
+ "unstable": hudson_model.UNSTABLE,
+ "failure": hudson_model.FAILURE,
+ "not_build": hudson_model.NOTBUILD,
+ "aborted": hudson_model.ABORTED,
+ }
+ sounds = XML.SubElement(
+ xml_parent, "net.hurstfrost.hudson." "sounds.HudsonSoundsNotifier"
+ )
+ events = XML.SubElement(sounds, "soundEvents")
for status, v in data.items():
try:
model = mapping_dict[status]
except KeyError:
- raise InvalidAttributeError('build status', status, mapping_dict)
-
- event = XML.SubElement(events,
- 'net.hurstfrost.hudson.sounds.'
- 'HudsonSoundsNotifier_-SoundEvent')
- XML.SubElement(event, 'soundId').text = v['sound']
- to_result = XML.SubElement(event, 'toResult')
- XML.SubElement(to_result, 'name').text = model['name']
- XML.SubElement(to_result, 'ordinal').text = model['ordinal']
- XML.SubElement(to_result, 'color').text = model['color']
- XML.SubElement(to_result, 'completeBuild').text = str(
- model['complete']).lower()
-
- from_results = XML.SubElement(event, 'fromResults')
- results = ['not_build', 'success', 'aborted', 'failure', 'unstable']
- if 'from' in v:
- results = v['from']
+ raise InvalidAttributeError("build status", status, mapping_dict)
+
+ event = XML.SubElement(
+ events, "net.hurstfrost.hudson.sounds." "HudsonSoundsNotifier_-SoundEvent"
+ )
+ XML.SubElement(event, "soundId").text = v["sound"]
+ to_result = XML.SubElement(event, "toResult")
+ XML.SubElement(to_result, "name").text = model["name"]
+ XML.SubElement(to_result, "ordinal").text = model["ordinal"]
+ XML.SubElement(to_result, "color").text = model["color"]
+ XML.SubElement(to_result, "completeBuild").text = str(model["complete"]).lower()
+
+ from_results = XML.SubElement(event, "fromResults")
+ results = ["not_build", "success", "aborted", "failure", "unstable"]
+ if "from" in v:
+ results = v["from"]
for result in results:
model = mapping_dict[result]
- from_result = XML.SubElement(from_results, 'hudson.model.Result')
- XML.SubElement(from_result, 'name').text = model['name']
- XML.SubElement(from_result, 'ordinal').text = model['ordinal']
- XML.SubElement(from_result, 'color').text = model['color']
- XML.SubElement(from_result, 'completeBuild').text = str(
- model['complete']).lower()
+ from_result = XML.SubElement(from_results, "hudson.model.Result")
+ XML.SubElement(from_result, "name").text = model["name"]
+ XML.SubElement(from_result, "ordinal").text = model["ordinal"]
+ XML.SubElement(from_result, "color").text = model["color"]
+ XML.SubElement(from_result, "completeBuild").text = str(
+ model["complete"]
+ ).lower()
def performance(registry, xml_parent, data):
@@ -3318,76 +3372,71 @@ def performance(registry, xml_parent, data):
/../../tests/publishers/fixtures/performance-full.yaml
:language: yaml
"""
- perf = XML.SubElement(xml_parent, 'hudson.plugins.performance.'
- 'PerformancePublisher')
- perf.set('plugin', 'performance')
- types = ['ART', 'MRT', 'PRT']
+ perf = XML.SubElement(
+ xml_parent, "hudson.plugins.performance." "PerformancePublisher"
+ )
+ perf.set("plugin", "performance")
+ types = ["ART", "MRT", "PRT"]
mappings = [
- ('failed-threshold', 'errorFailedThreshold', 0),
- ('unstable-threshold', 'errorUnstableThreshold', 0),
- ('unstable-response-time-threshold',
- 'errorUnstableResponseTimeThreshold',
- ''),
- ('failed-threshold-positive',
- 'relativeFailedThresholdPositive',
- '0.0'),
- ('failed-threshold-negative',
- 'relativeFailedThresholdNegative',
- '0.0'),
- ('unstable-threshold-positive',
- 'relativeUnstableThresholdPositive',
- '0.0'),
- ('unstable-threshold-negative',
- 'relativeUnstableThresholdNegative',
- '0.0'),
- ('nth-build-number', 'nthBuildNumber', 0),
- ('mode-relative-thresholds', 'modeRelativeThresholds', False),
- ('config-type', 'configType', 'ART', types),
- ('mode-of-threshold', 'modeOfThreshold', False),
- ('fail-build', 'failBuildIfNoResultFile', False),
- ('compare-build-previous', 'compareBuildPrevious', False),
- ('mode-performance-per-test-case', 'modePerformancePerTestCase', True),
- ('mode-thoughput', 'modeThroughput', False)
+ ("failed-threshold", "errorFailedThreshold", 0),
+ ("unstable-threshold", "errorUnstableThreshold", 0),
+ ("unstable-response-time-threshold", "errorUnstableResponseTimeThreshold", ""),
+ ("failed-threshold-positive", "relativeFailedThresholdPositive", "0.0"),
+ ("failed-threshold-negative", "relativeFailedThresholdNegative", "0.0"),
+ ("unstable-threshold-positive", "relativeUnstableThresholdPositive", "0.0"),
+ ("unstable-threshold-negative", "relativeUnstableThresholdNegative", "0.0"),
+ ("nth-build-number", "nthBuildNumber", 0),
+ ("mode-relative-thresholds", "modeRelativeThresholds", False),
+ ("config-type", "configType", "ART", types),
+ ("mode-of-threshold", "modeOfThreshold", False),
+ ("fail-build", "failBuildIfNoResultFile", False),
+ ("compare-build-previous", "compareBuildPrevious", False),
+ ("mode-performance-per-test-case", "modePerformancePerTestCase", True),
+ ("mode-thoughput", "modeThroughput", False),
]
helpers.convert_mapping_to_xml(perf, data, mappings, fail_required=True)
- parsers = XML.SubElement(perf, 'parsers')
- if 'report' in data:
- for item in data['report']:
+ parsers = XML.SubElement(perf, "parsers")
+ if "report" in data:
+ for item in data["report"]:
if isinstance(item, dict):
item_name = next(iter(item.keys()))
item_values = item.get(item_name, None)
- if item_name == 'jmeter':
- jmhold = XML.SubElement(parsers, 'hudson.plugins.'
- 'performance.'
- 'JMeterParser')
- XML.SubElement(jmhold, 'glob').text = str(item_values)
- elif item_name == 'junit':
- juhold = XML.SubElement(parsers, 'hudson.plugins.'
- 'performance.'
- 'JUnitParser')
- XML.SubElement(juhold, 'glob').text = str(item_values)
+ if item_name == "jmeter":
+ jmhold = XML.SubElement(
+ parsers, "hudson.plugins." "performance." "JMeterParser"
+ )
+ XML.SubElement(jmhold, "glob").text = str(item_values)
+ elif item_name == "junit":
+ juhold = XML.SubElement(
+ parsers, "hudson.plugins." "performance." "JUnitParser"
+ )
+ XML.SubElement(juhold, "glob").text = str(item_values)
else:
- raise JenkinsJobsException("You have not specified jmeter "
- "or junit, or you have "
- "incorrectly assigned the key "
- "value.")
+ raise JenkinsJobsException(
+ "You have not specified jmeter "
+ "or junit, or you have "
+ "incorrectly assigned the key "
+ "value."
+ )
elif isinstance(item, str):
- if item == 'jmeter':
- jmhold = XML.SubElement(parsers, 'hudson.plugins.'
- 'performance.'
- 'JMeterParser')
- XML.SubElement(jmhold, 'glob').text = '**/*.jtl'
- elif item == 'junit':
- juhold = XML.SubElement(parsers, 'hudson.plugins.'
- 'performance.'
- 'JUnitParser')
- XML.SubElement(juhold, 'glob').text = '**/TEST-*.xml'
+ if item == "jmeter":
+ jmhold = XML.SubElement(
+ parsers, "hudson.plugins." "performance." "JMeterParser"
+ )
+ XML.SubElement(jmhold, "glob").text = "**/*.jtl"
+ elif item == "junit":
+ juhold = XML.SubElement(
+ parsers, "hudson.plugins." "performance." "JUnitParser"
+ )
+ XML.SubElement(juhold, "glob").text = "**/TEST-*.xml"
else:
- raise JenkinsJobsException("You have not specified jmeter "
- "or junit, or you have "
- "incorrectly assigned the key "
- "value.")
+ raise JenkinsJobsException(
+ "You have not specified jmeter "
+ "or junit, or you have "
+ "incorrectly assigned the key "
+ "value."
+ )
def join_trigger(registry, xml_parent, data):
@@ -3407,18 +3456,18 @@ def join_trigger(registry, xml_parent, data):
/../../tests/publishers/fixtures/join-trigger001.yaml
:language: yaml
"""
- jointrigger = XML.SubElement(xml_parent, 'join.JoinTrigger')
+ jointrigger = XML.SubElement(xml_parent, "join.JoinTrigger")
- joinProjectsText = ','.join(data.get('projects', ['']))
- XML.SubElement(jointrigger, 'joinProjects').text = joinProjectsText
+ joinProjectsText = ",".join(data.get("projects", [""]))
+ XML.SubElement(jointrigger, "joinProjects").text = joinProjectsText
- publishers = XML.SubElement(jointrigger, 'joinPublishers')
- for pub in data.get('publishers', []):
+ publishers = XML.SubElement(jointrigger, "joinPublishers")
+ for pub in data.get("publishers", []):
for edited_node in create_publishers(registry, pub):
publishers.append(edited_node)
- unstable = str(data.get('even-if-unstable', 'false')).lower()
- XML.SubElement(jointrigger, 'evenIfDownstreamUnstable').text = unstable
+ unstable = str(data.get("even-if-unstable", "false")).lower()
+ XML.SubElement(jointrigger, "evenIfDownstreamUnstable").text = unstable
def jabber(registry, xml_parent, data):
@@ -3467,57 +3516,67 @@ def jabber(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/jabber-full.yaml
:language: yaml
"""
- j = XML.SubElement(xml_parent, 'hudson.plugins.jabber.im.transport.'
- 'JabberPublisher')
- j.set('plugin', 'jabber')
-
- t = XML.SubElement(j, 'targets')
- if 'group-targets' in data:
- for group in data['group-targets']:
- gcimt = XML.SubElement(t, 'hudson.plugins.im.'
- 'GroupChatIMMessageTarget')
- gcimt.set('plugin', 'instant-messaging')
- XML.SubElement(gcimt, 'name').text = group
- XML.SubElement(gcimt, 'notificationOnly').text = 'false'
- if 'individual-targets' in data:
- for individual in data['individual-targets']:
- dimt = XML.SubElement(t, 'hudson.plugins.im.'
- 'DefaultIMMessageTarget')
- dimt.set('plugin', 'instant-messaging')
- XML.SubElement(dimt, 'value').text = individual
- strategy = data.get('strategy', 'all')
- strategydict = {'all': 'ALL',
- 'failure': 'ANY_FAILURE',
- 'failure-fixed': 'FAILURE_AND_FIXED',
- 'new-failure-fixed': 'NEW_FAILURE_AND_FIXED',
- 'change': 'STATECHANGE_ONLY'}
+ j = XML.SubElement(
+ xml_parent, "hudson.plugins.jabber.im.transport." "JabberPublisher"
+ )
+ j.set("plugin", "jabber")
+
+ t = XML.SubElement(j, "targets")
+ if "group-targets" in data:
+ for group in data["group-targets"]:
+ gcimt = XML.SubElement(t, "hudson.plugins.im." "GroupChatIMMessageTarget")
+ gcimt.set("plugin", "instant-messaging")
+ XML.SubElement(gcimt, "name").text = group
+ XML.SubElement(gcimt, "notificationOnly").text = "false"
+ if "individual-targets" in data:
+ for individual in data["individual-targets"]:
+ dimt = XML.SubElement(t, "hudson.plugins.im." "DefaultIMMessageTarget")
+ dimt.set("plugin", "instant-messaging")
+ XML.SubElement(dimt, "value").text = individual
+ strategy = data.get("strategy", "all")
+ strategydict = {
+ "all": "ALL",
+ "failure": "ANY_FAILURE",
+ "failure-fixed": "FAILURE_AND_FIXED",
+ "new-failure-fixed": "NEW_FAILURE_AND_FIXED",
+ "change": "STATECHANGE_ONLY",
+ }
if strategy not in strategydict:
- raise JenkinsJobsException("Strategy entered is not valid, must be " +
- "one of: all, failure, failure-fixed, or "
- "change")
- XML.SubElement(j, 'strategy').text = strategydict[strategy]
+ raise JenkinsJobsException(
+ "Strategy entered is not valid, must be "
+ + "one of: all, failure, failure-fixed, or "
+ "change"
+ )
+ XML.SubElement(j, "strategy").text = strategydict[strategy]
mappings = [
- ('notify-on-build-start', 'notifyOnBuildStart', False),
- ('notify-scm-committers', 'notifySuspects', False),
- ('notify-scm-culprits', 'notifyCulprits', False),
- ('notify-scm-fixers', 'notifyFixers', False),
- ('notify-upstream-committers', 'notifyUpstreamCommitters', False)
+ ("notify-on-build-start", "notifyOnBuildStart", False),
+ ("notify-scm-committers", "notifySuspects", False),
+ ("notify-scm-culprits", "notifyCulprits", False),
+ ("notify-scm-fixers", "notifyFixers", False),
+ ("notify-upstream-committers", "notifyUpstreamCommitters", False),
]
helpers.convert_mapping_to_xml(j, data, mappings, fail_required=True)
- message = data.get('message', 'summary-scm')
- messagedict = {'summary-scm': 'DefaultBuildToChatNotifier',
- 'summary': 'SummaryOnlyBuildToChatNotifier',
- 'summary-build': 'BuildParametersBuildToChatNotifier',
- 'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
+ message = data.get("message", "summary-scm")
+ messagedict = {
+ "summary-scm": "DefaultBuildToChatNotifier",
+ "summary": "SummaryOnlyBuildToChatNotifier",
+ "summary-build": "BuildParametersBuildToChatNotifier",
+ "summary-scm-fail": "PrintFailingTestsBuildToChatNotifier",
+ }
if message not in messagedict:
- raise JenkinsJobsException("Message entered is not valid, must be one "
- "of: summary-scm, summary, summary-build "
- "or summary-scm-fail")
- XML.SubElement(j, 'buildToChatNotifier', {
- 'class': 'hudson.plugins.im.build_notify.' + messagedict[message]})
- XML.SubElement(j, 'matrixMultiplier').text = 'ONLY_CONFIGURATIONS'
+ raise JenkinsJobsException(
+ "Message entered is not valid, must be one "
+ "of: summary-scm, summary, summary-build "
+ "or summary-scm-fail"
+ )
+ XML.SubElement(
+ j,
+ "buildToChatNotifier",
+ {"class": "hudson.plugins.im.build_notify." + messagedict[message]},
+ )
+ XML.SubElement(j, "matrixMultiplier").text = "ONLY_CONFIGURATIONS"
def workspace_cleanup(registry, xml_parent, data):
@@ -3559,36 +3618,37 @@ def workspace_cleanup(registry, xml_parent, data):
:language: yaml
"""
- p = XML.SubElement(xml_parent,
- 'hudson.plugins.ws__cleanup.WsCleanup')
+ p = XML.SubElement(xml_parent, "hudson.plugins.ws__cleanup.WsCleanup")
p.set("plugin", "ws-cleanup")
if "include" in data or "exclude" in data:
- patterns = XML.SubElement(p, 'patterns')
+ patterns = XML.SubElement(p, "patterns")
for inc in data.get("include", []):
- ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
- XML.SubElement(ptrn, 'pattern').text = inc
- XML.SubElement(ptrn, 'type').text = "INCLUDE"
+ ptrn = XML.SubElement(patterns, "hudson.plugins.ws__cleanup.Pattern")
+ XML.SubElement(ptrn, "pattern").text = inc
+ XML.SubElement(ptrn, "type").text = "INCLUDE"
for exc in data.get("exclude", []):
- ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
- XML.SubElement(ptrn, 'pattern').text = exc
- XML.SubElement(ptrn, 'type').text = "EXCLUDE"
+ ptrn = XML.SubElement(patterns, "hudson.plugins.ws__cleanup.Pattern")
+ XML.SubElement(ptrn, "pattern").text = exc
+ XML.SubElement(ptrn, "type").text = "EXCLUDE"
mappings = [
- ('dirmatch', 'deleteDirs', False),
- ('clean-parent', 'cleanupMatrixParent', False),
- ('external-deletion-command', 'externalDelete', ''),
- ('disable-deferred-wipeout', 'disableDeferredWipeout', False),
+ ("dirmatch", "deleteDirs", False),
+ ("clean-parent", "cleanupMatrixParent", False),
+ ("external-deletion-command", "externalDelete", ""),
+ ("disable-deferred-wipeout", "disableDeferredWipeout", False),
]
helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
- mask = [('success', 'cleanWhenSuccess'),
- ('unstable', 'cleanWhenUnstable'),
- ('failure', 'cleanWhenFailure'),
- ('not-built', 'cleanWhenNotBuilt'),
- ('aborted', 'cleanWhenAborted')]
- clean = data.get('clean-if', [])
+ mask = [
+ ("success", "cleanWhenSuccess"),
+ ("unstable", "cleanWhenUnstable"),
+ ("failure", "cleanWhenFailure"),
+ ("not-built", "cleanWhenNotBuilt"),
+ ("aborted", "cleanWhenAborted"),
+ ]
+ clean = data.get("clean-if", [])
cdict = dict()
for d in clean:
cdict.update(d)
@@ -3596,12 +3656,12 @@ def workspace_cleanup(registry, xml_parent, data):
XML.SubElement(p, v).text = str(cdict.pop(k, True)).lower()
if len(cdict) > 0:
- raise ValueError('clean-if must be one of: %r' % list(mask.keys()))
+ raise ValueError("clean-if must be one of: %r" % list(mask.keys()))
- if str(data.get("fail-build", False)).lower() == 'false':
- XML.SubElement(p, 'notFailBuild').text = 'true'
+ if str(data.get("fail-build", False)).lower() == "false":
+ XML.SubElement(p, "notFailBuild").text = "true"
else:
- XML.SubElement(p, 'notFailBuild').text = 'false'
+ XML.SubElement(p, "notFailBuild").text = "false"
def maven_deploy(registry, xml_parent, data):
@@ -3624,17 +3684,19 @@ def maven_deploy(registry, xml_parent, data):
:language: yaml
"""
- p = XML.SubElement(xml_parent, 'hudson.maven.RedeployPublisher')
- if 'id' in data:
- XML.SubElement(p, 'id').text = data['id']
- if 'url' in data:
- XML.SubElement(p, 'url').text = data['url']
- XML.SubElement(p, 'uniqueVersion').text = str(
- data.get('unique-version', True)).lower()
- XML.SubElement(p, 'evenIfUnstable').text = str(
- data.get('deploy-unstable', False)).lower()
- if 'release-env-var' in data:
- XML.SubElement(p, 'releaseEnvVar').text = data['release-env-var']
+ p = XML.SubElement(xml_parent, "hudson.maven.RedeployPublisher")
+ if "id" in data:
+ XML.SubElement(p, "id").text = data["id"]
+ if "url" in data:
+ XML.SubElement(p, "url").text = data["url"]
+ XML.SubElement(p, "uniqueVersion").text = str(
+ data.get("unique-version", True)
+ ).lower()
+ XML.SubElement(p, "evenIfUnstable").text = str(
+ data.get("deploy-unstable", False)
+ ).lower()
+ if "release-env-var" in data:
+ XML.SubElement(p, "releaseEnvVar").text = data["release-env-var"]
def artifactory(registry, xml_parent, data):
@@ -3748,26 +3810,28 @@ def artifactory(registry, xml_parent, data):
"""
artifactory = XML.SubElement(
- xml_parent, 'org.jfrog.hudson.ArtifactoryRedeployPublisher')
+ xml_parent, "org.jfrog.hudson.ArtifactoryRedeployPublisher"
+ )
# optional_props
- helpers.artifactory_optional_props(artifactory, data, 'publishers')
+ helpers.artifactory_optional_props(artifactory, data, "publishers")
- XML.SubElement(artifactory, 'matrixParams').text = ','.join(
- data.get('matrix-params', []))
+ XML.SubElement(artifactory, "matrixParams").text = ",".join(
+ data.get("matrix-params", [])
+ )
# details
- details = XML.SubElement(artifactory, 'details')
+ details = XML.SubElement(artifactory, "details")
helpers.artifactory_common_details(details, data)
mapping = [
- ('release-repo-key', 'repositoryKey', ''),
- ('snapshot-repo-key', 'snapshotsRepositoryKey', ''),
+ ("release-repo-key", "repositoryKey", ""),
+ ("snapshot-repo-key", "snapshotsRepositoryKey", ""),
]
helpers.convert_mapping_to_xml(details, data, mapping, fail_required=True)
- plugin = XML.SubElement(details, 'stagingPlugin')
- XML.SubElement(plugin, 'pluginName').text = 'None'
+ plugin = XML.SubElement(details, "stagingPlugin")
+ XML.SubElement(plugin, "pluginName").text = "None"
# artifactDeploymentPatterns
helpers.artifactory_deployment_patterns(artifactory, data)
@@ -3862,35 +3926,35 @@ def test_fairy(registry, xml_parent, data):
/../../tests/publishers/fixtures/test-fairy-ios001.yaml
:language: yaml
"""
- platform = data.get('platform')
- valid_platforms = ['android', 'ios']
+ platform = data.get("platform")
+ valid_platforms = ["android", "ios"]
- if 'platform' not in data:
- raise MissingAttributeError('platform')
- if platform == 'android':
+ if "platform" not in data:
+ raise MissingAttributeError("platform")
+ if platform == "android":
root = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.testfairy.TestFairyAndroidRecorder')
+ xml_parent, "org.jenkinsci.plugins.testfairy.TestFairyAndroidRecorder"
+ )
helpers.test_fairy_common(root, data)
mappings = [
- ('proguard-file', 'mappingFile', ''),
- ('keystorepath', 'keystorePath', None),
- ('storepass', 'storepass', 'android'),
- ('alias', 'alias', 'androiddebugkey'),
- ('keypass', 'keypass', '')]
- helpers.convert_mapping_to_xml(
- root, data, mappings, fail_required=True)
- elif platform == 'ios':
+ ("proguard-file", "mappingFile", ""),
+ ("keystorepath", "keystorePath", None),
+ ("storepass", "storepass", "android"),
+ ("alias", "alias", "androiddebugkey"),
+ ("keypass", "keypass", ""),
+ ]
+ helpers.convert_mapping_to_xml(root, data, mappings, fail_required=True)
+ elif platform == "ios":
root = XML.SubElement(
- xml_parent, 'org.jenkinsci.plugins.testfairy.TestFairyIosRecorder')
+ xml_parent, "org.jenkinsci.plugins.testfairy.TestFairyIosRecorder"
+ )
helpers.test_fairy_common(root, data)
- mappings = [('dSYM-file', 'mappingFile', '')]
- helpers.convert_mapping_to_xml(
- root, data, mappings, fail_required=True)
+ mappings = [("dSYM-file", "mappingFile", "")]
+ helpers.convert_mapping_to_xml(root, data, mappings, fail_required=True)
else:
- raise InvalidAttributeError('platform', platform, valid_platforms)
+ raise InvalidAttributeError("platform", platform, valid_platforms)
def text_finder(registry, xml_parent, data):
@@ -3917,16 +3981,15 @@ def text_finder(registry, xml_parent, data):
:language: yaml
"""
- finder = XML.SubElement(xml_parent,
- 'hudson.plugins.textfinder.TextFinderPublisher')
- finder.set('plugin', 'text-finder')
- if ('fileset' in data):
- XML.SubElement(finder, 'fileSet').text = data['fileset']
+ finder = XML.SubElement(xml_parent, "hudson.plugins.textfinder.TextFinderPublisher")
+ finder.set("plugin", "text-finder")
+ if "fileset" in data:
+ XML.SubElement(finder, "fileSet").text = data["fileset"]
mappings = [
- ('regexp', 'regexp', None),
- ('also-check-console-output', 'alsoCheckConsoleOutput', False),
- ('succeed-if-found', 'succeedIfFound', False),
- ('unstable-if-found', 'unstableIfFound', False)
+ ("regexp", "regexp", None),
+ ("also-check-console-output", "alsoCheckConsoleOutput", False),
+ ("succeed-if-found", "succeedIfFound", False),
+ ("unstable-if-found", "unstableIfFound", False),
]
helpers.convert_mapping_to_xml(finder, data, mappings, fail_required=True)
@@ -3954,20 +4017,20 @@ def html_publisher(registry, xml_parent, data):
:language: yaml
"""
- reporter = XML.SubElement(xml_parent, 'htmlpublisher.HtmlPublisher')
- targets = XML.SubElement(reporter, 'reportTargets')
- ptarget = XML.SubElement(targets, 'htmlpublisher.HtmlPublisherTarget')
+ reporter = XML.SubElement(xml_parent, "htmlpublisher.HtmlPublisher")
+ targets = XML.SubElement(reporter, "reportTargets")
+ ptarget = XML.SubElement(targets, "htmlpublisher.HtmlPublisherTarget")
mapping = [
- ('name', 'reportName', None),
- ('dir', 'reportDir', None),
- ('files', 'reportFiles', None),
- ('link-to-last-build', 'alwaysLinkToLastBuild', False),
- ('keep-all', 'keepAll', False),
- ('allow-missing', 'allowMissing', False),
+ ("name", "reportName", None),
+ ("dir", "reportDir", None),
+ ("files", "reportFiles", None),
+ ("link-to-last-build", "alwaysLinkToLastBuild", False),
+ ("keep-all", "keepAll", False),
+ ("allow-missing", "allowMissing", False),
]
helpers.convert_mapping_to_xml(ptarget, data, mapping, fail_required=True)
- XML.SubElement(ptarget, 'wrapperName').text = "htmlpublisher-wrapper.html"
+ XML.SubElement(ptarget, "wrapperName").text = "htmlpublisher-wrapper.html"
def rich_text_publisher(registry, xml_parent, data):
@@ -4001,22 +4064,21 @@ def rich_text_publisher(registry, xml_parent, data):
:language: yaml
"""
- parsers = ['HTML', 'Confluence', 'WikiText']
+ parsers = ["HTML", "Confluence", "WikiText"]
reporter = XML.SubElement(
- xml_parent,
- 'org.korosoft.jenkins.plugin.rtp.RichTextPublisher')
- reporter.set('plugin', 'rich-text-publisher-plugin')
+ xml_parent, "org.korosoft.jenkins.plugin.rtp.RichTextPublisher"
+ )
+ reporter.set("plugin", "rich-text-publisher-plugin")
mappings = [
- ('stable-text', 'stableText', None),
- ('unstable-text', 'unstableText', ''),
- ('failed-text', 'failedText', ''),
- ('unstable-as-stable', 'unstableAsStable', True),
- ('failed-as-stable', 'failedAsStable', True),
- ('parser-name', 'parserName', 'WikiText', parsers)
+ ("stable-text", "stableText", None),
+ ("unstable-text", "unstableText", ""),
+ ("failed-text", "failedText", ""),
+ ("unstable-as-stable", "unstableAsStable", True),
+ ("failed-as-stable", "failedAsStable", True),
+ ("parser-name", "parserName", "WikiText", parsers),
]
- helpers.convert_mapping_to_xml(
- reporter, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(reporter, data, mappings, fail_required=True)
def tap(registry, xml_parent, data):
@@ -4053,24 +4115,22 @@ def tap(registry, xml_parent, data):
:language: yaml
"""
- tap = XML.SubElement(xml_parent, 'org.tap4j.plugin.TapPublisher')
- tap.set('plugin', 'tap')
+ tap = XML.SubElement(xml_parent, "org.tap4j.plugin.TapPublisher")
+ tap.set("plugin", "tap")
mappings = [
- ('results', 'testResults', None),
- ('fail-if-no-results', 'failIfNoResults', False),
- ('failed-tests-mark-build-as-failure',
- 'failedTestsMarkBuildAsFailure',
- False),
- ('output-tap-to-console', 'outputTapToConsole', True),
- ('enable-subtests', 'enableSubtests', True),
- ('discard-old-reports', 'discardOldReports', False),
- ('todo-is-failure', 'todoIsFailure', True),
- ('include-comment-diagnostics', 'includeCommentDiagnostics', False),
- ('validate-tests', 'validateNumberOfTests', False),
- ('plan-required', 'planRequired', True),
- ('verbose', 'verbose', True),
- ('show-only-failures', 'showOnlyFailures', False),
+ ("results", "testResults", None),
+ ("fail-if-no-results", "failIfNoResults", False),
+ ("failed-tests-mark-build-as-failure", "failedTestsMarkBuildAsFailure", False),
+ ("output-tap-to-console", "outputTapToConsole", True),
+ ("enable-subtests", "enableSubtests", True),
+ ("discard-old-reports", "discardOldReports", False),
+ ("todo-is-failure", "todoIsFailure", True),
+ ("include-comment-diagnostics", "includeCommentDiagnostics", False),
+ ("validate-tests", "validateNumberOfTests", False),
+ ("plan-required", "planRequired", True),
+ ("verbose", "verbose", True),
+ ("show-only-failures", "showOnlyFailures", False),
]
helpers.convert_mapping_to_xml(tap, data, mappings, fail_required=True)
@@ -4104,28 +4164,29 @@ def post_tasks(registry, xml_parent, data):
:language: yaml
"""
- pb_xml = XML.SubElement(xml_parent,
- 'hudson.plugins.postbuildtask.PostbuildTask')
- tasks_xml = XML.SubElement(pb_xml, 'tasks')
+ pb_xml = XML.SubElement(xml_parent, "hudson.plugins.postbuildtask.PostbuildTask")
+ tasks_xml = XML.SubElement(pb_xml, "tasks")
for task in data:
task_xml = XML.SubElement(
- tasks_xml,
- 'hudson.plugins.postbuildtask.TaskProperties')
- matches_xml = XML.SubElement(task_xml, 'logTexts')
- for match in task.get('matches', []):
+ tasks_xml, "hudson.plugins.postbuildtask.TaskProperties"
+ )
+ matches_xml = XML.SubElement(task_xml, "logTexts")
+ for match in task.get("matches", []):
lt_xml = XML.SubElement(
- matches_xml,
- 'hudson.plugins.postbuildtask.LogProperties')
- XML.SubElement(lt_xml, 'logText').text = str(
- match.get('log-text', False) or '')
- XML.SubElement(lt_xml, 'operator').text = str(
- match.get('operator', 'AND')).upper()
+ matches_xml, "hudson.plugins.postbuildtask.LogProperties"
+ )
+ XML.SubElement(lt_xml, "logText").text = str(
+ match.get("log-text", False) or ""
+ )
+ XML.SubElement(lt_xml, "operator").text = str(
+ match.get("operator", "AND")
+ ).upper()
mapping = [
- ('escalate-status', 'EscalateStatus', False),
- ('run-if-job-successful', 'RunIfJobSuccessful', False),
- ('script', 'script', '')]
- helpers.convert_mapping_to_xml(task_xml,
- task, mapping, fail_required=True)
+ ("escalate-status", "EscalateStatus", False),
+ ("run-if-job-successful", "RunIfJobSuccessful", False),
+ ("script", "script", ""),
+ ]
+ helpers.convert_mapping_to_xml(task_xml, task, mapping, fail_required=True)
def postbuildscript(registry, xml_parent, data):
@@ -4230,19 +4291,16 @@ def postbuildscript(registry, xml_parent, data):
"""
pbs_xml = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.postbuildscript.PostBuildScript')
+ xml_parent, "org.jenkinsci.plugins.postbuildscript.PostBuildScript"
+ )
- info = registry.get_plugin_info('postbuildscript')
+ info = registry.get_plugin_info("postbuildscript")
# Note: Assume latest version of plugin is preferred config format
- version = pkg_resources.parse_version(
- info.get('version', str(sys.maxsize)))
- if version >= pkg_resources.parse_version('2.0'):
- pbs_xml = XML.SubElement(pbs_xml, 'config')
+ version = pkg_resources.parse_version(info.get("version", str(sys.maxsize)))
+ if version >= pkg_resources.parse_version("2.0"):
+ pbs_xml = XML.SubElement(pbs_xml, "config")
- mapping = [
- ('mark-unstable-if-failed', 'markBuildUnstable', False),
- ]
+ mapping = [("mark-unstable-if-failed", "markBuildUnstable", False)]
helpers.convert_mapping_to_xml(pbs_xml, data, mapping, fail_required=True)
if version >= pkg_resources.parse_version("2.0"):
@@ -4251,153 +4309,148 @@ def postbuildscript(registry, xml_parent, data):
# Script Files #
################
- script_mapping = [
- ('role', 'role', 'BOTH'),
- ('file-path', 'filePath', False),
- ]
- sf_path = 'org.jenkinsci.plugins.postbuildscript.model.ScriptFile'
- sf_xml = XML.SubElement(pbs_xml, 'scriptFiles')
+ script_mapping = [("role", "role", "BOTH"), ("file-path", "filePath", False)]
+ sf_path = "org.jenkinsci.plugins.postbuildscript.model.ScriptFile"
+ sf_xml = XML.SubElement(pbs_xml, "scriptFiles")
- for gs_data in data.get('generic-script', []):
+ for gs_data in data.get("generic-script", []):
x = XML.SubElement(sf_xml, sf_path)
- results_xml = XML.SubElement(x, 'results')
+ results_xml = XML.SubElement(x, "results")
- for result in gs_data.get('build-on', ['SUCCESS']):
- XML.SubElement(results_xml, 'string').text = result
+ for result in gs_data.get("build-on", ["SUCCESS"]):
+ XML.SubElement(results_xml, "string").text = result
helpers.convert_mapping_to_xml(
- x, gs_data, script_mapping, fail_required=True)
- XML.SubElement(x, 'scriptType').text = 'GENERIC'
+ x, gs_data, script_mapping, fail_required=True
+ )
+ XML.SubElement(x, "scriptType").text = "GENERIC"
- for gs_data in data.get('groovy-script', []):
+ for gs_data in data.get("groovy-script", []):
x = XML.SubElement(sf_xml, sf_path)
- results_xml = XML.SubElement(x, 'results')
+ results_xml = XML.SubElement(x, "results")
- for result in gs_data.get('build-on', ['SUCCESS']):
- XML.SubElement(results_xml, 'string').text = result
+ for result in gs_data.get("build-on", ["SUCCESS"]):
+ XML.SubElement(results_xml, "string").text = result
helpers.convert_mapping_to_xml(
- x, gs_data, script_mapping, fail_required=True)
- XML.SubElement(x, 'scriptType').text = 'GROOVY'
+ x, gs_data, script_mapping, fail_required=True
+ )
+ XML.SubElement(x, "scriptType").text = "GROOVY"
#################
# Inline Groovy #
#################
- groovy_mapping = [
- ('role', 'role', 'BOTH'),
- ('content', 'content', False),
- ]
- gs_path = 'org.jenkinsci.plugins.postbuildscript.model.Script'
- gs_xml = XML.SubElement(pbs_xml, 'groovyScripts')
- for gs_data in data.get('groovy', []):
+ groovy_mapping = [("role", "role", "BOTH"), ("content", "content", False)]
+ gs_path = "org.jenkinsci.plugins.postbuildscript.model.Script"
+ gs_xml = XML.SubElement(pbs_xml, "groovyScripts")
+ for gs_data in data.get("groovy", []):
x = XML.SubElement(gs_xml, gs_path)
- results_xml = XML.SubElement(x, 'results')
+ results_xml = XML.SubElement(x, "results")
- for result in gs_data.get('build-on', ['SUCCESS']):
- XML.SubElement(results_xml, 'string').text = result
+ for result in gs_data.get("build-on", ["SUCCESS"]):
+ XML.SubElement(results_xml, "string").text = result
helpers.convert_mapping_to_xml(
- x, gs_data, groovy_mapping, fail_required=True)
+ x, gs_data, groovy_mapping, fail_required=True
+ )
############
# Builders #
############
- builder_mapping = [
- ('role', 'role', 'BOTH'),
- ]
- bs_path = 'org.jenkinsci.plugins.postbuildscript.model.PostBuildStep'
- bs_xml = XML.SubElement(pbs_xml, 'buildSteps')
- for bs_data in data.get('builders', []):
+ builder_mapping = [("role", "role", "BOTH")]
+ bs_path = "org.jenkinsci.plugins.postbuildscript.model.PostBuildStep"
+ bs_xml = XML.SubElement(pbs_xml, "buildSteps")
+ for bs_data in data.get("builders", []):
x = XML.SubElement(bs_xml, bs_path)
- results_xml = XML.SubElement(x, 'results')
+ results_xml = XML.SubElement(x, "results")
- for result in bs_data.get('build-on', ['SUCCESS']):
- XML.SubElement(results_xml, 'string').text = result
+ for result in bs_data.get("build-on", ["SUCCESS"]):
+ XML.SubElement(results_xml, "string").text = result
helpers.convert_mapping_to_xml(
- x, bs_data, builder_mapping, fail_required=True)
+ x, bs_data, builder_mapping, fail_required=True
+ )
- build_steps_xml = XML.SubElement(x, 'buildSteps')
- for builder in bs_data.get('build-steps'):
- registry.dispatch('builder', build_steps_xml, builder)
+ build_steps_xml = XML.SubElement(x, "buildSteps")
+ for builder in bs_data.get("build-steps"):
+ registry.dispatch("builder", build_steps_xml, builder)
else: # Options below are all deprecated in version < 2.0 of plugin
# Shell/Groovy in a file
script_types = {
- 'generic-script': 'GenericScript',
- 'groovy-script': 'GroovyScriptFile',
+ "generic-script": "GenericScript",
+ "groovy-script": "GroovyScriptFile",
}
# Assuming yaml preserves order of input data make sure
# corresponding XML steps are generated in the same order
- build_scripts = [(k, v) for k, v in data.items()
- if k in script_types or k in ['groovy', 'builders']]
+ build_scripts = [
+ (k, v)
+ for k, v in data.items()
+ if k in script_types or k in ["groovy", "builders"]
+ ]
for step, script_data in build_scripts:
if step in script_types:
scripts_xml = XML.SubElement(
- pbs_xml, step[:-len('-script')] + 'ScriptFileList')
+ pbs_xml, step[: -len("-script")] + "ScriptFileList"
+ )
for shell_script in script_data:
script_xml = XML.SubElement(
scripts_xml,
- 'org.jenkinsci.plugins.postbuildscript.' +
- script_types[step])
- file_path_xml = XML.SubElement(script_xml, 'filePath')
+ "org.jenkinsci.plugins.postbuildscript." + script_types[step],
+ )
+ file_path_xml = XML.SubElement(script_xml, "filePath")
file_path_xml.text = shell_script
# Inlined Groovy
- if step == 'groovy':
- groovy_inline_xml = XML.SubElement(
- pbs_xml, 'groovyScriptContentList')
+ if step == "groovy":
+ groovy_inline_xml = XML.SubElement(pbs_xml, "groovyScriptContentList")
for groovy in script_data:
groovy_xml = XML.SubElement(
groovy_inline_xml,
- 'org.jenkinsci.plugins.postbuildscript.'
- 'GroovyScriptContent'
+ "org.jenkinsci.plugins.postbuildscript." "GroovyScriptContent",
)
- groovy_content = XML.SubElement(groovy_xml, 'content')
+ groovy_content = XML.SubElement(groovy_xml, "content")
groovy_content.text = groovy
# Inject builders
- if step == 'builders':
- build_steps_xml = XML.SubElement(pbs_xml, 'buildSteps')
+ if step == "builders":
+ build_steps_xml = XML.SubElement(pbs_xml, "buildSteps")
for builder in script_data:
- registry.dispatch('builder', build_steps_xml, builder)
+ registry.dispatch("builder", build_steps_xml, builder)
# When to run the build? Note the plugin let one specify both options
# although they are antinomic
# onsuccess and onfailure parameters are deprecated, this is to keep
# backwards compatability
- success_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfSuccess')
- if 'script-only-if-succeeded' in data:
- success_xml.text = str(
- data.get('script-only-if-succeeded', True)).lower()
+ success_xml = XML.SubElement(pbs_xml, "scriptOnlyIfSuccess")
+ if "script-only-if-succeeded" in data:
+ success_xml.text = str(data.get("script-only-if-succeeded", True)).lower()
else:
- success_xml.text = str(data.get('onsuccess', True)).lower()
+ success_xml.text = str(data.get("onsuccess", True)).lower()
- failure_xml = XML.SubElement(pbs_xml, 'scriptOnlyIfFailure')
- if 'script-only-if-failed' in data:
- failure_xml.text = str(
- data.get('script-only-if-failed', False)).lower()
+ failure_xml = XML.SubElement(pbs_xml, "scriptOnlyIfFailure")
+ if "script-only-if-failed" in data:
+ failure_xml.text = str(data.get("script-only-if-failed", False)).lower()
else:
- failure_xml.text = str(data.get('onfailure', False)).lower()
+ failure_xml.text = str(data.get("onfailure", False)).lower()
# TODO: we may want to avoid setting "execute-on" on non-matrix jobs,
# either by skipping this part or by raising an error to let the user
# know an attempt was made to set execute-on on a non-matrix job.
# There are currently no easy ways to check for this though.
- if 'execute-on' in data:
- valid_values = ('matrix', 'axes', 'both')
- execute_on = data['execute-on'].lower()
+ if "execute-on" in data:
+ valid_values = ("matrix", "axes", "both")
+ execute_on = data["execute-on"].lower()
if execute_on not in valid_values:
raise JenkinsJobsException(
- 'execute-on must be one of %s, got %s' %
- valid_values, execute_on
+ "execute-on must be one of %s, got %s" % valid_values, execute_on
)
- execute_on_xml = XML.SubElement(pbs_xml, 'executeOn')
+ execute_on_xml = XML.SubElement(pbs_xml, "executeOn")
execute_on_xml.text = execute_on.upper()
@@ -4425,12 +4478,13 @@ def xml_summary(registry, xml_parent, data):
"""
summary = XML.SubElement(
- xml_parent, 'hudson.plugins.summary__report.ACIPluginPublisher')
- summary.set('plugin', 'summary_report')
+ xml_parent, "hudson.plugins.summary__report.ACIPluginPublisher"
+ )
+ summary.set("plugin", "summary_report")
mapping = [
- ('files', 'name', None),
- ('shown-on-project-page', 'shownOnProjectPage', False),
+ ("files", "name", None),
+ ("shown-on-project-page", "shownOnProjectPage", False),
]
helpers.convert_mapping_to_xml(summary, data, mapping, fail_required=True)
@@ -4473,26 +4527,27 @@ def robot(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/robot-full.yaml
:language: yaml
"""
- parent = XML.SubElement(xml_parent, 'hudson.plugins.robot.RobotPublisher')
- parent.set('plugin', 'robot')
+ parent = XML.SubElement(xml_parent, "hudson.plugins.robot.RobotPublisher")
+ parent.set("plugin", "robot")
mappings = [
- ('output-path', 'outputPath', None),
- ('log-file-link', 'logFileLink', ''),
- ('report-html', 'reportFileName', 'report.html'),
- ('log-html', 'logFileName', 'log.html'),
- ('output-xml', 'outputFileName', 'output.xml'),
- ('pass-threshold', 'passThreshold', '0.0'),
- ('unstable-threshold', 'unstableThreshold', '0.0'),
- ('only-critical', 'onlyCritical', True),
- ('enable-cache', 'enableCache', True)
+ ("output-path", "outputPath", None),
+ ("log-file-link", "logFileLink", ""),
+ ("report-html", "reportFileName", "report.html"),
+ ("log-html", "logFileName", "log.html"),
+ ("output-xml", "outputFileName", "output.xml"),
+ ("pass-threshold", "passThreshold", "0.0"),
+ ("unstable-threshold", "unstableThreshold", "0.0"),
+ ("only-critical", "onlyCritical", True),
+ ("enable-cache", "enableCache", True),
]
helpers.convert_mapping_to_xml(parent, data, mappings, fail_required=True)
- other_files = XML.SubElement(parent, 'otherFiles')
- for other_file in data.get('other-files', []):
- XML.SubElement(other_files, 'string').text = str(other_file)
- XML.SubElement(parent, 'disableArchiveOutput').text = str(
- not data.get('archive-output-xml', True)).lower()
+ other_files = XML.SubElement(parent, "otherFiles")
+ for other_file in data.get("other-files", []):
+ XML.SubElement(other_files, "string").text = str(other_file)
+ XML.SubElement(parent, "disableArchiveOutput").text = str(
+ not data.get("archive-output-xml", True)
+ ).lower()
def warnings(registry, xml_parent, data):
@@ -4617,79 +4672,80 @@ def warnings(registry, xml_parent, data):
:language: yaml
"""
- warnings = XML.SubElement(xml_parent,
- 'hudson.plugins.warnings.'
- 'WarningsPublisher')
- warnings.set('plugin', 'warnings')
- console = XML.SubElement(warnings, 'consoleParsers')
- for parser in data.get('console-log-parsers', []):
- console_parser = XML.SubElement(console,
- 'hudson.plugins.warnings.'
- 'ConsoleParser')
- XML.SubElement(console_parser, 'parserName').text = parser
- workspace = XML.SubElement(warnings, 'parserConfigurations')
- for wfs in data.get('workspace-file-scanners', []):
- workspace_pattern = XML.SubElement(workspace,
- 'hudson.plugins.warnings.'
- 'ParserConfiguration')
+ warnings = XML.SubElement(
+ xml_parent, "hudson.plugins.warnings." "WarningsPublisher"
+ )
+ warnings.set("plugin", "warnings")
+ console = XML.SubElement(warnings, "consoleParsers")
+ for parser in data.get("console-log-parsers", []):
+ console_parser = XML.SubElement(
+ console, "hudson.plugins.warnings." "ConsoleParser"
+ )
+ XML.SubElement(console_parser, "parserName").text = parser
+ workspace = XML.SubElement(warnings, "parserConfigurations")
+ for wfs in data.get("workspace-file-scanners", []):
+ workspace_pattern = XML.SubElement(
+ workspace, "hudson.plugins.warnings." "ParserConfiguration"
+ )
workspace_pattern_mappings = [
- ('file-pattern', 'pattern', None),
- ('scanner', 'parserName', '')
+ ("file-pattern", "pattern", None),
+ ("scanner", "parserName", ""),
]
- helpers.convert_mapping_to_xml(workspace_pattern,
- wfs,
- workspace_pattern_mappings,
- fail_required=True)
- prioritiesDict = {'priority-high': 'high',
- 'high-and-normal': 'normal',
- 'all-priorities': 'low'}
+ helpers.convert_mapping_to_xml(
+ workspace_pattern, wfs, workspace_pattern_mappings, fail_required=True
+ )
+ prioritiesDict = {
+ "priority-high": "high",
+ "high-and-normal": "normal",
+ "all-priorities": "low",
+ }
warnings_mappings = [
- ('files-to-include', 'includePattern', ''),
- ('files-to-ignore', 'excludePattern', ''),
- ('messages-to-ignore', 'messagesPattern', ''),
- ('categories-to-ignore', 'categoriesPattern', ''),
- ('plugin-name', 'pluginName', '[WARNINGS]'),
- ('run-always', 'canRunOnFailed', False),
- ('detect-modules', 'shouldDetectModules', False),
- ('health-threshold-high', 'healthy', ''),
- ('health-threshold-low', 'unHealthy', ''),
- ('health-priorities',
- 'thresholdLimit',
- 'all-priorities',
- prioritiesDict),
- ('default-encoding', 'defaultEncoding', '')
+ ("files-to-include", "includePattern", ""),
+ ("files-to-ignore", "excludePattern", ""),
+ ("messages-to-ignore", "messagesPattern", ""),
+ ("categories-to-ignore", "categoriesPattern", ""),
+ ("plugin-name", "pluginName", "[WARNINGS]"),
+ ("run-always", "canRunOnFailed", False),
+ ("detect-modules", "shouldDetectModules", False),
+ ("health-threshold-high", "healthy", ""),
+ ("health-threshold-low", "unHealthy", ""),
+ ("health-priorities", "thresholdLimit", "all-priorities", prioritiesDict),
+ ("default-encoding", "defaultEncoding", ""),
]
helpers.convert_mapping_to_xml(
- warnings, data, warnings_mappings, fail_required=True)
+ warnings, data, warnings_mappings, fail_required=True
+ )
# Note the logic reversal (included here to match the GUI)
- XML.SubElement(warnings, 'doNotResolveRelativePaths').text = str(
- not data.get('resolve-relative-paths', False)).lower()
- td = XML.SubElement(warnings, 'thresholds')
+ XML.SubElement(warnings, "doNotResolveRelativePaths").text = str(
+ not data.get("resolve-relative-paths", False)
+ ).lower()
+ td = XML.SubElement(warnings, "thresholds")
for base in ["total", "new"]:
thresholds = data.get("%s-thresholds" % base, {})
for status in ["unstable", "failed"]:
bystatus = thresholds.get(status, {})
for level in ["all", "high", "normal", "low"]:
- val = str(bystatus.get("%s-%s" % (base, level), ''))
- XML.SubElement(td, "%s%s%s" % (status,
- base.capitalize(), level.capitalize())
- ).text = val
- if data.get('new-thresholds'):
- XML.SubElement(warnings, 'dontComputeNew').text = 'false'
- delta = data.get('use-delta-for-new-warnings', False)
- XML.SubElement(warnings, 'useDeltaValues').text = str(delta).lower()
- use_previous_build = data.get('use-previous-build-as-reference', False)
- XML.SubElement(warnings, 'usePreviousBuildAsReference').text = str(
- use_previous_build).lower()
- use_stable_builds = data.get('only-use-stable-builds-as-reference',
- False)
- XML.SubElement(warnings, 'useStableBuildAsReference').text = str(
- use_stable_builds).lower()
+ val = str(bystatus.get("%s-%s" % (base, level), ""))
+ XML.SubElement(
+ td, "%s%s%s" % (status, base.capitalize(), level.capitalize())
+ ).text = val
+ if data.get("new-thresholds"):
+ XML.SubElement(warnings, "dontComputeNew").text = "false"
+ delta = data.get("use-delta-for-new-warnings", False)
+ XML.SubElement(warnings, "useDeltaValues").text = str(delta).lower()
+ use_previous_build = data.get("use-previous-build-as-reference", False)
+ XML.SubElement(warnings, "usePreviousBuildAsReference").text = str(
+ use_previous_build
+ ).lower()
+ use_stable_builds = data.get("only-use-stable-builds-as-reference", False)
+ XML.SubElement(warnings, "useStableBuildAsReference").text = str(
+ use_stable_builds
+ ).lower()
else:
- XML.SubElement(warnings, 'dontComputeNew').text = 'true'
- XML.SubElement(warnings, 'useDeltaValues').text = 'false'
- XML.SubElement(warnings, 'usePreviousBuildAsReference').text = 'false'
- XML.SubElement(warnings, 'useStableBuildAsReference').text = 'false'
+ XML.SubElement(warnings, "dontComputeNew").text = "true"
+ XML.SubElement(warnings, "useDeltaValues").text = "false"
+ XML.SubElement(warnings, "usePreviousBuildAsReference").text = "false"
+ XML.SubElement(warnings, "useStableBuildAsReference").text = "false"
def sloccount(registry, xml_parent, data):
@@ -4723,15 +4779,14 @@ def sloccount(registry, xml_parent, data):
/../../tests/publishers/fixtures/sloccount-full.yaml
:language: yaml
"""
- top = XML.SubElement(xml_parent,
- 'hudson.plugins.sloccount.SloccountPublisher')
- top.set('plugin', 'sloccount')
+ top = XML.SubElement(xml_parent, "hudson.plugins.sloccount.SloccountPublisher")
+ top.set("plugin", "sloccount")
mappings = [
- ('report-files', 'pattern', '**/sloccount.sc'),
- ('charset', 'encoding', 'UTF-8'),
- ('builds-in-graph', 'numBuildsInGraph', 0),
- ('comment-is-code', 'commentIsCode', False),
- ('ignore-build-failure', 'ignoreBuildFailure', False)
+ ("report-files", "pattern", "**/sloccount.sc"),
+ ("charset", "encoding", "UTF-8"),
+ ("builds-in-graph", "numBuildsInGraph", 0),
+ ("comment-is-code", "commentIsCode", False),
+ ("ignore-build-failure", "ignoreBuildFailure", False),
]
helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
@@ -4800,50 +4855,52 @@ def ircbot(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/ircbot-full.yaml
:language: yaml
"""
- top = XML.SubElement(xml_parent, 'hudson.plugins.ircbot.IrcPublisher')
- top.set('plugin', 'ircbot')
- message_dict = {'summary-scm': 'DefaultBuildToChatNotifier',
- 'summary': 'SummaryOnlyBuildToChatNotifier',
- 'summary-params': 'BuildParametersBuildToChatNotifier',
- 'summary-scm-fail': 'PrintFailingTestsBuildToChatNotifier'}
- message = data.get('message-type', 'summary-scm')
+ top = XML.SubElement(xml_parent, "hudson.plugins.ircbot.IrcPublisher")
+ top.set("plugin", "ircbot")
+ message_dict = {
+ "summary-scm": "DefaultBuildToChatNotifier",
+ "summary": "SummaryOnlyBuildToChatNotifier",
+ "summary-params": "BuildParametersBuildToChatNotifier",
+ "summary-scm-fail": "PrintFailingTestsBuildToChatNotifier",
+ }
+ message = data.get("message-type", "summary-scm")
if message not in message_dict:
- raise JenkinsJobsException("message-type entered is not valid, must "
- "be one of: %s" %
- ", ".join(message_dict.keys()))
+ raise JenkinsJobsException(
+ "message-type entered is not valid, must "
+ "be one of: %s" % ", ".join(message_dict.keys())
+ )
message = "hudson.plugins.im.build_notify." + message_dict.get(message)
- XML.SubElement(top, 'buildToChatNotifier', attrib={'class': message})
- targets = XML.SubElement(top, 'targets')
- channels = data.get('channels', [])
+ XML.SubElement(top, "buildToChatNotifier", attrib={"class": message})
+ targets = XML.SubElement(top, "targets")
+ channels = data.get("channels", [])
for channel in channels:
- sub = XML.SubElement(targets,
- 'hudson.plugins.im.GroupChatIMMessageTarget')
+ sub = XML.SubElement(targets, "hudson.plugins.im.GroupChatIMMessageTarget")
sub_mappings = [
- ('name', 'name', ''),
- ('password', 'password', ''),
- ('notify-only', 'notificationOnly', False)
+ ("name", "name", ""),
+ ("password", "password", ""),
+ ("notify-only", "notificationOnly", False),
]
- helpers.convert_mapping_to_xml(
- sub, channel, sub_mappings, fail_required=True)
- strategy_dict = {'all': 'ALL',
- 'any-failure': 'ANY_FAILURE',
- 'failure-and-fixed': 'FAILURE_AND_FIXED',
- 'new-failure-and-fixed': 'NEW_FAILURE_AND_FIXED',
- 'statechange-only': 'STATECHANGE_ONLY'}
- matrix_dict = {'all': 'ALL',
- 'only-configurations': 'ONLY_CONFIGURATIONS',
- 'only-parent': 'ONLY_PARENT'}
+ helpers.convert_mapping_to_xml(sub, channel, sub_mappings, fail_required=True)
+ strategy_dict = {
+ "all": "ALL",
+ "any-failure": "ANY_FAILURE",
+ "failure-and-fixed": "FAILURE_AND_FIXED",
+ "new-failure-and-fixed": "NEW_FAILURE_AND_FIXED",
+ "statechange-only": "STATECHANGE_ONLY",
+ }
+ matrix_dict = {
+ "all": "ALL",
+ "only-configurations": "ONLY_CONFIGURATIONS",
+ "only-parent": "ONLY_PARENT",
+ }
mappings = [
- ('strategy', 'strategy', 'all', strategy_dict),
- ('notify-start', 'notifyOnBuildStart', False),
- ('notify-committers', 'notifySuspects', False),
- ('notify-culprits', 'notifyCulprits', False),
- ('notify-fixers', 'notifyFixers', False),
- ('notify-upstream', 'notifyUpstreamCommitters', False),
- ('matrix-notifier',
- 'matrixMultiplier',
- 'only-configurations',
- matrix_dict)
+ ("strategy", "strategy", "all", strategy_dict),
+ ("notify-start", "notifyOnBuildStart", False),
+ ("notify-committers", "notifySuspects", False),
+ ("notify-culprits", "notifyCulprits", False),
+ ("notify-fixers", "notifyFixers", False),
+ ("notify-upstream", "notifyUpstreamCommitters", False),
+ ("matrix-notifier", "matrixMultiplier", "only-configurations", matrix_dict),
]
helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
@@ -4921,80 +4978,99 @@ def plot(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/plot-full.yaml
:language: yaml
"""
- top = XML.SubElement(xml_parent, 'hudson.plugins.plot.PlotPublisher')
- plots = XML.SubElement(top, 'plots')
- format_dict = {'properties': 'hudson.plugins.plot.PropertiesSeries',
- 'csv': 'hudson.plugins.plot.CSVSeries',
- 'xml': 'hudson.plugins.plot.XMLSeries'}
- xpath_dict = {'nodeset': 'NODESET', 'node': 'NODE', 'string': 'STRING',
- 'boolean': 'BOOLEAN', 'number': 'NUMBER'}
- inclusion_dict = {'off': 'OFF',
- 'include-by-string': 'INCLUDE_BY_STRING',
- 'exclude-by-string': 'EXCLUDE_BY_STRING',
- 'include-by-column': 'INCLUDE_BY_COLUMN',
- 'exclude-by-column': 'EXCLUDE_BY_COLUMN'}
-
- style_list = ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea',
- 'stackedbar', 'stackedbar3d', 'waterfall']
+ top = XML.SubElement(xml_parent, "hudson.plugins.plot.PlotPublisher")
+ plots = XML.SubElement(top, "plots")
+ format_dict = {
+ "properties": "hudson.plugins.plot.PropertiesSeries",
+ "csv": "hudson.plugins.plot.CSVSeries",
+ "xml": "hudson.plugins.plot.XMLSeries",
+ }
+ xpath_dict = {
+ "nodeset": "NODESET",
+ "node": "NODE",
+ "string": "STRING",
+ "boolean": "BOOLEAN",
+ "number": "NUMBER",
+ }
+ inclusion_dict = {
+ "off": "OFF",
+ "include-by-string": "INCLUDE_BY_STRING",
+ "exclude-by-string": "EXCLUDE_BY_STRING",
+ "include-by-column": "INCLUDE_BY_COLUMN",
+ "exclude-by-column": "EXCLUDE_BY_COLUMN",
+ }
+
+ style_list = [
+ "area",
+ "bar",
+ "bar3d",
+ "line",
+ "line3d",
+ "stackedArea",
+ "stackedbar",
+ "stackedbar3d",
+ "waterfall",
+ ]
plot_mappings = [
- ('title', 'title', ''),
- ('yaxis', 'yaxis', ''),
- ('width', 'width', '750'),
- ('height', 'height', '450'),
- ('csv-file-name', 'csvFileName', ''),
- ('group', 'group', None),
- ('use-description', 'useDescr', False),
- ('exclude-zero-yaxis', 'exclZero', False),
- ('logarithmic-yaxis', 'logarithmic', False),
- ('keep-records', 'keepRecords', False),
- ('num-builds', 'numBuilds', ''),
- ('style', 'style', 'line', style_list),
+ ("title", "title", ""),
+ ("yaxis", "yaxis", ""),
+ ("width", "width", "750"),
+ ("height", "height", "450"),
+ ("csv-file-name", "csvFileName", ""),
+ ("group", "group", None),
+ ("use-description", "useDescr", False),
+ ("exclude-zero-yaxis", "exclZero", False),
+ ("logarithmic-yaxis", "logarithmic", False),
+ ("keep-records", "keepRecords", False),
+ ("num-builds", "numBuilds", ""),
+ ("style", "style", "line", style_list),
]
plot_csv_mappings = [
- ('inclusion-flag', 'inclusionFlag', 'off', inclusion_dict),
- ('exclude', 'exclusionValues', ''),
- ('url', 'url', ''),
- ('display-table', 'displayTableFlag', False)
+ ("inclusion-flag", "inclusionFlag", "off", inclusion_dict),
+ ("exclude", "exclusionValues", ""),
+ ("url", "url", ""),
+ ("display-table", "displayTableFlag", False),
]
plot_xml_mappings = [
- ('url', 'url', ''),
- ('xpath', 'xpathString', ''),
- ('xpath-type', 'nodeTypeString', 'node', xpath_dict)
+ ("url", "url", ""),
+ ("xpath", "xpathString", ""),
+ ("xpath-type", "nodeTypeString", "node", xpath_dict),
]
for plot in data:
- plugin = XML.SubElement(plots, 'hudson.plugins.plot.Plot')
- helpers.convert_mapping_to_xml(
- plugin, plot, plot_mappings, fail_required=True)
+ plugin = XML.SubElement(plots, "hudson.plugins.plot.Plot")
+ helpers.convert_mapping_to_xml(plugin, plot, plot_mappings, fail_required=True)
- topseries = XML.SubElement(plugin, 'series')
- series = plot['series']
+ topseries = XML.SubElement(plugin, "series")
+ series = plot["series"]
for serie in series:
- format_data = serie.get('format')
+ format_data = serie.get("format")
if format_data not in format_dict:
- raise JenkinsJobsException("format entered is not valid, must "
- "be one of: %s" %
- " , ".join(format_dict.keys()))
+ raise JenkinsJobsException(
+ "format entered is not valid, must "
+ "be one of: %s" % " , ".join(format_dict.keys())
+ )
subserie = XML.SubElement(topseries, format_dict.get(format_data))
- XML.SubElement(subserie, 'file').text = serie.get('file')
- if format_data == 'properties':
- XML.SubElement(subserie, 'label').text = serie.get('label', '')
- if format_data == 'csv':
+ XML.SubElement(subserie, "file").text = serie.get("file")
+ if format_data == "properties":
+ XML.SubElement(subserie, "label").text = serie.get("label", "")
+ if format_data == "csv":
helpers.convert_mapping_to_xml(
- subserie, serie, plot_csv_mappings, fail_required=True)
- if serie.get('exclude', ''):
- exclude_strings = serie.get('exclude', '').split(',')
- exclusionset = XML.SubElement(subserie, 'strExclusionSet')
+ subserie, serie, plot_csv_mappings, fail_required=True
+ )
+ if serie.get("exclude", ""):
+ exclude_strings = serie.get("exclude", "").split(",")
+ exclusionset = XML.SubElement(subserie, "strExclusionSet")
for exclude_string in exclude_strings:
- XML.SubElement(exclusionset, 'string').text = \
- exclude_string
- if format_data == 'xml':
+ XML.SubElement(exclusionset, "string").text = exclude_string
+ if format_data == "xml":
helpers.convert_mapping_to_xml(
- subserie, serie, plot_xml_mappings, fail_required=True)
- XML.SubElement(subserie, 'fileType').text = serie.get('format')
+ subserie, serie, plot_xml_mappings, fail_required=True
+ )
+ XML.SubElement(subserie, "fileType").text = serie.get("format")
def git(registry, xml_parent, data):
@@ -5050,59 +5126,68 @@ def git(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/git-full.yaml
:language: yaml
"""
- mappings = [('push-merge', 'pushMerge', False),
- ('push-only-if-success', 'pushOnlyIfSuccess', True),
- ('force-push', 'forcePush', False)]
-
- tag_mappings = [('remote', 'targetRepoName', 'origin'),
- ('name', 'tagName', None),
- ('message', 'tagMessage', ''),
- ('create-tag', 'createTag', False),
- ('update-tag', 'updateTag', False)]
-
- branch_mappings = [('remote', 'targetRepoName', 'origin'),
- ('name', 'branchName', None)]
-
- note_mappings = [('remote', 'targetRepoName', 'origin'),
- ('message', 'noteMsg', None),
- ('namespace', 'noteNamespace', 'master'),
- ('replace-note', 'noteReplace', False)]
-
- top = XML.SubElement(xml_parent, 'hudson.plugins.git.GitPublisher')
- XML.SubElement(top, 'configVersion').text = '2'
+ mappings = [
+ ("push-merge", "pushMerge", False),
+ ("push-only-if-success", "pushOnlyIfSuccess", True),
+ ("force-push", "forcePush", False),
+ ]
+
+ tag_mappings = [
+ ("remote", "targetRepoName", "origin"),
+ ("name", "tagName", None),
+ ("message", "tagMessage", ""),
+ ("create-tag", "createTag", False),
+ ("update-tag", "updateTag", False),
+ ]
+
+ branch_mappings = [
+ ("remote", "targetRepoName", "origin"),
+ ("name", "branchName", None),
+ ]
+
+ note_mappings = [
+ ("remote", "targetRepoName", "origin"),
+ ("message", "noteMsg", None),
+ ("namespace", "noteNamespace", "master"),
+ ("replace-note", "noteReplace", False),
+ ]
+
+ top = XML.SubElement(xml_parent, "hudson.plugins.git.GitPublisher")
+ XML.SubElement(top, "configVersion").text = "2"
helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
- tags = data.get('tags', [])
+ tags = data.get("tags", [])
if tags:
- xml_tags = XML.SubElement(top, 'tagsToPush')
+ xml_tags = XML.SubElement(top, "tagsToPush")
for tag in tags:
xml_tag = XML.SubElement(
- xml_tags,
- 'hudson.plugins.git.GitPublisher_-TagToPush')
+ xml_tags, "hudson.plugins.git.GitPublisher_-TagToPush"
+ )
helpers.convert_mapping_to_xml(
- xml_tag, tag['tag'], tag_mappings, fail_required=True)
+ xml_tag, tag["tag"], tag_mappings, fail_required=True
+ )
- branches = data.get('branches', [])
+ branches = data.get("branches", [])
if branches:
- xml_branches = XML.SubElement(top, 'branchesToPush')
+ xml_branches = XML.SubElement(top, "branchesToPush")
for branch in branches:
xml_branch = XML.SubElement(
- xml_branches,
- 'hudson.plugins.git.GitPublisher_-BranchToPush')
- helpers.convert_mapping_to_xml(xml_branch,
- branch['branch'],
- branch_mappings,
- fail_required=True)
-
- notes = data.get('notes', [])
+ xml_branches, "hudson.plugins.git.GitPublisher_-BranchToPush"
+ )
+ helpers.convert_mapping_to_xml(
+ xml_branch, branch["branch"], branch_mappings, fail_required=True
+ )
+
+ notes = data.get("notes", [])
if notes:
- xml_notes = XML.SubElement(top, 'notesToPush')
+ xml_notes = XML.SubElement(top, "notesToPush")
for note in notes:
xml_note = XML.SubElement(
- xml_notes,
- 'hudson.plugins.git.GitPublisher_-NoteToPush')
+ xml_notes, "hudson.plugins.git.GitPublisher_-NoteToPush"
+ )
helpers.convert_mapping_to_xml(
- xml_note, note['note'], note_mappings, fail_required=True)
+ xml_note, note["note"], note_mappings, fail_required=True
+ )
def github_notifier(registry, xml_parent, data):
@@ -5115,8 +5200,7 @@ def github_notifier(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/github-notifier.yaml
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'com.cloudbees.jenkins.GitHubCommitNotifier')
+ XML.SubElement(xml_parent, "com.cloudbees.jenkins.GitHubCommitNotifier")
def gitlab_notifier(registry, xml_parent, data):
@@ -5142,13 +5226,13 @@ def gitlab_notifier(registry, xml_parent, data):
:language: yaml
"""
top = XML.SubElement(
- xml_parent,
- 'com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher')
- top.set('plugin', 'gitlab-plugin')
+ xml_parent, "com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher"
+ )
+ top.set("plugin", "gitlab-plugin")
mappings = [
- ('name', 'name', 'jenkins'),
- ('mark-unstable-as-success', 'markUnstableAsSuccess', False),
+ ("name", "name", "jenkins"),
+ ("mark-unstable-as-success", "markUnstableAsSuccess", False),
]
helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
@@ -5165,8 +5249,8 @@ def gitlab_vote(registry, xml_parent, data):
:language: yaml
"""
XML.SubElement(
- xml_parent,
- 'com.dabsquared.gitlabjenkins.publisher.GitLabVotePublisher')
+ xml_parent, "com.dabsquared.gitlabjenkins.publisher.GitLabVotePublisher"
+ )
def gitlab_message(registry, xml_parent, data):
@@ -5202,20 +5286,21 @@ def gitlab_message(registry, xml_parent, data):
:language: yaml
"""
gitlab = XML.SubElement(
- xml_parent,
- 'com.dabsquared.gitlabjenkins.publisher.GitLabMessagePublisher'
+ xml_parent, "com.dabsquared.gitlabjenkins.publisher.GitLabMessagePublisher"
)
- gitlab.set('plugin', 'gitlab-plugin')
-
- mapping = [('failure-only', 'onlyForFailure', False),
- ('success-note', 'replaceSuccessNote', False),
- ('failure-note', 'replaceFailureNote', False),
- ('abort-note', 'replaceAbortNote', False),
- ('unstable-note', 'replaceUnstableNote', False),
- ('success-note-text', 'successNoteText', ''),
- ('failure-note-text', 'failureNoteText', ''),
- ('abort-note-text', 'abortNoteText', ''),
- ('unstable-note-text', 'unstableNoteText', '')]
+ gitlab.set("plugin", "gitlab-plugin")
+
+ mapping = [
+ ("failure-only", "onlyForFailure", False),
+ ("success-note", "replaceSuccessNote", False),
+ ("failure-note", "replaceFailureNote", False),
+ ("abort-note", "replaceAbortNote", False),
+ ("unstable-note", "replaceUnstableNote", False),
+ ("success-note-text", "successNoteText", ""),
+ ("failure-note-text", "failureNoteText", ""),
+ ("abort-note-text", "abortNoteText", ""),
+ ("unstable-note-text", "unstableNoteText", ""),
+ ]
helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
@@ -5230,8 +5315,7 @@ def zulip(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/zulip.yaml
:language: yaml
"""
- XML.SubElement(xml_parent,
- 'hudson.plugins.humbug.HumbugNotifier')
+ XML.SubElement(xml_parent, "hudson.plugins.humbug.HumbugNotifier")
def build_publisher(registry, xml_parent, data):
@@ -5262,27 +5346,25 @@ def build_publisher(registry, xml_parent, data):
"""
reporter = XML.SubElement(
- xml_parent,
- 'hudson.plugins.build__publisher.BuildPublisher')
+ xml_parent, "hudson.plugins.build__publisher.BuildPublisher"
+ )
mappings = [
- ('publish-unstable-builds', 'publishUnstableBuilds', True),
- ('publish-failed-builds', 'publishFailedBuilds', True)
+ ("publish-unstable-builds", "publishUnstableBuilds", True),
+ ("publish-failed-builds", "publishFailedBuilds", True),
]
- helpers.convert_mapping_to_xml(
- reporter, data, mappings, fail_required=True)
- if 'days-to-keep' in data or 'num-to-keep' in data:
- logrotator = XML.SubElement(reporter, 'logRotator')
+ helpers.convert_mapping_to_xml(reporter, data, mappings, fail_required=True)
+ if "days-to-keep" in data or "num-to-keep" in data:
+ logrotator = XML.SubElement(reporter, "logRotator")
mappings = [
- ('days-to-keep', 'daysToKeep', -1),
- ('num-to-keep', 'numToKeep', -1),
+ ("days-to-keep", "daysToKeep", -1),
+ ("num-to-keep", "numToKeep", -1),
# hardcoded to -1 to emulate what the build publisher
# plugin seem to do.
- ('', 'artifactDaysToKeep', -1),
- ('', 'artifactNumToKeep', -1)
+ ("", "artifactDaysToKeep", -1),
+ ("", "artifactNumToKeep", -1),
]
- helpers.convert_mapping_to_xml(
- logrotator, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(logrotator, data, mappings, fail_required=True)
def stash(registry, xml_parent, data):
@@ -5312,27 +5394,30 @@ def stash(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/stash-full.yaml
:language: yaml
"""
- top = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.stashNotifier.StashNotifier')
+ top = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.stashNotifier.StashNotifier"
+ )
- XML.SubElement(top, 'stashServerBaseUrl').text = data.get('url', '')
- if data.get('credentials-id') is not None:
- XML.SubElement(top, 'credentialsId').text = str(
- data.get('credentials-id'))
+ XML.SubElement(top, "stashServerBaseUrl").text = data.get("url", "")
+ if data.get("credentials-id") is not None:
+ XML.SubElement(top, "credentialsId").text = str(data.get("credentials-id"))
else:
- XML.SubElement(top, 'stashUserName'
- ).text = helpers.get_value_from_yaml_or_config_file(
- 'username', 'stash', data, registry.jjb_config)
- XML.SubElement(top, 'stashUserPassword'
- ).text = helpers.get_value_from_yaml_or_config_file(
- 'password', 'stash', data, registry.jjb_config)
+ XML.SubElement(
+ top, "stashUserName"
+ ).text = helpers.get_value_from_yaml_or_config_file(
+ "username", "stash", data, registry.jjb_config
+ )
+ XML.SubElement(
+ top, "stashUserPassword"
+ ).text = helpers.get_value_from_yaml_or_config_file(
+ "password", "stash", data, registry.jjb_config
+ )
mappings = [
- ('ignore-ssl', 'ignoreUnverifiedSSLPeer', False),
- ('commit-sha1', 'commitSha1', ''),
- ('include-build-number', 'includeBuildNumberInKey', False)
+ ("ignore-ssl", "ignoreUnverifiedSSLPeer", False),
+ ("commit-sha1", "commitSha1", ""),
+ ("include-build-number", "includeBuildNumberInKey", False),
]
- helpers.convert_mapping_to_xml(
- top, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(top, data, mappings, fail_required=True)
def dependency_check(registry, xml_parent, data):
@@ -5404,12 +5489,11 @@ def dependency_check(registry, xml_parent, data):
"""
dependency_check = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher')
+ xml_parent, "org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher"
+ )
# trends
- helpers.build_trends_publisher(
- '[DEPENDENCYCHECK] ', dependency_check, data)
+ helpers.build_trends_publisher("[DEPENDENCYCHECK] ", dependency_check, data)
def description_setter(registry, xml_parent, data):
@@ -5444,17 +5528,18 @@ def description_setter(registry, xml_parent, data):
"""
descriptionsetter = XML.SubElement(
- xml_parent,
- 'hudson.plugins.descriptionsetter.DescriptionSetterPublisher')
+ xml_parent, "hudson.plugins.descriptionsetter.DescriptionSetterPublisher"
+ )
mappings = [
- ('regexp', 'regexp', ''),
- ('regexp-for-failed', 'regexpForFailed', ''),
- ('description', 'description', None),
- ('description-for-failed', 'descriptionForFailed', None),
- ('set-for-matrix', 'setForMatrix', False)
+ ("regexp", "regexp", ""),
+ ("regexp-for-failed", "regexpForFailed", ""),
+ ("description", "description", None),
+ ("description-for-failed", "descriptionForFailed", None),
+ ("set-for-matrix", "setForMatrix", False),
]
helpers.convert_mapping_to_xml(
- descriptionsetter, data, mappings, fail_required=False)
+ descriptionsetter, data, mappings, fail_required=False
+ )
def doxygen(registry, xml_parent, data):
@@ -5483,27 +5568,25 @@ def doxygen(registry, xml_parent, data):
"""
logger = logging.getLogger(__name__)
- p = XML.SubElement(xml_parent, 'hudson.plugins.doxygen.DoxygenArchiver')
+ p = XML.SubElement(xml_parent, "hudson.plugins.doxygen.DoxygenArchiver")
mappings = [
- ('doxyfile', 'doxyfilePath', None),
- ('slave', 'runOnChild', ''),
- ('folder', 'folderWhereYouRunDoxygen', '')
+ ("doxyfile", "doxyfilePath", None),
+ ("slave", "runOnChild", ""),
+ ("folder", "folderWhereYouRunDoxygen", ""),
]
helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
# backward compatibility
- if 'keepall' in data:
- if 'keep-all' in data:
- XML.SubElement(p, 'keepAll').text = str(
- data.get('keep-all', False)).lower()
- logger.warning("The value of 'keepall' will be ignored "
- "in preference to 'keep-all'.")
+ if "keepall" in data:
+ if "keep-all" in data:
+ XML.SubElement(p, "keepAll").text = str(data.get("keep-all", False)).lower()
+ logger.warning(
+ "The value of 'keepall' will be ignored " "in preference to 'keep-all'."
+ )
else:
- XML.SubElement(p, 'keepAll').text = str(
- data.get('keepall', False)).lower()
+ XML.SubElement(p, "keepAll").text = str(data.get("keepall", False)).lower()
logger.warning("'keepall' is deprecated please use 'keep-all'")
else:
- XML.SubElement(p, 'keepAll').text = str(
- data.get('keep-all', False)).lower()
+ XML.SubElement(p, "keepAll").text = str(data.get("keep-all", False)).lower()
def docker_stop_container(registry, xml_parent, data):
@@ -5523,15 +5606,15 @@ def docker_stop_container(registry, xml_parent, data):
.. literalinclude:: /../../tests/
publishers/fixtures/docker-stop-container-full.yaml
"""
- docker_stop_container = XML.SubElement(xml_parent,
- 'com.nirima.jenkins.plugins.docker'
- '.publisher.DockerPublisherControl')
- docker_stop_container.set('plugin', 'docker-plugin')
- mapping = [
- ('remove-stopped-containers', 'remove', False),
- ]
+ docker_stop_container = XML.SubElement(
+ xml_parent,
+ "com.nirima.jenkins.plugins.docker" ".publisher.DockerPublisherControl",
+ )
+ docker_stop_container.set("plugin", "docker-plugin")
+ mapping = [("remove-stopped-containers", "remove", False)]
helpers.convert_mapping_to_xml(
- docker_stop_container, data, mapping, fail_required=False)
+ docker_stop_container, data, mapping, fail_required=False
+ )
def sitemonitor(registry, xml_parent, data):
@@ -5553,14 +5636,12 @@ def sitemonitor(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/sitemonitor-full.yaml
:language: yaml
"""
- mon = XML.SubElement(xml_parent,
- 'hudson.plugins.sitemonitor.SiteMonitorRecorder')
- if data.get('sites'):
- sites = XML.SubElement(mon, 'mSites')
- for siteurl in data.get('sites'):
- site = XML.SubElement(sites,
- 'hudson.plugins.sitemonitor.model.Site')
- XML.SubElement(site, 'mUrl').text = siteurl['url']
+ mon = XML.SubElement(xml_parent, "hudson.plugins.sitemonitor.SiteMonitorRecorder")
+ if data.get("sites"):
+ sites = XML.SubElement(mon, "mSites")
+ for siteurl in data.get("sites"):
+ site = XML.SubElement(sites, "hudson.plugins.sitemonitor.model.Site")
+ XML.SubElement(site, "mUrl").text = siteurl["url"]
def testng(registry, xml_parent, data):
@@ -5603,26 +5684,23 @@ def testng(registry, xml_parent, data):
:language: yaml
"""
- reporter = XML.SubElement(xml_parent, 'hudson.plugins.testng.Publisher')
- reporter.set('plugin', 'testng-plugin')
- threshold_modes = {
- 'number': 1,
- 'percentage': 2}
+ reporter = XML.SubElement(xml_parent, "hudson.plugins.testng.Publisher")
+ reporter.set("plugin", "testng-plugin")
+ threshold_modes = {"number": 1, "percentage": 2}
mappings = [
- ('pattern', 'reportFilenamePattern', None),
- ('escape-test-description', 'escapeTestDescp', True),
- ('escape-exception-msg', 'escapeExceptionMsg', True),
- ('fail-on-failed-test-config', 'failureOnFailedTestConfig', False),
- ('show-failed-builds', 'showFailedBuilds', False),
- ('unstable-skips', 'unstableSkips', 100),
- ('unstable-fails', 'unstableFails', 0),
- ('failed-skips', 'failedSkips', 100),
- ('failed-fails', 'failedFails', 100),
- ('threshold-mode', 'thresholdMode', 'percentage', threshold_modes)
+ ("pattern", "reportFilenamePattern", None),
+ ("escape-test-description", "escapeTestDescp", True),
+ ("escape-exception-msg", "escapeExceptionMsg", True),
+ ("fail-on-failed-test-config", "failureOnFailedTestConfig", False),
+ ("show-failed-builds", "showFailedBuilds", False),
+ ("unstable-skips", "unstableSkips", 100),
+ ("unstable-fails", "unstableFails", 0),
+ ("failed-skips", "failedSkips", 100),
+ ("failed-fails", "failedFails", 100),
+ ("threshold-mode", "thresholdMode", "percentage", threshold_modes),
]
- helpers.convert_mapping_to_xml(
- reporter, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(reporter, data, mappings, fail_required=True)
def artifact_deployer(registry, xml_parent, data):
@@ -5657,38 +5735,41 @@ def artifact_deployer(registry, xml_parent, data):
:language: yaml
"""
- deployer = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.artifactdeployer.'
- 'ArtifactDeployerPublisher')
- if data is None or 'entries' not in data:
- raise Exception('entries field is missing')
- elif data.get('entries', None) is None:
- entries = XML.SubElement(deployer, 'entries', {'class': 'empty-list'})
+ deployer = XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins.artifactdeployer." "ArtifactDeployerPublisher",
+ )
+ if data is None or "entries" not in data:
+ raise Exception("entries field is missing")
+ elif data.get("entries", None) is None:
+ entries = XML.SubElement(deployer, "entries", {"class": "empty-list"})
else:
- entries = XML.SubElement(deployer, 'entries')
- for entry in data.get('entries'):
+ entries = XML.SubElement(deployer, "entries")
+ for entry in data.get("entries"):
deployer_entry = XML.SubElement(
- entries,
- 'org.jenkinsci.plugins.artifactdeployer.ArtifactDeployerEntry')
- XML.SubElement(deployer_entry, 'includes').text = \
- entry.get('files')
- XML.SubElement(deployer_entry, 'basedir').text = \
- entry.get('basedir')
- XML.SubElement(deployer_entry, 'excludes').text = \
- entry.get('excludes')
- XML.SubElement(deployer_entry, 'remote').text = entry.get('remote')
- XML.SubElement(deployer_entry, 'flatten').text = \
- str(entry.get('flatten', False)).lower()
- XML.SubElement(deployer_entry, 'deleteRemote').text = \
- str(entry.get('delete-remote', False)).lower()
- XML.SubElement(deployer_entry, 'deleteRemoteArtifacts').text = \
- str(entry.get('delete-remote-artifacts', False)).lower()
- XML.SubElement(deployer_entry, 'failNoFilesDeploy').text = \
- str(entry.get('fail-no-files', False)).lower()
- XML.SubElement(deployer_entry, 'groovyExpression').text = \
- entry.get('groovy-script')
- deploy_if_fail = str(data.get('deploy-if-fail', False)).lower()
- XML.SubElement(deployer, 'deployEvenBuildFail').text = deploy_if_fail
+ entries, "org.jenkinsci.plugins.artifactdeployer.ArtifactDeployerEntry"
+ )
+ XML.SubElement(deployer_entry, "includes").text = entry.get("files")
+ XML.SubElement(deployer_entry, "basedir").text = entry.get("basedir")
+ XML.SubElement(deployer_entry, "excludes").text = entry.get("excludes")
+ XML.SubElement(deployer_entry, "remote").text = entry.get("remote")
+ XML.SubElement(deployer_entry, "flatten").text = str(
+ entry.get("flatten", False)
+ ).lower()
+ XML.SubElement(deployer_entry, "deleteRemote").text = str(
+ entry.get("delete-remote", False)
+ ).lower()
+ XML.SubElement(deployer_entry, "deleteRemoteArtifacts").text = str(
+ entry.get("delete-remote-artifacts", False)
+ ).lower()
+ XML.SubElement(deployer_entry, "failNoFilesDeploy").text = str(
+ entry.get("fail-no-files", False)
+ ).lower()
+ XML.SubElement(deployer_entry, "groovyExpression").text = entry.get(
+ "groovy-script"
+ )
+ deploy_if_fail = str(data.get("deploy-if-fail", False)).lower()
+ XML.SubElement(deployer, "deployEvenBuildFail").text = deploy_if_fail
def s3(registry, xml_parent, data):
@@ -5733,48 +5814,49 @@ def s3(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/s3001.yaml
:language: yaml
"""
- deployer = XML.SubElement(xml_parent,
- 'hudson.plugins.s3.S3BucketPublisher')
- if data is None or not data.get('entries'):
- raise JenkinsJobsException('No filesets defined.')
+ deployer = XML.SubElement(xml_parent, "hudson.plugins.s3.S3BucketPublisher")
+ if data is None or not data.get("entries"):
+ raise JenkinsJobsException("No filesets defined.")
- XML.SubElement(deployer, 'dontWaitForConcurrentBuildCompletion').text = (
- str(data.get('dont-wait-for-concurrent-builds', False)).lower()
- )
+ XML.SubElement(deployer, "dontWaitForConcurrentBuildCompletion").text = str(
+ data.get("dont-wait-for-concurrent-builds", False)
+ ).lower()
- XML.SubElement(deployer, 'profileName').text = data.get('s3-profile')
+ XML.SubElement(deployer, "profileName").text = data.get("s3-profile")
- entries = XML.SubElement(deployer, 'entries')
+ entries = XML.SubElement(deployer, "entries")
- for entry in data.get('entries'):
- fileset = XML.SubElement(entries, 'hudson.plugins.s3.Entry')
+ for entry in data.get("entries"):
+ fileset = XML.SubElement(entries, "hudson.plugins.s3.Entry")
# xml keys -> yaml keys
- settings = [('bucket', 'destination-bucket', ''),
- ('sourceFile', 'source-files', ''),
- ('storageClass', 'storage-class', ''),
- ('selectedRegion', 'bucket-region', ''),
- ('noUploadOnFailure', 'upload-on-failure', False),
- ('uploadFromSlave', 'upload-from-slave', False),
- ('managedArtifacts', 'managed-artifacts', False),
- ('useServerSideEncryption', 's3-encryption', False),
- ('flatten', 'flatten', False)]
+ settings = [
+ ("bucket", "destination-bucket", ""),
+ ("sourceFile", "source-files", ""),
+ ("storageClass", "storage-class", ""),
+ ("selectedRegion", "bucket-region", ""),
+ ("noUploadOnFailure", "upload-on-failure", False),
+ ("uploadFromSlave", "upload-from-slave", False),
+ ("managedArtifacts", "managed-artifacts", False),
+ ("useServerSideEncryption", "s3-encryption", False),
+ ("flatten", "flatten", False),
+ ]
for xml_key, yaml_key, default in settings:
xml_config = XML.SubElement(fileset, xml_key)
config_value = entry.get(yaml_key, default)
- if xml_key == 'noUploadOnFailure':
+ if xml_key == "noUploadOnFailure":
xml_config.text = str(not config_value).lower()
elif isinstance(default, bool):
xml_config.text = str(config_value).lower()
else:
xml_config.text = str(config_value)
- metadata = XML.SubElement(deployer, 'userMetadata')
- for tag in data.get('metadata-tags', []):
- pair = XML.SubElement(metadata, 'hudson.plugins.s3.MetadataPair')
- XML.SubElement(pair, 'key').text = tag.get('key')
- XML.SubElement(pair, 'value').text = tag.get('value')
+ metadata = XML.SubElement(deployer, "userMetadata")
+ for tag in data.get("metadata-tags", []):
+ pair = XML.SubElement(metadata, "hudson.plugins.s3.MetadataPair")
+ XML.SubElement(pair, "key").text = tag.get("key")
+ XML.SubElement(pair, "value").text = tag.get("value")
def ruby_metrics(registry, xml_parent, data):
@@ -5801,28 +5883,27 @@ def ruby_metrics(registry, xml_parent, data):
"""
metrics = XML.SubElement(
- xml_parent,
- 'hudson.plugins.rubyMetrics.rcov.RcovPublisher')
- report_dir = data.get('report-dir', '')
- XML.SubElement(metrics, 'reportDir').text = report_dir
- targets = XML.SubElement(metrics, 'targets')
- if 'target' in data:
- for t in data['target']:
- if not ('code-coverage' in t or 'total-coverage' in t):
- raise JenkinsJobsException('Unrecognized target name')
+ xml_parent, "hudson.plugins.rubyMetrics.rcov.RcovPublisher"
+ )
+ report_dir = data.get("report-dir", "")
+ XML.SubElement(metrics, "reportDir").text = report_dir
+ targets = XML.SubElement(metrics, "targets")
+ if "target" in data:
+ for t in data["target"]:
+ if not ("code-coverage" in t or "total-coverage" in t):
+ raise JenkinsJobsException("Unrecognized target name")
el = XML.SubElement(
- targets,
- 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget')
- if 'total-coverage' in t:
- XML.SubElement(el, 'metric').text = 'TOTAL_COVERAGE'
+ targets, "hudson.plugins.rubyMetrics.rcov.model.MetricTarget"
+ )
+ if "total-coverage" in t:
+ XML.SubElement(el, "metric").text = "TOTAL_COVERAGE"
else:
- XML.SubElement(el, 'metric').text = 'CODE_COVERAGE'
- for threshold_name, threshold_value in \
- next(iter(t.values())).items():
+ XML.SubElement(el, "metric").text = "CODE_COVERAGE"
+ for threshold_name, threshold_value in next(iter(t.values())).items():
elname = threshold_name.lower()
XML.SubElement(el, elname).text = str(threshold_value)
else:
- raise JenkinsJobsException('Coverage metric targets must be set')
+ raise JenkinsJobsException("Coverage metric targets must be set")
def fitnesse(registry, xml_parent, data):
@@ -5839,10 +5920,10 @@ def fitnesse(registry, xml_parent, data):
:language: yaml
"""
fitnesse = XML.SubElement(
- xml_parent,
- 'hudson.plugins.fitnesse.FitnesseResultsRecorder')
- results = data.get('results', '')
- XML.SubElement(fitnesse, 'fitnessePathToXmlResultsIn').text = results
+ xml_parent, "hudson.plugins.fitnesse.FitnesseResultsRecorder"
+ )
+ results = data.get("results", "")
+ XML.SubElement(fitnesse, "fitnessePathToXmlResultsIn").text = results
def valgrind(registry, xml_parent, data):
@@ -5879,38 +5960,38 @@ def valgrind(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/valgrind001.yaml
:language: yaml
"""
- p = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.valgrind.ValgrindPublisher')
- p = XML.SubElement(p, 'valgrindPublisherConfig')
+ p = XML.SubElement(xml_parent, "org.jenkinsci.plugins.valgrind.ValgrindPublisher")
+ p = XML.SubElement(p, "valgrindPublisherConfig")
- if 'pattern' not in data:
+ if "pattern" not in data:
raise JenkinsJobsException("A filename pattern must be specified.")
- XML.SubElement(p, 'pattern').text = data['pattern']
+ XML.SubElement(p, "pattern").text = data["pattern"]
- dthresholds = data.get('thresholds', {})
+ dthresholds = data.get("thresholds", {})
- for threshold in ['unstable', 'failed']:
+ for threshold in ["unstable", "failed"]:
dthreshold = dthresholds.get(threshold, {})
- threshold = threshold.replace('failed', 'fail')
+ threshold = threshold.replace("failed", "fail")
- ThresholdInvalidReadWrite = '%sThresholdInvalidReadWrite' % threshold
- ThresholdDefinitelyLost = '%sThresholdDefinitelyLost' % threshold
- ThresholdTotal = '%sThresholdTotal' % threshold
+ ThresholdInvalidReadWrite = "%sThresholdInvalidReadWrite" % threshold
+ ThresholdDefinitelyLost = "%sThresholdDefinitelyLost" % threshold
+ ThresholdTotal = "%sThresholdTotal" % threshold
threshold_mapping = [
- ('invalid-read-write', ThresholdInvalidReadWrite, ''),
- ('definitely-lost', ThresholdDefinitelyLost, ''),
- ('total', ThresholdTotal, ''),
+ ("invalid-read-write", ThresholdInvalidReadWrite, ""),
+ ("definitely-lost", ThresholdDefinitelyLost, ""),
+ ("total", ThresholdTotal, ""),
]
helpers.convert_mapping_to_xml(
- p, dthreshold, threshold_mapping, fail_required=True)
+ p, dthreshold, threshold_mapping, fail_required=True
+ )
mapping = [
- ('fail-no-reports', 'failBuildOnMissingReports', False),
- ('fail-invalid-reports', 'failBuildOnInvalidReports', False),
- ('publish-if-aborted', 'publishResultsForAbortedBuilds', False),
- ('publish-if-failed', 'publishResultsForFailedBuilds', False),
+ ("fail-no-reports", "failBuildOnMissingReports", False),
+ ("fail-invalid-reports", "failBuildOnInvalidReports", False),
+ ("publish-if-aborted", "publishResultsForAbortedBuilds", False),
+ ("publish-if-failed", "publishResultsForFailedBuilds", False),
]
helpers.convert_mapping_to_xml(p, data, mapping, fail_required=True)
@@ -5979,9 +6060,9 @@ def pmd(registry, xml_parent, data):
:language: yaml
"""
- xml_element = XML.SubElement(xml_parent, 'hudson.plugins.pmd.PmdPublisher')
+ xml_element = XML.SubElement(xml_parent, "hudson.plugins.pmd.PmdPublisher")
- helpers.build_trends_publisher('[PMD] ', xml_element, data)
+ helpers.build_trends_publisher("[PMD] ", xml_element, data)
def scan_build(registry, xml_parent, data):
@@ -6014,15 +6095,15 @@ def scan_build(registry, xml_parent, data):
:language: yaml
"""
p = XML.SubElement(
- xml_parent,
- 'jenkins.plugins.clangscanbuild.publisher.ClangScanBuildPublisher')
- p.set('plugin', 'clang-scanbuild')
+ xml_parent, "jenkins.plugins.clangscanbuild.publisher.ClangScanBuildPublisher"
+ )
+ p.set("plugin", "clang-scanbuild")
mappings = [
- ('mark-unstable', 'markBuildUnstableWhenThresholdIsExceeded', False),
- ('threshold', 'bugThreshold', 0),
- ('exclude-paths', 'clangexcludedpaths', ''),
- ('report-folder', 'reportFolderName', 'clangScanBuildReports'),
+ ("mark-unstable", "markBuildUnstableWhenThresholdIsExceeded", False),
+ ("threshold", "bugThreshold", 0),
+ ("exclude-paths", "clangexcludedpaths", ""),
+ ("report-folder", "reportFolderName", "clangScanBuildReports"),
]
helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
@@ -6094,16 +6175,16 @@ def dry(registry, xml_parent, data):
:language: yaml
"""
- xml_element = XML.SubElement(xml_parent, 'hudson.plugins.dry.DryPublisher')
+ xml_element = XML.SubElement(xml_parent, "hudson.plugins.dry.DryPublisher")
- helpers.build_trends_publisher('[DRY] ', xml_element, data)
+ helpers.build_trends_publisher("[DRY] ", xml_element, data)
# Add specific settings for this trends publisher
settings = [
- ('high-threshold', 'highThreshold', 50),
- ('normal-threshold', 'normalThreshold', 25)]
- helpers.convert_mapping_to_xml(
- xml_element, data, settings, fail_required=True)
+ ("high-threshold", "highThreshold", 50),
+ ("normal-threshold", "normalThreshold", 25),
+ ]
+ helpers.convert_mapping_to_xml(xml_element, data, settings, fail_required=True)
def shining_panda(registry, xml_parent, data):
@@ -6120,12 +6201,13 @@ def shining_panda(registry, xml_parent, data):
:language: yaml
"""
shining_panda_plugin = XML.SubElement(
- xml_parent,
- 'jenkins.plugins.shiningpanda.publishers.CoveragePublisher')
+ xml_parent, "jenkins.plugins.shiningpanda.publishers.CoveragePublisher"
+ )
- mapping = [('html-reports-directory', 'htmlDir', None)]
+ mapping = [("html-reports-directory", "htmlDir", None)]
helpers.convert_mapping_to_xml(
- shining_panda_plugin, data, mapping, fail_required=False)
+ shining_panda_plugin, data, mapping, fail_required=False
+ )
def downstream_ext(registry, xml_parent, data):
@@ -6158,39 +6240,39 @@ def downstream_ext(registry, xml_parent, data):
conditions = {
"equal-or-over": "AND_HIGHER",
"equal-or-under": "AND_LOWER",
- "equal": "EXACT"
+ "equal": "EXACT",
}
- p = XML.SubElement(xml_parent,
- 'hudson.plugins.downstream__ext.DownstreamTrigger')
+ p = XML.SubElement(xml_parent, "hudson.plugins.downstream__ext.DownstreamTrigger")
- if 'projects' not in data:
+ if "projects" not in data:
raise JenkinsJobsException("Missing list of downstream projects.")
- XML.SubElement(p, 'childProjects').text = ','.join(data['projects'])
+ XML.SubElement(p, "childProjects").text = ",".join(data["projects"])
- th = XML.SubElement(p, 'threshold')
+ th = XML.SubElement(p, "threshold")
- criteria = data.get('criteria', 'success').upper()
+ criteria = data.get("criteria", "success").upper()
- wr_threshold = hudson_model.THRESHOLDS[
- criteria]
+ wr_threshold = hudson_model.THRESHOLDS[criteria]
if criteria not in hudson_model.THRESHOLDS:
- raise JenkinsJobsException("criteria must be one of %s" %
- ", ".join(hudson_model.THRESHOLDS.keys()))
- mapping = [('name', 'name', None),
- ('ordinal', 'ordinal', None),
- ('color', 'color', None),
- ('complete', 'completeBuild', None)]
- helpers.convert_mapping_to_xml(th,
- wr_threshold, mapping, fail_required=True)
-
- condition_mapping = [('condition',
- 'thresholdStrategy', 'equal-or-over', conditions),
- ('only-on-scm-change', 'onlyIfSCMChanges', False),
- ('only-on-local-scm-change', 'onlyIfLocalSCMChanges', False)]
- helpers.convert_mapping_to_xml(p, data,
- condition_mapping, fail_required=True)
+ raise JenkinsJobsException(
+ "criteria must be one of %s" % ", ".join(hudson_model.THRESHOLDS.keys())
+ )
+ mapping = [
+ ("name", "name", None),
+ ("ordinal", "ordinal", None),
+ ("color", "color", None),
+ ("complete", "completeBuild", None),
+ ]
+ helpers.convert_mapping_to_xml(th, wr_threshold, mapping, fail_required=True)
+
+ condition_mapping = [
+ ("condition", "thresholdStrategy", "equal-or-over", conditions),
+ ("only-on-scm-change", "onlyIfSCMChanges", False),
+ ("only-on-local-scm-change", "onlyIfLocalSCMChanges", False),
+ ]
+ helpers.convert_mapping_to_xml(p, data, condition_mapping, fail_required=True)
def rundeck(registry, xml_parent, data):
@@ -6229,24 +6311,22 @@ def rundeck(registry, xml_parent, data):
:language: yaml
"""
- p = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.rundeck.RundeckNotifier')
+ p = XML.SubElement(xml_parent, "org.jenkinsci.plugins.rundeck.RundeckNotifier")
mappings = [
- ('job-id', 'jobId', None),
- ('options', 'options', ''),
- ('node-filters', 'nodeFilters', ''),
- ('tag', 'tag', ''),
- ('wait-for-rundeck', 'shouldWaitForRundeckJob', False),
- ('fail-the-build', 'shouldFailTheBuild', False),
+ ("job-id", "jobId", None),
+ ("options", "options", ""),
+ ("node-filters", "nodeFilters", ""),
+ ("tag", "tag", ""),
+ ("wait-for-rundeck", "shouldWaitForRundeckJob", False),
+ ("fail-the-build", "shouldFailTheBuild", False),
]
helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
def create_publishers(registry, action):
dummy_parent = XML.Element("dummy")
- registry.dispatch('publisher', dummy_parent, action)
+ registry.dispatch("publisher", dummy_parent, action)
return list(dummy_parent)
@@ -6332,125 +6412,120 @@ def conditional_publisher(registry, xml_parent, data):
<../../tests/publishers/fixtures/conditional-publisher002.yaml>`
"""
+
def publish_condition_tag(cdata, prefix, condition_tag):
- kind = cdata['%s-kind' % prefix]
+ kind = cdata["%s-kind" % prefix]
ctag = XML.SubElement(cond_publisher, condition_tag)
- class_pkg = 'org.jenkins_ci.plugins.run_condition'
+ class_pkg = "org.jenkins_ci.plugins.run_condition"
if kind == "always":
- ctag.set('class',
- class_pkg + '.core.AlwaysRun')
+ ctag.set("class", class_pkg + ".core.AlwaysRun")
elif kind == "never":
- ctag.set('class',
- class_pkg + '.core.NeverRun')
+ ctag.set("class", class_pkg + ".core.NeverRun")
elif kind == "boolean-expression":
- ctag.set('class',
- class_pkg + '.core.BooleanCondition')
- XML.SubElement(ctag,
- "token").text = cdata['%s-expression' % prefix]
+ ctag.set("class", class_pkg + ".core.BooleanCondition")
+ XML.SubElement(ctag, "token").text = cdata["%s-expression" % prefix]
elif kind == "current-status":
- ctag.set('class',
- class_pkg + '.core.StatusCondition')
- wr = XML.SubElement(ctag, 'worstResult')
- wr_name = cdata['%s-worst' % prefix]
+ ctag.set("class", class_pkg + ".core.StatusCondition")
+ wr = XML.SubElement(ctag, "worstResult")
+ wr_name = cdata["%s-worst" % prefix]
if wr_name not in hudson_model.THRESHOLDS:
raise JenkinsJobsException(
- "threshold must be one of %s" %
- ", ".join(hudson_model.THRESHOLDS.keys()))
+ "threshold must be one of %s"
+ % ", ".join(hudson_model.THRESHOLDS.keys())
+ )
wr_threshold = hudson_model.THRESHOLDS[wr_name]
- XML.SubElement(wr, "name").text = wr_threshold['name']
- XML.SubElement(wr, "ordinal").text = wr_threshold['ordinal']
- XML.SubElement(wr, "color").text = wr_threshold['color']
- XML.SubElement(wr, "completeBuild").text = \
- str(wr_threshold['complete']).lower()
-
- br = XML.SubElement(ctag, 'bestResult')
- br_name = cdata['%s-best' % prefix]
+ XML.SubElement(wr, "name").text = wr_threshold["name"]
+ XML.SubElement(wr, "ordinal").text = wr_threshold["ordinal"]
+ XML.SubElement(wr, "color").text = wr_threshold["color"]
+ XML.SubElement(wr, "completeBuild").text = str(
+ wr_threshold["complete"]
+ ).lower()
+
+ br = XML.SubElement(ctag, "bestResult")
+ br_name = cdata["%s-best" % prefix]
if br_name not in hudson_model.THRESHOLDS:
raise JenkinsJobsException(
- "threshold must be one of %s" %
- ", ".join(hudson_model.THRESHOLDS.keys()))
+ "threshold must be one of %s"
+ % ", ".join(hudson_model.THRESHOLDS.keys())
+ )
br_threshold = hudson_model.THRESHOLDS[br_name]
- XML.SubElement(br, "name").text = br_threshold['name']
- XML.SubElement(br, "ordinal").text = br_threshold['ordinal']
- XML.SubElement(br, "color").text = br_threshold['color']
- XML.SubElement(br, "completeBuild").text = \
- str(wr_threshold['complete']).lower()
+ XML.SubElement(br, "name").text = br_threshold["name"]
+ XML.SubElement(br, "ordinal").text = br_threshold["ordinal"]
+ XML.SubElement(br, "color").text = br_threshold["color"]
+ XML.SubElement(br, "completeBuild").text = str(
+ wr_threshold["complete"]
+ ).lower()
elif kind == "shell":
- ctag.set('class',
- class_pkg + '.contributed.ShellCondition')
- XML.SubElement(ctag, "command").text = cdata['%s-command' % prefix]
+ ctag.set("class", class_pkg + ".contributed.ShellCondition")
+ XML.SubElement(ctag, "command").text = cdata["%s-command" % prefix]
elif kind == "windows-shell":
- ctag.set('class',
- class_pkg + '.contributed.BatchFileCondition')
- XML.SubElement(ctag, "command").text = cdata['%s-command' % prefix]
+ ctag.set("class", class_pkg + ".contributed.BatchFileCondition")
+ XML.SubElement(ctag, "command").text = cdata["%s-command" % prefix]
elif kind == "regexp":
- ctag.set('class',
- class_pkg + '.core.ExpressionCondition')
- XML.SubElement(ctag,
- "expression").text = cdata['%s-expression' % prefix]
- XML.SubElement(ctag,
- "label").text = cdata['%s-searchtext' % prefix]
+ ctag.set("class", class_pkg + ".core.ExpressionCondition")
+ XML.SubElement(ctag, "expression").text = cdata["%s-expression" % prefix]
+ XML.SubElement(ctag, "label").text = cdata["%s-searchtext" % prefix]
elif kind == "file-exists":
- ctag.set('class',
- class_pkg + '.core.FileExistsCondition')
- XML.SubElement(ctag, "file").text = cdata['%s-filename' % prefix]
- basedir = cdata.get('%s-basedir', 'workspace')
+ ctag.set("class", class_pkg + ".core.FileExistsCondition")
+ XML.SubElement(ctag, "file").text = cdata["%s-filename" % prefix]
+ basedir = cdata.get("%s-basedir", "workspace")
basedir_tag = XML.SubElement(ctag, "baseDir")
if "workspace" == basedir:
- basedir_tag.set('class',
- class_pkg + '.common.BaseDirectory$Workspace')
+ basedir_tag.set("class", class_pkg + ".common.BaseDirectory$Workspace")
elif "artifact-directory" == basedir:
- basedir_tag.set('class',
- class_pkg + '.common.'
- 'BaseDirectory$ArtifactsDir')
+ basedir_tag.set(
+ "class", class_pkg + ".common." "BaseDirectory$ArtifactsDir"
+ )
elif "jenkins-home" == basedir:
- basedir_tag.set('class',
- class_pkg + '.common.'
- 'BaseDirectory$JenkinsHome')
+ basedir_tag.set(
+ "class", class_pkg + ".common." "BaseDirectory$JenkinsHome"
+ )
else:
- raise JenkinsJobsException('%s is not a valid %s-kind '
- 'value.' % (kind, prefix))
+ raise JenkinsJobsException(
+ "%s is not a valid %s-kind " "value." % (kind, prefix)
+ )
def publish_condition(cdata):
- return publish_condition_tag(cdata, 'condition', condition_tag)
+ return publish_condition_tag(cdata, "condition", condition_tag)
def publish_aggregation_condition(cdata):
- return publish_condition_tag(cdata, 'condition-aggregation',
- aggregation_condition_tag)
+ return publish_condition_tag(
+ cdata, "condition-aggregation", aggregation_condition_tag
+ )
def publish_action(parent, action):
for edited_node in create_publishers(registry, action):
if not use_publisher_list:
- edited_node.set('class', edited_node.tag)
- edited_node.tag = 'publisher'
+ edited_node.set("class", edited_node.tag)
+ edited_node.tag = "publisher"
parent.append(edited_node)
- flex_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
- 'FlexiblePublisher'
- cond_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
- 'ConditionalPublisher'
+ flex_publisher_tag = (
+ "org.jenkins__ci.plugins.flexible__publish." "FlexiblePublisher"
+ )
+ cond_publisher_tag = (
+ "org.jenkins__ci.plugins.flexible__publish." "ConditionalPublisher"
+ )
root_tag = XML.SubElement(xml_parent, flex_publisher_tag)
publishers_tag = XML.SubElement(root_tag, "publishers")
condition_tag = "condition"
aggregation_condition_tag = "aggregationCondition"
- evaluation_classes_pkg = 'org.jenkins_ci.plugins.run_condition'
+ evaluation_classes_pkg = "org.jenkins_ci.plugins.run_condition"
evaluation_classes = {
- 'fail': evaluation_classes_pkg + '.BuildStepRunner$Fail',
- 'mark-unstable': evaluation_classes_pkg +
- '.BuildStepRunner$Unstable',
- 'run-and-mark-unstable': evaluation_classes_pkg +
- '.BuildStepRunner$RunUnstable',
- 'run': evaluation_classes_pkg + '.BuildStepRunner$Run',
- 'dont-run': evaluation_classes_pkg + '.BuildStepRunner$DontRun',
+ "fail": evaluation_classes_pkg + ".BuildStepRunner$Fail",
+ "mark-unstable": evaluation_classes_pkg + ".BuildStepRunner$Unstable",
+ "run-and-mark-unstable": evaluation_classes_pkg
+ + ".BuildStepRunner$RunUnstable",
+ "run": evaluation_classes_pkg + ".BuildStepRunner$Run",
+ "dont-run": evaluation_classes_pkg + ".BuildStepRunner$DontRun",
}
plugin_info = registry.get_plugin_info("Flexible Publish Plugin")
# Note: Assume latest version of plugin is preferred config format
- version = pkg_resources.parse_version(
- plugin_info.get('version', str(sys.maxsize)))
+ version = pkg_resources.parse_version(plugin_info.get("version", str(sys.maxsize)))
# Support for MatrixAggregator was added in v0.11
# See JENKINS-14494
@@ -6459,24 +6534,26 @@ def conditional_publisher(registry, xml_parent, data):
for cond_action in data:
cond_publisher = XML.SubElement(publishers_tag, cond_publisher_tag)
publish_condition(cond_action)
- condition_aggregation = cond_action.get('condition-aggregation', False)
+ condition_aggregation = cond_action.get("condition-aggregation", False)
if condition_aggregation and has_matrix_aggregator:
publish_aggregation_condition(cond_action)
elif condition_aggregation:
- raise JenkinsJobsException("Matrix Aggregation is not supported "
- "in your plugin version.")
- evaluation_flag = cond_action.get('on-evaluation-failure', 'fail')
+ raise JenkinsJobsException(
+ "Matrix Aggregation is not supported " "in your plugin version."
+ )
+ evaluation_flag = cond_action.get("on-evaluation-failure", "fail")
if evaluation_flag not in evaluation_classes.keys():
- raise JenkinsJobsException('on-evaluation-failure value '
- 'specified is not valid. Must be one '
- 'of: %s' % evaluation_classes.keys())
+ raise JenkinsJobsException(
+ "on-evaluation-failure value "
+ "specified is not valid. Must be one "
+ "of: %s" % evaluation_classes.keys()
+ )
evaluation_class = evaluation_classes[evaluation_flag]
- XML.SubElement(cond_publisher, "runner").set('class',
- evaluation_class)
+ XML.SubElement(cond_publisher, "runner").set("class", evaluation_class)
- if 'action' in cond_action:
- actions = cond_action['action']
+ if "action" in cond_action:
+ actions = cond_action["action"]
action_parent = cond_publisher
@@ -6485,18 +6562,19 @@ def conditional_publisher(registry, xml_parent, data):
use_publisher_list = version >= pkg_resources.parse_version("0.13")
if use_publisher_list:
- action_parent = XML.SubElement(cond_publisher, 'publisherList')
+ action_parent = XML.SubElement(cond_publisher, "publisherList")
else:
# Check the length of actions list for versions prior to 0.13.
# Flexible Publish will overwrite action if more than one is
# specified. Limit the action list to one element.
if len(actions) != 1:
- raise JenkinsJobsException("Only one action may be "
- "specified for each condition.")
+ raise JenkinsJobsException(
+ "Only one action may be " "specified for each condition."
+ )
for action in actions:
publish_action(action_parent, action)
else:
- raise JenkinsJobsException('action must be set for each condition')
+ raise JenkinsJobsException("action must be set for each condition")
def scoverage(registry, xml_parent, data):
@@ -6515,16 +6593,15 @@ def scoverage(registry, xml_parent, data):
:language: yaml
"""
scoverage = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.scoverage.ScoveragePublisher')
- scoverage.set('plugin', 'scoverage')
+ xml_parent, "org.jenkinsci.plugins.scoverage.ScoveragePublisher"
+ )
+ scoverage.set("plugin", "scoverage")
mappings = [
- ('report-directory', 'reportDir', None),
- ('report-file', 'reportFile', None),
+ ("report-directory", "reportDir", None),
+ ("report-file", "reportFile", None),
]
- helpers.convert_mapping_to_xml(
- scoverage, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(scoverage, data, mappings, fail_required=True)
def display_upstream_changes(registry, xml_parent, data):
@@ -6540,8 +6617,8 @@ def display_upstream_changes(registry, xml_parent, data):
"""
XML.SubElement(
xml_parent,
- 'jenkins.plugins.displayupstreamchanges.'
- 'DisplayUpstreamChangesRecorder')
+ "jenkins.plugins.displayupstreamchanges." "DisplayUpstreamChangesRecorder",
+ )
def gatling(registry, xml_parent, data):
@@ -6554,9 +6631,8 @@ def gatling(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/gatling001.yaml
:language: yaml
"""
- gatling = XML.SubElement(
- xml_parent, 'io.gatling.jenkins.GatlingPublisher')
- mapping = [('', 'enabled', 'true')]
+ gatling = XML.SubElement(xml_parent, "io.gatling.jenkins.GatlingPublisher")
+ mapping = [("", "enabled", "true")]
helpers.convert_mapping_to_xml(gatling, data, mapping, fail_required=True)
@@ -6582,14 +6658,10 @@ def logstash(registry, xml_parent, data):
:language: yaml
"""
- logstash = XML.SubElement(xml_parent,
- 'jenkins.plugins.logstash.LogstashNotifier')
- logstash.set('plugin', 'logstash')
+ logstash = XML.SubElement(xml_parent, "jenkins.plugins.logstash.LogstashNotifier")
+ logstash.set("plugin", "logstash")
- mapping = [
- ('max-lines', 'maxLines', 1000),
- ('fail-build', 'failBuild', False),
- ]
+ mapping = [("max-lines", "maxLines", 1000), ("fail-build", "failBuild", False)]
helpers.convert_mapping_to_xml(logstash, data, mapping, fail_required=True)
@@ -6619,51 +6691,47 @@ def image_gallery(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/image-gallery001.yaml
"""
+
def include_comparative_elements(gallery_parent_elem, gallery):
- XML.SubElement(gallery_parent_elem, 'baseRootFolder').text = str(
- gallery.get('base-root-folder', ''))
- image_inner_width = gallery.get('image-inner-width', '')
+ XML.SubElement(gallery_parent_elem, "baseRootFolder").text = str(
+ gallery.get("base-root-folder", "")
+ )
+ image_inner_width = gallery.get("image-inner-width", "")
if image_inner_width:
- XML.SubElement(gallery_parent_elem, 'imageInnerWidth').text = str(
- image_inner_width)
+ XML.SubElement(gallery_parent_elem, "imageInnerWidth").text = str(
+ image_inner_width
+ )
- package_prefix = 'org.jenkinsci.plugins.imagegallery.'
- builder = XML.SubElement(
- xml_parent, package_prefix + 'ImageGalleryRecorder'
- )
- image_galleries = XML.SubElement(builder, 'imageGalleries')
+ package_prefix = "org.jenkinsci.plugins.imagegallery."
+ builder = XML.SubElement(xml_parent, package_prefix + "ImageGalleryRecorder")
+ image_galleries = XML.SubElement(builder, "imageGalleries")
galleries = {
- 'archived-images-gallery': package_prefix + 'imagegallery.'
- 'ArchivedImagesGallery',
- 'in-folder-comparative-gallery': package_prefix + 'comparative.'
- 'InFolderComparativeArchivedImagesGallery',
- 'multiple-folder-comparative-gallery': package_prefix + 'comparative.'
- 'MultipleFolderComparativeArchivedImagesGallery'
+ "archived-images-gallery": package_prefix + "imagegallery."
+ "ArchivedImagesGallery",
+ "in-folder-comparative-gallery": package_prefix + "comparative."
+ "InFolderComparativeArchivedImagesGallery",
+ "multiple-folder-comparative-gallery": package_prefix + "comparative."
+ "MultipleFolderComparativeArchivedImagesGallery",
}
for gallery_def in data:
- gallery_type = gallery_def.get('gallery-type',
- 'archived-images-gallery')
+ gallery_type = gallery_def.get("gallery-type", "archived-images-gallery")
if gallery_type not in galleries:
- raise InvalidAttributeError('gallery-type', gallery_type,
- galleries.keys())
- gallery_config = XML.SubElement(
- image_galleries, galleries[gallery_type])
- XML.SubElement(gallery_config, 'title').text = str(
- gallery_def.get('title', ''))
- image_width = str(gallery_def.get('image-width', ''))
+ raise InvalidAttributeError("gallery-type", gallery_type, galleries.keys())
+ gallery_config = XML.SubElement(image_galleries, galleries[gallery_type])
+ XML.SubElement(gallery_config, "title").text = str(gallery_def.get("title", ""))
+ image_width = str(gallery_def.get("image-width", ""))
if image_width:
- XML.SubElement(gallery_config, 'imageWidth').text = str(
- image_width)
+ XML.SubElement(gallery_config, "imageWidth").text = str(image_width)
XML.SubElement(
- gallery_config,
- 'markBuildAsUnstableIfNoArchivesFound').text = str(gallery_def.get(
- 'unstable-if-no-artifacts', False))
- if gallery_type == 'archived-images-gallery':
- XML.SubElement(gallery_config, 'includes').text = str(
- gallery_def.get('includes', ''))
- if gallery_type == 'in-folder-comparative-gallery':
+ gallery_config, "markBuildAsUnstableIfNoArchivesFound"
+ ).text = str(gallery_def.get("unstable-if-no-artifacts", False))
+ if gallery_type == "archived-images-gallery":
+ XML.SubElement(gallery_config, "includes").text = str(
+ gallery_def.get("includes", "")
+ )
+ if gallery_type == "in-folder-comparative-gallery":
include_comparative_elements(gallery_config, gallery_def)
- if gallery_type == 'multiple-folder-comparative-gallery':
+ if gallery_type == "multiple-folder-comparative-gallery":
include_comparative_elements(gallery_config, gallery_def)
@@ -6696,39 +6764,49 @@ def naginator(registry, xml_parent, data):
:language: yaml
"""
naginator = XML.SubElement(
- xml_parent,
- 'com.chikli.hudson.plugin.naginator.NaginatorPublisher')
- XML.SubElement(naginator, 'regexpForRerun').text = str(
- data.get('regular-expression', ''))
- XML.SubElement(naginator, 'checkRegexp').text = str(
- 'regular-expression' in data).lower()
- XML.SubElement(naginator, 'rerunIfUnstable').text = str(
- data.get('rerun-unstable-builds', False)).lower()
- XML.SubElement(naginator, 'rerunMatrixPart').text = str(
- data.get('rerun-matrix-part', False)).lower()
- progressive_delay = ('progressive-delay-increment' in data or
- 'progressive-delay-maximum' in data)
- if 'fixed-delay' in data and progressive_delay:
- raise JenkinsJobsException("You cannot specify both fixed "
- "and progressive delays")
+ xml_parent, "com.chikli.hudson.plugin.naginator.NaginatorPublisher"
+ )
+ XML.SubElement(naginator, "regexpForRerun").text = str(
+ data.get("regular-expression", "")
+ )
+ XML.SubElement(naginator, "checkRegexp").text = str(
+ "regular-expression" in data
+ ).lower()
+ XML.SubElement(naginator, "rerunIfUnstable").text = str(
+ data.get("rerun-unstable-builds", False)
+ ).lower()
+ XML.SubElement(naginator, "rerunMatrixPart").text = str(
+ data.get("rerun-matrix-part", False)
+ ).lower()
+ progressive_delay = (
+ "progressive-delay-increment" in data or "progressive-delay-maximum" in data
+ )
+ if "fixed-delay" in data and progressive_delay:
+ raise JenkinsJobsException(
+ "You cannot specify both fixed " "and progressive delays"
+ )
if not progressive_delay:
delay = XML.SubElement(
naginator,
- 'delay',
- {'class': 'com.chikli.hudson.plugin.naginator.FixedDelay'})
- XML.SubElement(delay, 'delay').text = str(
- data.get('fixed-delay', '0'))
+ "delay",
+ {"class": "com.chikli.hudson.plugin.naginator.FixedDelay"},
+ )
+ XML.SubElement(delay, "delay").text = str(data.get("fixed-delay", "0"))
else:
delay = XML.SubElement(
naginator,
- 'delay',
- {'class': 'com.chikli.hudson.plugin.naginator.ProgressiveDelay'})
- XML.SubElement(delay, 'increment').text = str(
- data.get('progressive-delay-increment', '0'))
- XML.SubElement(delay, 'max').text = str(
- data.get('progressive-delay-maximum', '0'))
- XML.SubElement(naginator, 'maxSchedule').text = str(
- data.get('max-failed-builds', '0'))
+ "delay",
+ {"class": "com.chikli.hudson.plugin.naginator.ProgressiveDelay"},
+ )
+ XML.SubElement(delay, "increment").text = str(
+ data.get("progressive-delay-increment", "0")
+ )
+ XML.SubElement(delay, "max").text = str(
+ data.get("progressive-delay-maximum", "0")
+ )
+ XML.SubElement(naginator, "maxSchedule").text = str(
+ data.get("max-failed-builds", "0")
+ )
def disable_failed_job(registry, xml_parent, data):
@@ -6755,25 +6833,24 @@ def disable_failed_job(registry, xml_parent, data):
:language: yaml
"""
- xml_element = XML.SubElement(xml_parent, 'disableFailedJob.'
- 'disableFailedJob.DisableFailedJob',
- {'plugin': 'disable-failed-job'})
+ xml_element = XML.SubElement(
+ xml_parent,
+ "disableFailedJob." "disableFailedJob.DisableFailedJob",
+ {"plugin": "disable-failed-job"},
+ )
- valid_conditions = ['Only Failure',
- 'Failure and Unstable',
- 'Only Unstable']
- mapping = [('when-to-disable', 'whenDisable', None, valid_conditions)]
- helpers.convert_mapping_to_xml(
- xml_element, data, mapping, fail_required=True)
+ valid_conditions = ["Only Failure", "Failure and Unstable", "Only Unstable"]
+ mapping = [("when-to-disable", "whenDisable", None, valid_conditions)]
+ helpers.convert_mapping_to_xml(xml_element, data, mapping, fail_required=True)
- if 'no-of-failures' in data:
+ if "no-of-failures" in data:
mapping = [
- ('no-of-failures', 'failureTimes', None),
- ('', 'optionalBrockChecked', True)]
- helpers.convert_mapping_to_xml(xml_element,
- data, mapping, fail_required=True)
+ ("no-of-failures", "failureTimes", None),
+ ("", "optionalBrockChecked", True),
+ ]
+ helpers.convert_mapping_to_xml(xml_element, data, mapping, fail_required=True)
else:
- XML.SubElement(xml_element, 'optionalBrockChecked').text = 'false'
+ XML.SubElement(xml_element, "optionalBrockChecked").text = "false"
def google_cloud_storage(registry, xml_parent, data):
@@ -6845,94 +6922,117 @@ def google_cloud_storage(registry, xml_parent, data):
def expiring_elements(properties, upload_element, types):
# Handle expiring elements upload action
- xml_element = XML.SubElement(upload_element, 'com.google.'
- 'jenkins.plugins.storage.'
- 'ExpiringBucketLifecycleManager')
+ xml_element = XML.SubElement(
+ upload_element,
+ "com.google." "jenkins.plugins.storage." "ExpiringBucketLifecycleManager",
+ )
mapping = [
- ('bucket-name', 'bucketNameWithVars', None),
- ('', 'sharedPublicly', False),
- ('', 'forFailedJobs', False),
- ('days-to-retain', 'bucketObjectTTL', None)]
+ ("bucket-name", "bucketNameWithVars", None),
+ ("", "sharedPublicly", False),
+ ("", "forFailedJobs", False),
+ ("days-to-retain", "bucketObjectTTL", None),
+ ]
helpers.convert_mapping_to_xml(
- xml_element, properties, mapping, fail_required=True)
+ xml_element, properties, mapping, fail_required=True
+ )
- if types.count('expiring-elements') > 1:
- XML.SubElement(xml_element, 'module',
- {'reference': '../../com.google.jenkins.plugins.'
- 'storage.ExpiringBucketLifecycleManager/module'})
+ if types.count("expiring-elements") > 1:
+ XML.SubElement(
+ xml_element,
+ "module",
+ {
+ "reference": "../../com.google.jenkins.plugins."
+ "storage.ExpiringBucketLifecycleManager/module"
+ },
+ )
else:
- XML.SubElement(xml_element, 'module')
+ XML.SubElement(xml_element, "module")
def build_log(properties, upload_element, types):
# Handle build log upload action
- xml_element = XML.SubElement(upload_element, 'com.google.jenkins.'
- 'plugins.storage.StdoutUpload')
+ xml_element = XML.SubElement(
+ upload_element, "com.google.jenkins." "plugins.storage.StdoutUpload"
+ )
mapping = [
- ('storage-location', 'bucketNameWithVars', None),
- ('share-publicly', 'sharedPublicly', False),
- ('upload-for-failed-jobs', 'forFailedJobs', False),
- ('show-inline', 'showInline', True),
- ('strip-prefix', 'pathPrefix', ''),
- ('log-name', 'logName', None)]
+ ("storage-location", "bucketNameWithVars", None),
+ ("share-publicly", "sharedPublicly", False),
+ ("upload-for-failed-jobs", "forFailedJobs", False),
+ ("show-inline", "showInline", True),
+ ("strip-prefix", "pathPrefix", ""),
+ ("log-name", "logName", None),
+ ]
helpers.convert_mapping_to_xml(
- xml_element, properties, mapping, fail_required=True)
+ xml_element, properties, mapping, fail_required=True
+ )
- if types.count('build-log') > 1:
- XML.SubElement(xml_element, 'module',
- {'reference': '../../com.google.jenkins.plugins.'
- 'storage.StdoutUpload/module'})
+ if types.count("build-log") > 1:
+ XML.SubElement(
+ xml_element,
+ "module",
+ {
+ "reference": "../../com.google.jenkins.plugins."
+ "storage.StdoutUpload/module"
+ },
+ )
else:
- XML.SubElement(xml_element, 'module')
+ XML.SubElement(xml_element, "module")
def classic(properties, upload_element, types):
# Handle classic upload action
- xml_element = XML.SubElement(upload_element, 'com.google.jenkins.'
- 'plugins.storage.ClassicUpload')
+ xml_element = XML.SubElement(
+ upload_element, "com.google.jenkins." "plugins.storage.ClassicUpload"
+ )
mapping = [
- ('storage-location', 'bucketNameWithVars', None),
- ('share-publicly', 'sharedPublicly', False),
- ('upload-for-failed-jobs', 'forFailedJobs', False),
- ('show-inline', 'showInline', False),
- ('strip-prefix', 'pathPrefix', ''),
- ('file-pattern', 'sourceGlobWithVars', None)]
+ ("storage-location", "bucketNameWithVars", None),
+ ("share-publicly", "sharedPublicly", False),
+ ("upload-for-failed-jobs", "forFailedJobs", False),
+ ("show-inline", "showInline", False),
+ ("strip-prefix", "pathPrefix", ""),
+ ("file-pattern", "sourceGlobWithVars", None),
+ ]
helpers.convert_mapping_to_xml(
- xml_element, properties, mapping, fail_required=True)
+ xml_element, properties, mapping, fail_required=True
+ )
- if types.count('classic') > 1:
- XML.SubElement(xml_element, 'module',
- {'reference': '../../com.google.jenkins.plugins.'
- 'storage.ClassicUpload/module'})
+ if types.count("classic") > 1:
+ XML.SubElement(
+ xml_element,
+ "module",
+ {
+ "reference": "../../com.google.jenkins.plugins."
+ "storage.ClassicUpload/module"
+ },
+ )
else:
- XML.SubElement(xml_element, 'module')
+ XML.SubElement(xml_element, "module")
- uploader = XML.SubElement(xml_parent,
- 'com.google.jenkins.plugins.storage.'
- 'GoogleCloudStorageUploader',
- {'plugin': 'google-storage-plugin'})
+ uploader = XML.SubElement(
+ xml_parent,
+ "com.google.jenkins.plugins.storage." "GoogleCloudStorageUploader",
+ {"plugin": "google-storage-plugin"},
+ )
- mapping = [('credentials-id', 'credentialsId', None)]
+ mapping = [("credentials-id", "credentialsId", None)]
helpers.convert_mapping_to_xml(uploader, data, mapping, fail_required=True)
- valid_upload_types = ['expiring-elements',
- 'build-log',
- 'classic']
+ valid_upload_types = ["expiring-elements", "build-log", "classic"]
types = []
- upload_element = XML.SubElement(uploader, 'uploads')
+ upload_element = XML.SubElement(uploader, "uploads")
- uploads = data['uploads']
+ uploads = data["uploads"]
for upload in uploads:
for upload_type, properties in upload.items():
types.append(upload_type)
if upload_type not in valid_upload_types:
- raise InvalidAttributeError('uploads', upload_type,
- valid_upload_types)
+ raise InvalidAttributeError("uploads", upload_type, valid_upload_types)
else:
- locals()[upload_type.replace('-', '_')](
- properties, upload_element, types)
+ locals()[upload_type.replace("-", "_")](
+ properties, upload_element, types
+ )
def flowdock(registry, xml_parent, data):
@@ -6971,36 +7071,38 @@ def flowdock(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/flowdock002.yaml
:language: yaml
"""
+
def gen_notification_entry(data_item, default, text):
- e = XML.SubElement(nm, 'entry')
+ e = XML.SubElement(nm, "entry")
mapping = [
- ('', 'com.flowdock.jenkins.BuildResult', text),
- (data_item, 'boolean', default)]
+ ("", "com.flowdock.jenkins.BuildResult", text),
+ (data_item, "boolean", default),
+ ]
helpers.convert_mapping_to_xml(e, data, mapping, fail_required=True)
- parent = XML.SubElement(xml_parent,
- 'com.flowdock.jenkins.FlowdockNotifier')
+ parent = XML.SubElement(xml_parent, "com.flowdock.jenkins.FlowdockNotifier")
mapping = [
- ('token', 'flowToken', None),
- ('tags', 'notificationTags', ''),
- ('chat-notification', 'chatNotification', True),
- ('notify-success', 'notifySuccess', True),
- ('notify-failure', 'notifyFailure', True),
- ('notify-fixed', 'notifyFixed', True),
- ('notify-unstable', 'notifyUnstable', False),
- ('notify-aborted', 'notifyAborted', False),
- ('notify-notbuilt', 'notifyNotBuilt', False)]
+ ("token", "flowToken", None),
+ ("tags", "notificationTags", ""),
+ ("chat-notification", "chatNotification", True),
+ ("notify-success", "notifySuccess", True),
+ ("notify-failure", "notifyFailure", True),
+ ("notify-fixed", "notifyFixed", True),
+ ("notify-unstable", "notifyUnstable", False),
+ ("notify-aborted", "notifyAborted", False),
+ ("notify-notbuilt", "notifyNotBuilt", False),
+ ]
helpers.convert_mapping_to_xml(parent, data, mapping, fail_required=True)
- nm = XML.SubElement(parent, 'notifyMap')
+ nm = XML.SubElement(parent, "notifyMap")
# notification entries
- gen_notification_entry('notify-success', True, 'SUCCESS')
- gen_notification_entry('notify-failure', True, 'FAILURE')
- gen_notification_entry('notify-fixed', True, 'FIXED')
- gen_notification_entry('notify-unstable', False, 'UNSTABLE')
- gen_notification_entry('notify-aborted', False, 'ABORTED')
- gen_notification_entry('notify-notbuilt', False, 'NOT_BUILT')
+ gen_notification_entry("notify-success", True, "SUCCESS")
+ gen_notification_entry("notify-failure", True, "FAILURE")
+ gen_notification_entry("notify-fixed", True, "FIXED")
+ gen_notification_entry("notify-unstable", False, "UNSTABLE")
+ gen_notification_entry("notify-aborted", False, "ABORTED")
+ gen_notification_entry("notify-notbuilt", False, "NOT_BUILT")
def clamav(registry, xml_parent, data):
@@ -7023,15 +7125,10 @@ def clamav(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/clamav-minimal.yaml
:language: yaml
"""
- clamav = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.clamav.ClamAvRecorder')
- clamav.set('plugin', 'clamav')
+ clamav = XML.SubElement(xml_parent, "org.jenkinsci.plugins.clamav.ClamAvRecorder")
+ clamav.set("plugin", "clamav")
- mappings = [
- ('includes', 'includes', ''),
- ('excludes', 'excludes', ''),
- ]
+ mappings = [("includes", "includes", ""), ("excludes", "excludes", "")]
helpers.convert_mapping_to_xml(clamav, data, mappings, fail_required=True)
@@ -7065,21 +7162,21 @@ def testselector(registry, xml_parent, data):
:language: yaml
"""
- testselector = XML.SubElement(xml_parent, 'il.ac.technion.jenkins.plugins'
- 'TestExecuter')
+ testselector = XML.SubElement(
+ xml_parent, "il.ac.technion.jenkins.plugins" "TestExecuter"
+ )
mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ('properties-file', 'propertiesFilePath', None),
- ('enable-field', 'enableField', ''),
- ('groupby', 'groupBy', ''),
- ('field-separator', 'fieldSeparator', ''),
- ('show-fields', 'showFields', ''),
- ('multiplicity-field', 'multiplicityField', ''),
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("properties-file", "propertiesFilePath", None),
+ ("enable-field", "enableField", ""),
+ ("groupby", "groupBy", ""),
+ ("field-separator", "fieldSeparator", ""),
+ ("show-fields", "showFields", ""),
+ ("multiplicity-field", "multiplicityField", ""),
]
- helpers.convert_mapping_to_xml(
- testselector, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(testselector, data, mapping, fail_required=True)
def cloudformation(registry, xml_parent, data):
@@ -7145,16 +7242,19 @@ def cloudformation(registry, xml_parent, data):
"""
region_dict = helpers.cloudformation_region_dict()
stacks = helpers.cloudformation_init(
- xml_parent, data, 'CloudFormationPostBuildNotifier')
- for stack in data.get('create-stacks', []):
- helpers.cloudformation_stack(xml_parent, stack, 'PostBuildStackBean',
- stacks, region_dict)
+ xml_parent, data, "CloudFormationPostBuildNotifier"
+ )
+ for stack in data.get("create-stacks", []):
+ helpers.cloudformation_stack(
+ xml_parent, stack, "PostBuildStackBean", stacks, region_dict
+ )
delete_stacks = helpers.cloudformation_init(
- xml_parent, data, 'CloudFormationNotifier')
- for delete_stack in data.get('delete-stacks', []):
- helpers.cloudformation_stack(xml_parent, delete_stack,
- 'SimpleStackBean', delete_stacks,
- region_dict)
+ xml_parent, data, "CloudFormationNotifier"
+ )
+ for delete_stack in data.get("delete-stacks", []):
+ helpers.cloudformation_stack(
+ xml_parent, delete_stack, "SimpleStackBean", delete_stacks, region_dict
+ )
def whitesource(registry, xml_parent, data):
@@ -7188,27 +7288,25 @@ def whitesource(registry, xml_parent, data):
/../../tests/publishers/fixtures/whitesource-minimal.yaml
:language: yaml
"""
- whitesource = XML.SubElement(xml_parent, 'org.whitesource.jenkins.'
- 'WhiteSourcePublisher')
- whitesource.set('plugin', 'whitesource')
- policies = ['global', 'enable', 'disable']
+ whitesource = XML.SubElement(
+ xml_parent, "org.whitesource.jenkins." "WhiteSourcePublisher"
+ )
+ whitesource.set("plugin", "whitesource")
+ policies = ["global", "enable", "disable"]
mappings = [
- ('policies', 'jobCheckPolicies', 'global', policies),
- ('override-token', 'jobApiToken', ''),
- ('product-token', 'product', ''),
- ('version', 'productVersion', ''),
- ('project-token', 'projectToken', ''),
- ('requester-email', 'requesterEmail', ''),
+ ("policies", "jobCheckPolicies", "global", policies),
+ ("override-token", "jobApiToken", ""),
+ ("product-token", "product", ""),
+ ("version", "productVersion", ""),
+ ("project-token", "projectToken", ""),
+ ("requester-email", "requesterEmail", ""),
]
- helpers.convert_mapping_to_xml(
- whitesource, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(whitesource, data, mappings, fail_required=True)
- XML.SubElement(whitesource, 'libIncludes').text = ' '.join(
- data.get('includes', []))
- XML.SubElement(whitesource, 'libExcludes').text = ' '.join(
- data.get('excludes', []))
- XML.SubElement(whitesource, 'ignorePomModules').text = 'false'
+ XML.SubElement(whitesource, "libIncludes").text = " ".join(data.get("includes", []))
+ XML.SubElement(whitesource, "libExcludes").text = " ".join(data.get("excludes", []))
+ XML.SubElement(whitesource, "ignorePomModules").text = "false"
def hipchat(registry, xml_parent, data):
@@ -7248,26 +7346,22 @@ def hipchat(registry, xml_parent, data):
.. literalinclude:: /../../tests/publishers/fixtures/hipchat001.yaml
:language: yaml
"""
- hipchat = XML.SubElement(
- xml_parent,
- 'jenkins.plugins.hipchat.HipChatNotifier')
- XML.SubElement(hipchat, 'token').text = str(
- data.get('token', ''))
+ hipchat = XML.SubElement(xml_parent, "jenkins.plugins.hipchat.HipChatNotifier")
+ XML.SubElement(hipchat, "token").text = str(data.get("token", ""))
- if 'rooms' in data:
- XML.SubElement(hipchat, 'room').text = str(
- ",".join(data['rooms']))
+ if "rooms" in data:
+ XML.SubElement(hipchat, "room").text = str(",".join(data["rooms"]))
mapping = [
- ('notify-start', 'startNotification', False),
- ('notify-success', 'notifySuccess', False),
- ('notify-aborted', 'notifyAborted', False),
- ('notify-not-built', 'notifyNotBuilt', False),
- ('notify-unstable', 'notifyUnstable', False),
- ('notify-failure', 'notifyFailure', False),
- ('notify-back-to-normal', 'notifyBackToNormal', False),
- ('start-message', 'startJobMessage', None),
- ('complete-message', 'completeJobMessage', None),
+ ("notify-start", "startNotification", False),
+ ("notify-success", "notifySuccess", False),
+ ("notify-aborted", "notifyAborted", False),
+ ("notify-not-built", "notifyNotBuilt", False),
+ ("notify-unstable", "notifyUnstable", False),
+ ("notify-failure", "notifyFailure", False),
+ ("notify-back-to-normal", "notifyBackToNormal", False),
+ ("start-message", "startJobMessage", None),
+ ("complete-message", "completeJobMessage", None),
]
helpers.convert_mapping_to_xml(hipchat, data, mapping, fail_required=False)
@@ -7356,51 +7450,50 @@ def slack(registry, xml_parent, data):
:language: yaml
"""
- def _add_xml(elem, name, value=''):
+
+ def _add_xml(elem, name, value=""):
if isinstance(value, bool):
value = str(value).lower()
XML.SubElement(elem, name).text = value
logger = logging.getLogger(__name__)
- plugin_info = registry.get_plugin_info('Slack Notification Plugin')
+ plugin_info = registry.get_plugin_info("Slack Notification Plugin")
# Note: Assume latest version of plugin is preferred config format
plugin_ver = pkg_resources.parse_version(
- plugin_info.get('version', str(sys.maxsize)))
+ plugin_info.get("version", str(sys.maxsize))
+ )
mapping = (
- ('team-domain', 'teamDomain', ''),
- ('auth-token', 'authToken', ''),
- ('auth-token-id', 'authTokenCredentialId', ''),
- ('build-server-url', 'buildServerUrl', '/'),
- ('room', 'room', ''),
+ ("team-domain", "teamDomain", ""),
+ ("auth-token", "authToken", ""),
+ ("auth-token-id", "authTokenCredentialId", ""),
+ ("build-server-url", "buildServerUrl", "/"),
+ ("room", "room", ""),
)
mapping_20 = (
- ('notify-start', 'startNotification', False),
- ('notify-success', 'notifySuccess', False),
- ('notify-aborted', 'notifyAborted', False),
- ('notify-not-built', 'notifyNotBuilt', False),
- ('notify-unstable', 'notifyUnstable', False),
- ('notify-failure', 'notifyFailure', False),
- ('notify-back-to-normal', 'notifyBackToNormal', False),
- ('notify-regression', 'notifyRegression', False),
- ('notify-repeated-failure', 'notifyRepeatedFailure', False),
- ('include-test-summary', 'includeTestSummary', False),
- ('include-failed-tests', 'includeFailedTests', False),
- ('commit-info-choice', 'commitInfoChoice', 'NONE'),
- ('include-custom-message', 'includeCustomMessage', False),
- ('custom-message', 'customMessage', ''),
- ('auth-token-credential-id', 'authTokenCredentialId', ''),
- ('bot-user', 'botUser', False),
- ('base-url', 'baseUrl', ''),
+ ("notify-start", "startNotification", False),
+ ("notify-success", "notifySuccess", False),
+ ("notify-aborted", "notifyAborted", False),
+ ("notify-not-built", "notifyNotBuilt", False),
+ ("notify-unstable", "notifyUnstable", False),
+ ("notify-failure", "notifyFailure", False),
+ ("notify-back-to-normal", "notifyBackToNormal", False),
+ ("notify-regression", "notifyRegression", False),
+ ("notify-repeated-failure", "notifyRepeatedFailure", False),
+ ("include-test-summary", "includeTestSummary", False),
+ ("include-failed-tests", "includeFailedTests", False),
+ ("commit-info-choice", "commitInfoChoice", "NONE"),
+ ("include-custom-message", "includeCustomMessage", False),
+ ("custom-message", "customMessage", ""),
+ ("auth-token-credential-id", "authTokenCredentialId", ""),
+ ("bot-user", "botUser", False),
+ ("base-url", "baseUrl", ""),
)
- commit_info_choices = ['NONE', 'AUTHORS', 'AUTHORS_AND_TITLES']
+ commit_info_choices = ["NONE", "AUTHORS", "AUTHORS_AND_TITLES"]
- slack = XML.SubElement(
- xml_parent,
- 'jenkins.plugins.slack.SlackNotifier',
- )
+ slack = XML.SubElement(xml_parent, "jenkins.plugins.slack.SlackNotifier")
if plugin_ver >= pkg_resources.parse_version("2.0"):
mapping = mapping + mapping_20
@@ -7415,28 +7508,24 @@ def slack(registry, xml_parent, data):
for yaml_name, _, _ in mapping_20:
if yaml_name in data:
logger.warning(
- "'%s' is invalid with plugin version < 2.0, ignored",
- yaml_name,
+ "'%s' is invalid with plugin version < 2.0, ignored", yaml_name
)
for yaml_name, xml_name, default_value in mapping:
value = data.get(yaml_name, default_value)
# 'commit-info-choice' is enumerated type
- if (
- yaml_name == 'commit-info-choice' and
- value not in commit_info_choices):
- raise InvalidAttributeError(
- yaml_name, value, commit_info_choices,
- )
+ if yaml_name == "commit-info-choice" and value not in commit_info_choices:
+ raise InvalidAttributeError(yaml_name, value, commit_info_choices)
# Ensure that custom-message is set when include-custom-message is set
# to true.
if (
- yaml_name == 'include-custom-message' and
- data is False and
- not data.get('custom-message', '')):
- raise MissingAttributeError('custom-message')
+ yaml_name == "include-custom-message"
+ and data is False
+ and not data.get("custom-message", "")
+ ):
+ raise MissingAttributeError("custom-message")
_add_xml(slack, xml_name, value)
@@ -7464,15 +7553,19 @@ def phabricator(registry, xml_parent, data):
:language: yaml
"""
- root = XML.SubElement(xml_parent,
- 'com.uber.jenkins.phabricator.PhabricatorNotifier')
+ root = XML.SubElement(
+ xml_parent, "com.uber.jenkins.phabricator.PhabricatorNotifier"
+ )
mapping = [
- ('comment-on-success', 'commentOnSuccess', None),
- ('uberalls-enabled', 'uberallsEnabled', None),
- ('comment-file', 'commentFile', None),
- ('comment-size', 'commentSize', None),
- ('comment-with-console-link-on-failure',
- 'commentWithConsoleLinkOnFailure', None),
+ ("comment-on-success", "commentOnSuccess", None),
+ ("uberalls-enabled", "uberallsEnabled", None),
+ ("comment-file", "commentFile", None),
+ ("comment-size", "commentSize", None),
+ (
+ "comment-with-console-link-on-failure",
+ "commentWithConsoleLinkOnFailure",
+ None,
+ ),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
@@ -7517,8 +7610,9 @@ def jms_messaging(registry, xml_parent, data):
../../tests/publishers/fixtures/jms-messaging-minimal.yaml
:language: yaml
"""
- helpers.jms_messaging_common(xml_parent, 'com.redhat.jenkins.plugins.ci.'
- 'CIMessageNotifier', data)
+ helpers.jms_messaging_common(
+ xml_parent, "com.redhat.jenkins.plugins.ci." "CIMessageNotifier", data
+ )
def openshift_build_canceller(registry, xml_parent, data):
@@ -7558,16 +7652,16 @@ def openshift_build_canceller(registry, xml_parent, data):
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftBuildCanceller')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftBuildCanceller"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("bld-cfg", 'bldCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("bld-cfg", "bldCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -7606,16 +7700,16 @@ def openshift_deploy_canceller(registry, xml_parent, data):
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftDeployCanceller')
+ osb = XML.SubElement(
+ xml_parent, "com.openshift.jenkins.plugins.pipeline." "OpenShiftDeployCanceller"
+ )
mapping = [
# option, xml name, default value
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("dep-cfg", 'depCfg', 'frontend'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("dep-cfg", "depCfg", "frontend"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -7652,15 +7746,16 @@ def github_pull_request_merge(registry, xml_parent, data):
:language: yaml
"""
- osb = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.ghprb.GhprbPullRequestMerge')
+ osb = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.ghprb.GhprbPullRequestMerge"
+ )
mapping = [
# option, xml name, default value
- ("only-admins-merge", 'onlyAdminsMerge', 'false'),
- ("disallow-own-code", 'disallowOwnCode', 'false'),
- ("merge-comment", 'mergeComment', ''),
- ("fail-on-non-merge", 'failOnNonMerge', 'false'),
- ("delete-on-merge", 'deleteOnMerge', 'false'),
+ ("only-admins-merge", "onlyAdminsMerge", "false"),
+ ("disallow-own-code", "disallowOwnCode", "false"),
+ ("merge-comment", "mergeComment", ""),
+ ("fail-on-non-merge", "failOnNonMerge", "false"),
+ ("delete-on-merge", "deleteOnMerge", "false"),
]
helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True)
@@ -7679,8 +7774,9 @@ def chuck_norris(registry, xml_parent, data):
:language: yaml
"""
- chuck = XML.SubElement(xml_parent,
- 'hudson.plugins.chucknorris.CordellWalkerRecorder')
+ chuck = XML.SubElement(
+ xml_parent, "hudson.plugins.chucknorris.CordellWalkerRecorder"
+ )
return XML.SubElement(chuck, "factGenerator")
@@ -7697,9 +7793,8 @@ def publishers_from(registry, xml_parent, data):
.. literalinclude:: ../../tests/publishers/fixtures/publishers-from.yaml
:language: yaml
"""
- pbs = XML.SubElement(xml_parent,
- 'hudson.plugins.templateproject.ProxyPublisher')
- mapping = [('project-name', 'projectName', None)]
+ pbs = XML.SubElement(xml_parent, "hudson.plugins.templateproject.ProxyPublisher")
+ mapping = [("project-name", "projectName", None)]
helpers.convert_mapping_to_xml(pbs, data, mapping, fail_required=True)
@@ -7843,71 +7938,70 @@ def tasks(registry, xml_parent, data):
:language: yaml
"""
- root = XML.SubElement(xml_parent,
- 'hudson.plugins.tasks.TasksPublisher')
- root.set('plugin', 'tasks')
+ root = XML.SubElement(xml_parent, "hudson.plugins.tasks.TasksPublisher")
+ root.set("plugin", "tasks")
- if 'files-to-scan' in data:
- XML.SubElement(root, 'pattern').text = str(
- ",".join(data['files-to-scan']))
+ if "files-to-scan" in data:
+ XML.SubElement(root, "pattern").text = str(",".join(data["files-to-scan"]))
- if 'files-to-exclude' in data:
- XML.SubElement(root, 'excludePattern').text = str(
- ",".join(data['files-to-exclude']))
+ if "files-to-exclude" in data:
+ XML.SubElement(root, "excludePattern").text = str(
+ ",".join(data["files-to-exclude"])
+ )
- for prio in ['high', 'normal', 'low']:
- if 'tasks-tags-' + prio in data:
- XML.SubElement(root, prio).text = str(
- ",".join(data['tasks-tags-' + prio]))
+ for prio in ["high", "normal", "low"]:
+ if "tasks-tags-" + prio in data:
+ XML.SubElement(root, prio).text = str(",".join(data["tasks-tags-" + prio]))
# on the UI, we can see compute-new-warnings but we need the opposite (XML)
- if 'compute-new-warnings' in data and data['compute-new-warnings']:
- XML.SubElement(root, 'dontComputeNew').text = "false"
+ if "compute-new-warnings" in data and data["compute-new-warnings"]:
+ XML.SubElement(root, "dontComputeNew").text = "false"
else:
- XML.SubElement(root, 'dontComputeNew').text = "true"
+ XML.SubElement(root, "dontComputeNew").text = "true"
# Two parameters we cannot modify from the UI
- XML.SubElement(root, 'pluginName').text = "[TASKS] "
- XML.SubElement(root, 'doNotResolveRelativePaths').text = "false"
+ XML.SubElement(root, "pluginName").text = "[TASKS] "
+ XML.SubElement(root, "doNotResolveRelativePaths").text = "false"
mappings = [
- ('ignore-case', 'ignoreCase', False),
- ('regular-expression', 'asRegexp', False),
- ('run-always', 'canRunOnFailed', False),
- ('detect-module', 'shouldDetectModules', False),
- ('health-thresholds-100', 'healthy', ''),
- ('health-thresholds-0', 'unHealthy', ''),
- ('health-priorities', 'thresholdLimit', 'low'),
- ('use-delta', 'useDeltaValues', False),
- ('use-prev-build-as-ref', 'usePreviousBuildAsReference', False),
- ('only-use-stable-as-ref', 'useStableBuildAsReference', False),
- ('default-encoding', 'defaultEncoding', '')
+ ("ignore-case", "ignoreCase", False),
+ ("regular-expression", "asRegexp", False),
+ ("run-always", "canRunOnFailed", False),
+ ("detect-module", "shouldDetectModules", False),
+ ("health-thresholds-100", "healthy", ""),
+ ("health-thresholds-0", "unHealthy", ""),
+ ("health-priorities", "thresholdLimit", "low"),
+ ("use-delta", "useDeltaValues", False),
+ ("use-prev-build-as-ref", "usePreviousBuildAsReference", False),
+ ("only-use-stable-as-ref", "useStableBuildAsReference", False),
+ ("default-encoding", "defaultEncoding", ""),
]
helpers.convert_mapping_to_xml(root, data, mappings, fail_required=True)
- thrsh_xml = XML.SubElement(root, 'thresholds')
- thrsh_xml.set('plugin', 'analysis-core')
- thrsh_data = data.get('status-thresholds', {})
+ thrsh_xml = XML.SubElement(root, "thresholds")
+ thrsh_xml.set("plugin", "analysis-core")
+ thrsh_data = data.get("status-thresholds", {})
thrsh_mappings = [
- ('unstable-total-all', 'unstableTotalAll', ''),
- ('unstable-total-high', 'unstableTotalHigh', ''),
- ('unstable-total-normal', 'unstableTotalNormal', ''),
- ('unstable-total-low', 'unstableTotalLow', ''),
- ('unstable-new-all', 'unstableNewAll', ''),
- ('unstable-new-high', 'unstableNewHigh', ''),
- ('unstable-new-normal', 'unstableNewNormal', ''),
- ('unstable-new-low', 'unstableNewLow', ''),
- ('failed-total-all', 'failedTotalAll', ''),
- ('failed-total-high', 'failedTotalHigh', ''),
- ('failed-total-normal', 'failedTotalNormal', ''),
- ('failed-total-low', 'failedTotalLow', ''),
- ('failed-new-all', 'failedNewAll', ''),
- ('failed-new-high', 'failedNewHigh', ''),
- ('failed-new-normal', 'failedNewNormal', ''),
- ('failed-new-low', 'failedNewLow', '')
+ ("unstable-total-all", "unstableTotalAll", ""),
+ ("unstable-total-high", "unstableTotalHigh", ""),
+ ("unstable-total-normal", "unstableTotalNormal", ""),
+ ("unstable-total-low", "unstableTotalLow", ""),
+ ("unstable-new-all", "unstableNewAll", ""),
+ ("unstable-new-high", "unstableNewHigh", ""),
+ ("unstable-new-normal", "unstableNewNormal", ""),
+ ("unstable-new-low", "unstableNewLow", ""),
+ ("failed-total-all", "failedTotalAll", ""),
+ ("failed-total-high", "failedTotalHigh", ""),
+ ("failed-total-normal", "failedTotalNormal", ""),
+ ("failed-total-low", "failedTotalLow", ""),
+ ("failed-new-all", "failedNewAll", ""),
+ ("failed-new-high", "failedNewHigh", ""),
+ ("failed-new-normal", "failedNewNormal", ""),
+ ("failed-new-low", "failedNewLow", ""),
]
helpers.convert_mapping_to_xml(
- thrsh_xml, thrsh_data, thrsh_mappings, fail_required=True)
+ thrsh_xml, thrsh_data, thrsh_mappings, fail_required=True
+ )
def packer(registry, xml_parent, data):
@@ -7949,45 +8043,48 @@ def packer(registry, xml_parent, data):
:language: yaml
"""
- root = XML.SubElement(xml_parent,
- 'biz.neustar.jenkins.plugins.packer.PackerPublisher')
+ root = XML.SubElement(
+ xml_parent, "biz.neustar.jenkins.plugins.packer.PackerPublisher"
+ )
- template_valid_types = ['global', 'file', 'text']
+ template_valid_types = ["global", "file", "text"]
mapping = [
- ('name', 'name', None),
- ('json-template', 'jsonTemplate', ''),
- ('json-template-text', 'jsonTemplateText', ''),
- ('add-params', 'params', ''),
- ('use-debug', 'useDebug', False),
- ('change-dir', 'changeDir', ''),
- ('template-mode', 'templateMode', 'global', template_valid_types),
+ ("name", "name", None),
+ ("json-template", "jsonTemplate", ""),
+ ("json-template-text", "jsonTemplateText", ""),
+ ("add-params", "params", ""),
+ ("use-debug", "useDebug", False),
+ ("change-dir", "changeDir", ""),
+ ("template-mode", "templateMode", "global", template_valid_types),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
format_dict = {
- 'packer-file-entry':
- 'biz.neustar.jenkins.plugins.packer.PackerFileEntry'
+ "packer-file-entry": "biz.neustar.jenkins.plugins.packer.PackerFileEntry"
}
- if 'file-entries' in data:
- file_entries_tag = XML.SubElement(root, 'fileEntries')
- for file_entries in data['file-entries']:
+ if "file-entries" in data:
+ file_entries_tag = XML.SubElement(root, "fileEntries")
+ for file_entries in data["file-entries"]:
for file, params in file_entries.items():
- packer_file_entry_tag = XML.SubElement(file_entries_tag,
- format_dict.get('packer-file-entry'))
- XML.SubElement(packer_file_entry_tag,
- 'varFileName').text = params.get('variable-name', '')
- XML.SubElement(packer_file_entry_tag,
- 'contents').text = params.get('contents', '')
+ packer_file_entry_tag = XML.SubElement(
+ file_entries_tag, format_dict.get("packer-file-entry")
+ )
+ XML.SubElement(packer_file_entry_tag, "varFileName").text = params.get(
+ "variable-name", ""
+ )
+ XML.SubElement(packer_file_entry_tag, "contents").text = params.get(
+ "contents", ""
+ )
class Publishers(jenkins_jobs.modules.base.Base):
sequence = 70
- component_type = 'publisher'
- component_list_type = 'publishers'
+ component_type = "publisher"
+ component_list_type = "publishers"
def gen_xml(self, xml_parent, data):
- publishers = XML.SubElement(xml_parent, 'publishers')
+ publishers = XML.SubElement(xml_parent, "publishers")
- for action in data.get('publishers', []):
- self.registry.dispatch('publisher', publishers, action)
+ for action in data.get("publishers", []):
+ self.registry.dispatch("publisher", publishers, action)
diff --git a/jenkins_jobs/modules/reporters.py b/jenkins_jobs/modules/reporters.py
index 0156792b..5fd5641e 100644
--- a/jenkins_jobs/modules/reporters.py
+++ b/jenkins_jobs/modules/reporters.py
@@ -57,21 +57,19 @@ def email(registry, xml_parent, data):
recipients: breakage@example.com
"""
- mailer = XML.SubElement(xml_parent,
- 'hudson.maven.reporters.MavenMailer')
- XML.SubElement(mailer, 'recipients').text = data['recipients']
+ mailer = XML.SubElement(xml_parent, "hudson.maven.reporters.MavenMailer")
+ XML.SubElement(mailer, "recipients").text = data["recipients"]
# Note the logic reversal (included here to match the GUI
- if data.get('notify-every-unstable-build', True):
- XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false'
+ if data.get("notify-every-unstable-build", True):
+ XML.SubElement(mailer, "dontNotifyEveryUnstableBuild").text = "false"
else:
- XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true'
+ XML.SubElement(mailer, "dontNotifyEveryUnstableBuild").text = "true"
mapping = [
- ('send-to-individuals', 'sendToIndividuals', False),
- ('notify-for-each-module', 'perModuleEmail', True),
+ ("send-to-individuals", "sendToIndividuals", False),
+ ("notify-for-each-module", "perModuleEmail", True),
]
- helpers.convert_mapping_to_xml(
- mailer, data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(mailer, data, mapping, fail_required=False)
def findbugs(registry, xml_parent, data):
@@ -131,29 +129,29 @@ def findbugs(registry, xml_parent, data):
.. literalinclude:: /../../tests/reporters/fixtures/findbugs01.yaml
"""
- findbugs = XML.SubElement(xml_parent,
- 'hudson.plugins.findbugs.FindBugsReporter')
- findbugs.set('plugin', 'findbugs')
+ findbugs = XML.SubElement(xml_parent, "hudson.plugins.findbugs.FindBugsReporter")
+ findbugs.set("plugin", "findbugs")
helpers.findbugs_settings(findbugs, data)
- helpers.build_trends_publisher('[FINDBUGS] ', findbugs, data)
+ helpers.build_trends_publisher("[FINDBUGS] ", findbugs, data)
class Reporters(jenkins_jobs.modules.base.Base):
sequence = 55
- component_type = 'reporter'
- component_list_type = 'reporters'
+ component_type = "reporter"
+ component_list_type = "reporters"
def gen_xml(self, xml_parent, data):
- if 'reporters' not in data:
+ if "reporters" not in data:
return
- if xml_parent.tag != 'maven2-moduleset':
- raise JenkinsJobsException("Reporters may only be used for Maven "
- "modules.")
+ if xml_parent.tag != "maven2-moduleset":
+ raise JenkinsJobsException(
+ "Reporters may only be used for Maven " "modules."
+ )
- reporters = XML.SubElement(xml_parent, 'reporters')
+ reporters = XML.SubElement(xml_parent, "reporters")
- for action in data.get('reporters', []):
- self.registry.dispatch('reporter', reporters, action)
+ for action in data.get("reporters", []):
+ self.registry.dispatch("reporter", reporters, action)
diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py
index baa4f94c..6e7e6291 100644
--- a/jenkins_jobs/modules/scm.py
+++ b/jenkins_jobs/modules/scm.py
@@ -50,11 +50,13 @@ def p4(registry, xml_parent, data):
Specifies the Perforce (P4) repository for this job
Requires the Jenkins :jenkins-wiki:`P4 Plugin <P4+Plugin>`.
"""
- scm = XML.SubElement(xml_parent, 'scm',
- {'class': 'org.jenkinsci.plugins.p4.PerforceScm',
- 'plugin': 'p4'})
+ scm = XML.SubElement(
+ xml_parent,
+ "scm",
+ {"class": "org.jenkinsci.plugins.p4.PerforceScm", "plugin": "p4"},
+ )
- XML.SubElement(scm, 'credential').text = data.get('credential')
+ XML.SubElement(scm, "credential").text = data.get("credential")
p4_construct_workspace(scm, data)
@@ -65,93 +67,105 @@ def p4_construct_workspace(xml_parent, data):
workspace = None
workspace_mapping = [
- ('workspace-charset', 'charset', 'none'),
- ('workspace-pin-host', 'pinHost', False),
- ('workspace-name', 'name', ''),
- ('workspace-cleanup', 'cleanup', None)
+ ("workspace-charset", "charset", "none"),
+ ("workspace-pin-host", "pinHost", False),
+ ("workspace-name", "name", ""),
+ ("workspace-cleanup", "cleanup", None),
]
- if data.get('workspace-type') == 'Static':
- workspace = XML.SubElement(xml_parent, 'workspace',
- {'class':
- 'org.jenkinsci.plugins.p4.workspace.StaticWorkspaceImpl'})
- elif data.get('workspace-type') == 'Manual':
- workspace = XML.SubElement(xml_parent, 'workspace',
- {'class':
- 'org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl'})
-
- spec = XML.SubElement(workspace, 'spec')
+ if data.get("workspace-type") == "Static":
+ workspace = XML.SubElement(
+ xml_parent,
+ "workspace",
+ {"class": "org.jenkinsci.plugins.p4.workspace.StaticWorkspaceImpl"},
+ )
+ elif data.get("workspace-type") == "Manual":
+ workspace = XML.SubElement(
+ xml_parent,
+ "workspace",
+ {"class": "org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl"},
+ )
+
+ spec = XML.SubElement(workspace, "spec")
spec_mapping = [
- ('spec-allwrite', 'allwrite', False),
- ('spec-clobber', 'clobber', False),
- ('spec-compress', 'compress', False),
- ('spec-locked', 'locked', False),
- ('spec-modtime', 'modtime', False),
- ('spec-rmdir', 'rmdir', False),
- ('spec-line', 'line', ''),
- ('spec-view', 'view', ''),
- ('spec-type', 'type', ''),
- ('spec-backup', 'backup', False),
- ('spec-stream-name', 'streamName', '')
+ ("spec-allwrite", "allwrite", False),
+ ("spec-clobber", "clobber", False),
+ ("spec-compress", "compress", False),
+ ("spec-locked", "locked", False),
+ ("spec-modtime", "modtime", False),
+ ("spec-rmdir", "rmdir", False),
+ ("spec-line", "line", ""),
+ ("spec-view", "view", ""),
+ ("spec-type", "type", ""),
+ ("spec-backup", "backup", False),
+ ("spec-stream-name", "streamName", ""),
]
- helpers.convert_mapping_to_xml(
- spec, data, spec_mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(spec, data, spec_mapping, fail_required=False)
- if 'view-mask' in data.keys():
- filter_node = XML.SubElement(xml_parent, 'filter')
+ if "view-mask" in data.keys():
+ filter_node = XML.SubElement(xml_parent, "filter")
- view_mask = XML.SubElement(filter_node,
- 'org.jenkinsci.plugins.p4.filters.FilterViewMaskImpl')
+ view_mask = XML.SubElement(
+ filter_node, "org.jenkinsci.plugins.p4.filters.FilterViewMaskImpl"
+ )
- view_mask_mapping = [
- ('view-mask', 'viewMask', None)
- ]
+ view_mask_mapping = [("view-mask", "viewMask", None)]
helpers.convert_mapping_to_xml(
- view_mask, data, view_mask_mapping, fail_required=False)
+ view_mask, data, view_mask_mapping, fail_required=False
+ )
helpers.convert_mapping_to_xml(
- workspace, data, workspace_mapping, fail_required=False)
+ workspace, data, workspace_mapping, fail_required=False
+ )
def p4_construct_populate(xml_parent, data):
populate = None
populate_mapping = [
- ('populate-have-list', 'have', False),
- ('populate-force-sync', 'force', False),
- ('populate-modtime', 'modtime', False),
- ('populate-quiet', 'quiet', False),
- ('populate-label', 'pin', None),
- ('populate-revert', 'revert', None),
- ('populate-replace', 'replace', None),
- ('populate-delete', 'delete', None),
- ('populate-tidy', 'tidy', None)
+ ("populate-have-list", "have", False),
+ ("populate-force-sync", "force", False),
+ ("populate-modtime", "modtime", False),
+ ("populate-quiet", "quiet", False),
+ ("populate-label", "pin", None),
+ ("populate-revert", "revert", None),
+ ("populate-replace", "replace", None),
+ ("populate-delete", "delete", None),
+ ("populate-tidy", "tidy", None),
]
parallel_mapping = [
- ('parallel-enabled', 'enable', False),
- ('parallel-threads', 'threads', '4'),
- ('parallel-minfiles', 'minfiles', '1'),
- ('parallel-minbytes', 'minbytes', '1024')
+ ("parallel-enabled", "enable", False),
+ ("parallel-threads", "threads", "4"),
+ ("parallel-minfiles", "minfiles", "1"),
+ ("parallel-minbytes", "minbytes", "1024"),
]
- if data.get('populate-type') == 'SyncOnly':
- populate = XML.SubElement(xml_parent, 'populate',
- {'class': 'org.jenkinsci.plugins.p4.populate.SyncOnlyImpl'})
- elif data.get('populate-type') == 'AutoClean':
- populate = XML.SubElement(xml_parent, 'populate',
- {'class': 'org.jenkinsci.plugins.p4.populate.AutoCleanImpl'})
+ if data.get("populate-type") == "SyncOnly":
+ populate = XML.SubElement(
+ xml_parent,
+ "populate",
+ {"class": "org.jenkinsci.plugins.p4.populate.SyncOnlyImpl"},
+ )
+ elif data.get("populate-type") == "AutoClean":
+ populate = XML.SubElement(
+ xml_parent,
+ "populate",
+ {"class": "org.jenkinsci.plugins.p4.populate.AutoCleanImpl"},
+ )
helpers.convert_mapping_to_xml(
- populate, data, populate_mapping, fail_required=False)
+ populate, data, populate_mapping, fail_required=False
+ )
- parallel = XML.SubElement(populate, 'parallel')
+ parallel = XML.SubElement(populate, "parallel")
helpers.convert_mapping_to_xml(
- parallel, data, parallel_mapping, fail_required=False)
+ parallel, data, parallel_mapping, fail_required=False
+ )
def git(registry, xml_parent, data):
@@ -321,63 +335,64 @@ def git(registry, xml_parent, data):
# None so we have a sensible name/key for it.
mapping = [
# option, xml name, default value (text), attributes (hard coded)
- ("disable-submodules", 'disableSubmodules', False),
- ("recursive-submodules", 'recursiveSubmodules', False),
- (None, 'doGenerateSubmoduleConfigurations', False),
+ ("disable-submodules", "disableSubmodules", False),
+ ("recursive-submodules", "recursiveSubmodules", False),
+ (None, "doGenerateSubmoduleConfigurations", False),
# XXX is this the same as force-polling-using-workspace?
- ("fastpoll", 'remotePoll', False),
+ ("fastpoll", "remotePoll", False),
# XXX does this option still exist?
- ("git-tool", 'gitTool', "Default"),
- (None, 'submoduleCfg', '', {'class': 'list'}),
- ('reference-repo', 'reference', ''),
- ("git-config-name", 'gitConfigName', ''),
- ("git-config-email", 'gitConfigEmail', ''),
+ ("git-tool", "gitTool", "Default"),
+ (None, "submoduleCfg", "", {"class": "list"}),
+ ("reference-repo", "reference", ""),
+ ("git-config-name", "gitConfigName", ""),
+ ("git-config-email", "gitConfigEmail", ""),
]
- scm = XML.SubElement(xml_parent,
- 'scm', {'class': 'hudson.plugins.git.GitSCM'})
- XML.SubElement(scm, 'configVersion').text = '2'
- user = XML.SubElement(scm, 'userRemoteConfigs')
- if 'remotes' not in data:
- data['remotes'] = [{data.get('name', 'origin'): data.copy()}]
- for remoteData in data['remotes']:
- huser = XML.SubElement(user, 'hudson.plugins.git.UserRemoteConfig')
+ scm = XML.SubElement(xml_parent, "scm", {"class": "hudson.plugins.git.GitSCM"})
+ XML.SubElement(scm, "configVersion").text = "2"
+ user = XML.SubElement(scm, "userRemoteConfigs")
+ if "remotes" not in data:
+ data["remotes"] = [{data.get("name", "origin"): data.copy()}]
+ for remoteData in data["remotes"]:
+ huser = XML.SubElement(user, "hudson.plugins.git.UserRemoteConfig")
remoteName = next(iter(remoteData.keys()))
- XML.SubElement(huser, 'name').text = remoteName
+ XML.SubElement(huser, "name").text = remoteName
remoteParams = next(iter(remoteData.values()))
- if 'refspec' in remoteParams:
- refspec = remoteParams['refspec']
+ if "refspec" in remoteParams:
+ refspec = remoteParams["refspec"]
else:
- refspec = '+refs/heads/*:refs/remotes/' + remoteName + '/*'
- XML.SubElement(huser, 'refspec').text = refspec
- if 'url' in remoteParams:
- remoteURL = remoteParams['url']
+ refspec = "+refs/heads/*:refs/remotes/" + remoteName + "/*"
+ XML.SubElement(huser, "refspec").text = refspec
+ if "url" in remoteParams:
+ remoteURL = remoteParams["url"]
else:
raise JenkinsJobsException(
- 'Must specify a url for git remote \"' + remoteName + '"')
- XML.SubElement(huser, 'url').text = remoteURL
- if 'credentials-id' in remoteParams:
- credentialsId = remoteParams['credentials-id']
- XML.SubElement(huser, 'credentialsId').text = credentialsId
- xml_branches = XML.SubElement(scm, 'branches')
- branches = data.get('branches', ['**'])
+ 'Must specify a url for git remote "' + remoteName + '"'
+ )
+ XML.SubElement(huser, "url").text = remoteURL
+ if "credentials-id" in remoteParams:
+ credentialsId = remoteParams["credentials-id"]
+ XML.SubElement(huser, "credentialsId").text = credentialsId
+ xml_branches = XML.SubElement(scm, "branches")
+ branches = data.get("branches", ["**"])
for branch in branches:
- bspec = XML.SubElement(xml_branches, 'hudson.plugins.git.BranchSpec')
- XML.SubElement(bspec, 'name').text = branch
+ bspec = XML.SubElement(xml_branches, "hudson.plugins.git.BranchSpec")
+ XML.SubElement(bspec, "name").text = branch
for elem in mapping:
(optname, xmlname, val) = elem[:3]
# Throw warning for deprecated settings and skip if the 'submodule' key
# is available.
- submodule_cfgs = ['disable-submodules', 'recursive-submodules']
+ submodule_cfgs = ["disable-submodules", "recursive-submodules"]
if optname in submodule_cfgs:
if optname in data:
logger.warning(
"'{0}' is deprecated, please convert to use the "
"'submodule' section instead as support for this "
"top level option will be removed in a future "
- "release.".format(optname))
- if 'submodule' in data:
+ "release.".format(optname)
+ )
+ if "submodule" in data:
continue
attrs = {}
@@ -391,52 +406,52 @@ def git(registry, xml_parent, data):
else:
xe.text = val
- exts = XML.SubElement(scm, 'extensions')
+ exts = XML.SubElement(scm, "extensions")
# handle all supported git extensions
git_extensions(exts, data)
- browser = data.get('browser', 'auto')
+ browser = data.get("browser", "auto")
browserdict = {
- 'auto': 'auto',
- 'assemblaweb': 'AssemblaWeb',
- 'bitbucketweb': 'BitbucketWeb',
- 'cgit': 'CGit',
- 'fisheye': 'FisheyeGitRepositoryBrowser',
- 'gitblit': 'GitBlitRepositoryBrowser',
- 'githubweb': 'GithubWeb',
- 'gitiles': 'Gitiles',
- 'gitlab': 'GitLab',
- 'gitlist': 'GitList',
- 'gitoriousweb': 'GitoriousWeb',
- 'gitweb': 'GitWeb',
- 'kiln': 'KilnGit',
- 'microsoft-tfs-2013': 'TFS2013GitRepositoryBrowser',
- 'phabricator': 'Phabricator',
- 'redmineweb': 'RedmineWeb',
- 'rhodecode': 'RhodeCode',
- 'stash': 'Stash',
- 'viewgit': 'ViewGitWeb',
+ "auto": "auto",
+ "assemblaweb": "AssemblaWeb",
+ "bitbucketweb": "BitbucketWeb",
+ "cgit": "CGit",
+ "fisheye": "FisheyeGitRepositoryBrowser",
+ "gitblit": "GitBlitRepositoryBrowser",
+ "githubweb": "GithubWeb",
+ "gitiles": "Gitiles",
+ "gitlab": "GitLab",
+ "gitlist": "GitList",
+ "gitoriousweb": "GitoriousWeb",
+ "gitweb": "GitWeb",
+ "kiln": "KilnGit",
+ "microsoft-tfs-2013": "TFS2013GitRepositoryBrowser",
+ "phabricator": "Phabricator",
+ "redmineweb": "RedmineWeb",
+ "rhodecode": "RhodeCode",
+ "stash": "Stash",
+ "viewgit": "ViewGitWeb",
}
if browser not in browserdict:
valid = sorted(browserdict.keys())
- raise JenkinsJobsException("Browser entered is not valid must be one "
- "of: %s or %s." % (", ".join(valid[:-1]),
- valid[-1]))
- if browser != 'auto':
- bc = XML.SubElement(scm, 'browser', {'class':
- 'hudson.plugins.git.browser.' +
- browserdict[browser]})
- XML.SubElement(bc, 'url').text = data['browser-url']
- if browser in ['gitblit', 'viewgit']:
- XML.SubElement(bc, 'projectName').text = str(
- data.get('project-name', ''))
- if browser == 'gitlab':
- XML.SubElement(bc, 'version').text = str(
- data.get('browser-version', '0.0'))
- if browser == 'phabricator':
- XML.SubElement(bc, 'repo').text = str(
- data.get('repo-name', ''))
+ raise JenkinsJobsException(
+ "Browser entered is not valid must be one "
+ "of: %s or %s." % (", ".join(valid[:-1]), valid[-1])
+ )
+ if browser != "auto":
+ bc = XML.SubElement(
+ scm,
+ "browser",
+ {"class": "hudson.plugins.git.browser." + browserdict[browser]},
+ )
+ XML.SubElement(bc, "url").text = data["browser-url"]
+ if browser in ["gitblit", "viewgit"]:
+ XML.SubElement(bc, "projectName").text = str(data.get("project-name", ""))
+ if browser == "gitlab":
+ XML.SubElement(bc, "version").text = str(data.get("browser-version", "0.0"))
+ if browser == "phabricator":
+ XML.SubElement(bc, "repo").text = str(data.get("repo-name", ""))
def git_extensions(xml_parent, data):
@@ -445,111 +460,120 @@ def git_extensions(xml_parent, data):
trait = xml_parent.tag == "traits"
# list of availavble traits here: https://bit.ly/2CNEtqS
- trait_prefix = 'jenkins.plugins.git.traits.'
- impl_prefix = 'hudson.plugins.git.extensions.impl.'
+ trait_prefix = "jenkins.plugins.git.traits."
+ impl_prefix = "hudson.plugins.git.extensions.impl."
choosing_strategies = {
- 'default': 'hudson.plugins.git.util.DefaultBuildChooser',
- 'gerrit': ('com.sonyericsson.hudson.plugins.'
- 'gerrit.trigger.hudsontrigger.GerritTriggerBuildChooser'),
- 'inverse': 'hudson.plugins.git.util.InverseBuildChooser',
+ "default": "hudson.plugins.git.util.DefaultBuildChooser",
+ "gerrit": (
+ "com.sonyericsson.hudson.plugins."
+ "gerrit.trigger.hudsontrigger.GerritTriggerBuildChooser"
+ ),
+ "inverse": "hudson.plugins.git.util.InverseBuildChooser",
}
- if not trait and 'basedir' in data:
- ext = XML.SubElement(xml_parent,
- impl_prefix + 'RelativeTargetDirectory')
- XML.SubElement(ext, 'relativeTargetDir').text = data['basedir']
- if not trait and 'changelog-against' in data:
- ext_name = impl_prefix + 'ChangelogToBranch'
+ if not trait and "basedir" in data:
+ ext = XML.SubElement(xml_parent, impl_prefix + "RelativeTargetDirectory")
+ XML.SubElement(ext, "relativeTargetDir").text = data["basedir"]
+ if not trait and "changelog-against" in data:
+ ext_name = impl_prefix + "ChangelogToBranch"
ext = XML.SubElement(xml_parent, ext_name)
- opts = XML.SubElement(ext, 'options')
- change_remote = data['changelog-against'].get('remote', 'origin')
- change_branch = data['changelog-against'].get('branch', 'master')
- XML.SubElement(opts, 'compareRemote').text = change_remote
- XML.SubElement(opts, 'compareTarget').text = change_branch
- if not trait and 'choosing-strategy' in data:
+ opts = XML.SubElement(ext, "options")
+ change_remote = data["changelog-against"].get("remote", "origin")
+ change_branch = data["changelog-against"].get("branch", "master")
+ XML.SubElement(opts, "compareRemote").text = change_remote
+ XML.SubElement(opts, "compareTarget").text = change_branch
+ if not trait and "choosing-strategy" in data:
try:
- choosing_strategy = choosing_strategies[
- data.get('choosing-strategy')]
+ choosing_strategy = choosing_strategies[data.get("choosing-strategy")]
except KeyError:
- raise ValueError('Invalid choosing-strategy %r' %
- data.get('choosing-strategy'))
- ext = XML.SubElement(xml_parent, impl_prefix + 'BuildChooserSetting')
- XML.SubElement(ext, 'buildChooser', {'class': choosing_strategy})
- if 'clean' in data:
+ raise ValueError(
+ "Invalid choosing-strategy %r" % data.get("choosing-strategy")
+ )
+ ext = XML.SubElement(xml_parent, impl_prefix + "BuildChooserSetting")
+ XML.SubElement(ext, "buildChooser", {"class": choosing_strategy})
+ if "clean" in data:
# Keep support for old format 'clean' configuration by checking
# if 'clean' is boolean. Else we're using the new extensions style.
- if isinstance(data['clean'], bool):
- clean_after = data['clean']
+ if isinstance(data["clean"], bool):
+ clean_after = data["clean"]
clean_before = False
logger.warning(
"'clean: bool' configuration format is deprecated, "
"please use the extension style format to configure "
- "this option.")
+ "this option."
+ )
else:
- clean_after = data['clean'].get('after', False)
- clean_before = data['clean'].get('before', False)
+ clean_after = data["clean"].get("after", False)
+ clean_before = data["clean"].get("before", False)
if clean_after:
- ext_name = impl_prefix + 'CleanCheckout'
+ ext_name = impl_prefix + "CleanCheckout"
if trait:
- trait_name = 'CleanAfterCheckoutTrait'
+ trait_name = "CleanAfterCheckoutTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
if clean_before:
- ext_name = impl_prefix + 'CleanBeforeCheckout'
+ ext_name = impl_prefix + "CleanBeforeCheckout"
if trait:
- trait_name = 'CleanBeforeCheckoutTrait'
+ trait_name = "CleanBeforeCheckoutTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
- if not trait and 'excluded-users' in data:
- excluded_users = '\n'.join(data['excluded-users'])
- ext = XML.SubElement(xml_parent, impl_prefix + 'UserExclusion')
- XML.SubElement(ext, 'excludedUsers').text = excluded_users
- if not trait and 'included-regions' in data or 'excluded-regions' in data:
- ext = XML.SubElement(xml_parent,
- 'hudson.plugins.git.extensions.impl.'
- 'PathRestriction')
- if 'included-regions' in data:
- include_string = '\n'.join(data['included-regions'])
- XML.SubElement(ext, 'includedRegions').text = include_string
- if 'excluded-regions' in data:
- exclude_string = '\n'.join(data['excluded-regions'])
- XML.SubElement(ext, 'excludedRegions').text = exclude_string
- if not trait and 'ignore-commits-with-messages' in data:
- for msg in data['ignore-commits-with-messages']:
- ext_name = impl_prefix + 'MessageExclusion'
+ if not trait and "excluded-users" in data:
+ excluded_users = "\n".join(data["excluded-users"])
+ ext = XML.SubElement(xml_parent, impl_prefix + "UserExclusion")
+ XML.SubElement(ext, "excludedUsers").text = excluded_users
+ if not trait and "included-regions" in data or "excluded-regions" in data:
+ ext = XML.SubElement(
+ xml_parent, "hudson.plugins.git.extensions.impl." "PathRestriction"
+ )
+ if "included-regions" in data:
+ include_string = "\n".join(data["included-regions"])
+ XML.SubElement(ext, "includedRegions").text = include_string
+ if "excluded-regions" in data:
+ exclude_string = "\n".join(data["excluded-regions"])
+ XML.SubElement(ext, "excludedRegions").text = exclude_string
+ if not trait and "ignore-commits-with-messages" in data:
+ for msg in data["ignore-commits-with-messages"]:
+ ext_name = impl_prefix + "MessageExclusion"
ext = XML.SubElement(xml_parent, ext_name)
- XML.SubElement(ext, 'excludedMessage').text = msg
- if not trait and 'local-branch' in data:
- ext = XML.SubElement(xml_parent, impl_prefix + 'LocalBranch')
- XML.SubElement(ext, 'localBranch').text = str(data['local-branch'])
- if not trait and 'merge' in data:
- merge = data['merge']
- merge_strategies = ['default', 'resolve', 'recursive', 'octopus',
- 'ours', 'subtree']
- fast_forward_modes = ['FF', 'FF_ONLY', 'NO_FF']
- name = merge.get('remote', 'origin')
- branch = merge['branch']
- ext = XML.SubElement(xml_parent, impl_prefix + 'PreBuildMerge')
- merge_opts = XML.SubElement(ext, 'options')
- XML.SubElement(merge_opts, 'mergeRemote').text = name
- XML.SubElement(merge_opts, 'mergeTarget').text = branch
- strategy = merge.get('strategy', 'default')
+ XML.SubElement(ext, "excludedMessage").text = msg
+ if not trait and "local-branch" in data:
+ ext = XML.SubElement(xml_parent, impl_prefix + "LocalBranch")
+ XML.SubElement(ext, "localBranch").text = str(data["local-branch"])
+ if not trait and "merge" in data:
+ merge = data["merge"]
+ merge_strategies = [
+ "default",
+ "resolve",
+ "recursive",
+ "octopus",
+ "ours",
+ "subtree",
+ ]
+ fast_forward_modes = ["FF", "FF_ONLY", "NO_FF"]
+ name = merge.get("remote", "origin")
+ branch = merge["branch"]
+ ext = XML.SubElement(xml_parent, impl_prefix + "PreBuildMerge")
+ merge_opts = XML.SubElement(ext, "options")
+ XML.SubElement(merge_opts, "mergeRemote").text = name
+ XML.SubElement(merge_opts, "mergeTarget").text = branch
+ strategy = merge.get("strategy", "default")
if strategy not in merge_strategies:
- raise InvalidAttributeError('strategy', strategy, merge_strategies)
- XML.SubElement(merge_opts, 'mergeStrategy').text = strategy
- fast_forward_mode = merge.get('fast-forward-mode', 'FF')
+ raise InvalidAttributeError("strategy", strategy, merge_strategies)
+ XML.SubElement(merge_opts, "mergeStrategy").text = strategy
+ fast_forward_mode = merge.get("fast-forward-mode", "FF")
if fast_forward_mode not in fast_forward_modes:
- raise InvalidAttributeError('fast-forward-mode', fast_forward_mode,
- fast_forward_modes)
- XML.SubElement(merge_opts, 'fastForwardMode').text = fast_forward_mode
- if not trait and 'scm-name' in data:
- ext = XML.SubElement(xml_parent, impl_prefix + 'ScmName')
- XML.SubElement(ext, 'name').text = str(data['scm-name'])
+ raise InvalidAttributeError(
+ "fast-forward-mode", fast_forward_mode, fast_forward_modes
+ )
+ XML.SubElement(merge_opts, "fastForwardMode").text = fast_forward_mode
+ if not trait and "scm-name" in data:
+ ext = XML.SubElement(xml_parent, impl_prefix + "ScmName")
+ XML.SubElement(ext, "name").text = str(data["scm-name"])
clone_options = (
"shallow-clone",
@@ -559,116 +583,118 @@ def git_extensions(xml_parent, data):
"reference-repo",
)
if any(key in data for key in clone_options):
- ext_name = impl_prefix + 'CloneOption'
+ ext_name = impl_prefix + "CloneOption"
if trait:
- tr = XML.SubElement(xml_parent, trait_prefix + 'CloneOptionTrait')
+ tr = XML.SubElement(xml_parent, trait_prefix + "CloneOptionTrait")
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
- clone_mapping = [
- ('shallow-clone', 'shallow', False),
- ('depth', 'depth', 1),
- ]
- helpers.convert_mapping_to_xml(
- ext, data, clone_mapping, fail_required=True)
- if 'do-not-fetch-tags' in data:
- XML.SubElement(ext, 'noTags').text = str(
- data.get('do-not-fetch-tags', False)).lower()
- if 'timeout' in data:
- XML.SubElement(ext, 'timeout').text = str(data['timeout'])
- if 'honor-refspec' in data:
- XML.SubElement(ext, 'honorRefspec').text = str(
- data.get('honor-refspec', False)).lower()
- if 'reference-repo' in data:
- XML.SubElement(ext, 'reference').text = str(data['reference-repo'])
- if not trait and 'sparse-checkout' in data:
- ext_name = impl_prefix + 'SparseCheckoutPaths'
+ clone_mapping = [("shallow-clone", "shallow", False), ("depth", "depth", 1)]
+ helpers.convert_mapping_to_xml(ext, data, clone_mapping, fail_required=True)
+ if "do-not-fetch-tags" in data:
+ XML.SubElement(ext, "noTags").text = str(
+ data.get("do-not-fetch-tags", False)
+ ).lower()
+ if "timeout" in data:
+ XML.SubElement(ext, "timeout").text = str(data["timeout"])
+ if "honor-refspec" in data:
+ XML.SubElement(ext, "honorRefspec").text = str(
+ data.get("honor-refspec", False)
+ ).lower()
+ if "reference-repo" in data:
+ XML.SubElement(ext, "reference").text = str(data["reference-repo"])
+ if not trait and "sparse-checkout" in data:
+ ext_name = impl_prefix + "SparseCheckoutPaths"
ext = XML.SubElement(xml_parent, ext_name)
- sparse_co = XML.SubElement(ext, 'sparseCheckoutPaths')
- sparse_paths = data['sparse-checkout'].get('paths')
+ sparse_co = XML.SubElement(ext, "sparseCheckoutPaths")
+ sparse_paths = data["sparse-checkout"].get("paths")
if sparse_paths is not None:
- path_tagname = impl_prefix + 'SparseCheckoutPath'
+ path_tagname = impl_prefix + "SparseCheckoutPath"
for path in sparse_paths:
path_tag = XML.SubElement(sparse_co, path_tagname)
- XML.SubElement(path_tag, 'path').text = path
- if 'submodule' in data:
- ext_name = impl_prefix + 'SubmoduleOption'
+ XML.SubElement(path_tag, "path").text = path
+ if "submodule" in data:
+ ext_name = impl_prefix + "SubmoduleOption"
if trait:
- trait_name = 'SubmoduleOptionTrait'
+ trait_name = "SubmoduleOptionTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
- XML.SubElement(ext, 'disableSubmodules').text = str(
- data['submodule'].get('disable', False)).lower()
- XML.SubElement(ext, 'recursiveSubmodules').text = str(
- data['submodule'].get('recursive', False)).lower()
- XML.SubElement(ext, 'trackingSubmodules').text = str(
- data['submodule'].get('tracking', False)).lower()
- XML.SubElement(ext, 'parentCredentials').text = str(
- data['submodule'].get('parent-credentials', False)).lower()
- XML.SubElement(ext, 'reference').text = str(
- data['submodule'].get('reference-repo', ''))
- XML.SubElement(ext, 'timeout').text = str(
- data['submodule'].get('timeout', 10))
- if 'timeout' in data:
- ext_name = impl_prefix + 'CheckoutOption'
+ XML.SubElement(ext, "disableSubmodules").text = str(
+ data["submodule"].get("disable", False)
+ ).lower()
+ XML.SubElement(ext, "recursiveSubmodules").text = str(
+ data["submodule"].get("recursive", False)
+ ).lower()
+ XML.SubElement(ext, "trackingSubmodules").text = str(
+ data["submodule"].get("tracking", False)
+ ).lower()
+ XML.SubElement(ext, "parentCredentials").text = str(
+ data["submodule"].get("parent-credentials", False)
+ ).lower()
+ XML.SubElement(ext, "reference").text = str(
+ data["submodule"].get("reference-repo", "")
+ )
+ XML.SubElement(ext, "timeout").text = str(data["submodule"].get("timeout", 10))
+ if "timeout" in data:
+ ext_name = impl_prefix + "CheckoutOption"
if trait:
- trait_name = 'CheckoutOptionTrait'
+ trait_name = "CheckoutOptionTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
- XML.SubElement(ext, 'timeout').text = str(data['timeout'])
+ XML.SubElement(ext, "timeout").text = str(data["timeout"])
- polling_using_workspace = str(data.get('force-polling-using-workspace',
- False)).lower()
- if not trait and polling_using_workspace == 'true':
- ext_name = impl_prefix + 'DisableRemotePoll'
+ polling_using_workspace = str(
+ data.get("force-polling-using-workspace", False)
+ ).lower()
+ if not trait and polling_using_workspace == "true":
+ ext_name = impl_prefix + "DisableRemotePoll"
ext = XML.SubElement(xml_parent, ext_name)
- if not trait and 'per-build-tag' in data or 'skip-tag' in data:
+ if not trait and "per-build-tag" in data or "skip-tag" in data:
# We want to support both skip-tag (the old option) and per-build-tag
# (the new option), with the new one overriding the old one.
# Unfortunately they have inverse meanings, so we have to be careful.
# The default value of per-build-tag is False if skip-tag is not set,
# so we set the default value of skip-tag to True.
per_build_tag_default = False
- if str(data.get('skip-tag', True)).lower() == 'false':
+ if str(data.get("skip-tag", True)).lower() == "false":
per_build_tag_default = True
- if str(data.get('per-build-tag',
- per_build_tag_default)).lower() == 'true':
- XML.SubElement(xml_parent, impl_prefix + 'PerBuildTag')
- prune = str(data.get('prune', False)).lower()
- if prune == 'true':
- ext_name = impl_prefix + 'PruneStaleBranch'
+ if str(data.get("per-build-tag", per_build_tag_default)).lower() == "true":
+ XML.SubElement(xml_parent, impl_prefix + "PerBuildTag")
+ prune = str(data.get("prune", False)).lower()
+ if prune == "true":
+ ext_name = impl_prefix + "PruneStaleBranch"
if trait:
- trait_name = 'PruneStaleBranchTrait'
+ trait_name = "PruneStaleBranchTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
- ignore_notify_commits = str(data.get('ignore-notify', False)).lower()
- if not trait and ignore_notify_commits == 'true':
- XML.SubElement(xml_parent, impl_prefix + 'IgnoreNotifyCommit')
+ ignore_notify_commits = str(data.get("ignore-notify", False)).lower()
+ if not trait and ignore_notify_commits == "true":
+ XML.SubElement(xml_parent, impl_prefix + "IgnoreNotifyCommit")
# By default we wipe the workspace
- wipe_workspace = str(data.get('wipe-workspace', True)).lower()
- if wipe_workspace == 'true':
- ext_name = impl_prefix + 'WipeWorkspace'
+ wipe_workspace = str(data.get("wipe-workspace", True)).lower()
+ if wipe_workspace == "true":
+ ext_name = impl_prefix + "WipeWorkspace"
if trait:
- trait_name = 'WipeWorkspaceTrait'
+ trait_name = "WipeWorkspaceTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
- use_author = str(data.get('use-author', False)).lower()
- if use_author == 'true':
- ext_name = impl_prefix + 'AuthorInChangelog'
+ use_author = str(data.get("use-author", False)).lower()
+ if use_author == "true":
+ ext_name = impl_prefix + "AuthorInChangelog"
if trait:
- trait_name = 'AuthorInChangelogTrait'
+ trait_name = "AuthorInChangelogTrait"
tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
@@ -737,76 +763,71 @@ def cvs(registry, xml_parent, data):
.. literalinclude:: /../../tests/scm/fixtures/cvs002.yaml
:language: yaml
"""
- prefix = 'hudson.scm.'
- valid_loc_types = {
- 'HEAD': 'Head',
- 'TAG': 'Tag',
- 'BRANCH': 'Branch'
- }
+ prefix = "hudson.scm."
+ valid_loc_types = {"HEAD": "Head", "TAG": "Tag", "BRANCH": "Branch"}
- cvs = XML.SubElement(xml_parent, 'scm', {'class': prefix + 'CVSSCM'})
- repos = data.get('repos')
- repos_tag = XML.SubElement(cvs, 'repositories')
+ cvs = XML.SubElement(xml_parent, "scm", {"class": prefix + "CVSSCM"})
+ repos = data.get("repos")
+ repos_tag = XML.SubElement(cvs, "repositories")
for repo in repos:
- repo_tag = XML.SubElement(repos_tag, prefix + 'CvsRepository')
- compression_level = repo.get('compression-level', '-1')
+ repo_tag = XML.SubElement(repos_tag, prefix + "CvsRepository")
+ compression_level = repo.get("compression-level", "-1")
repo_mapping = [
- ('root', 'cvsRoot', None),
- ('', 'compressionLevel', int(compression_level), range(-1, 10)),
+ ("root", "cvsRoot", None),
+ ("", "compressionLevel", int(compression_level), range(-1, 10)),
]
- helpers.convert_mapping_to_xml(repo_tag,
- repo, repo_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(repo_tag, repo, repo_mapping, fail_required=True)
- items_tag = XML.SubElement(repo_tag, 'repositoryItems')
- locations = repo.get('locations')
+ items_tag = XML.SubElement(repo_tag, "repositoryItems")
+ locations = repo.get("locations")
for location in locations:
- item_tag = XML.SubElement(items_tag, prefix + 'CvsRepositoryItem')
- loc_type = location.get('type', 'HEAD')
+ item_tag = XML.SubElement(items_tag, prefix + "CvsRepositoryItem")
+ loc_type = location.get("type", "HEAD")
if loc_type not in valid_loc_types:
- raise InvalidAttributeError('type', loc_type, valid_loc_types)
- loc_class = ('{0}CvsRepositoryLocation${1}Repository'
- 'Location').format(prefix, valid_loc_types[loc_type])
- loc_tag = XML.SubElement(item_tag, 'location',
- {'class': loc_class})
- mapping = [
- ('type', 'locationType', 'HEAD'),
- ]
+ raise InvalidAttributeError("type", loc_type, valid_loc_types)
+ loc_class = ("{0}CvsRepositoryLocation${1}Repository" "Location").format(
+ prefix, valid_loc_types[loc_type]
+ )
+ loc_tag = XML.SubElement(item_tag, "location", {"class": loc_class})
+ mapping = [("type", "locationType", "HEAD")]
helpers.convert_mapping_to_xml(
- loc_tag, location, mapping, fail_required=True)
+ loc_tag, location, mapping, fail_required=True
+ )
- if loc_type != 'HEAD':
+ if loc_type != "HEAD":
mapping = [
- ('name', 'locationName', ''),
- ('use-head', 'useHeadIfNotFound', False),
+ ("name", "locationName", ""),
+ ("use-head", "useHeadIfNotFound", False),
]
helpers.convert_mapping_to_xml(
- loc_tag, location, mapping, fail_required=True)
+ loc_tag, location, mapping, fail_required=True
+ )
- modules = location.get('modules')
- modules_tag = XML.SubElement(item_tag, 'modules')
+ modules = location.get("modules")
+ modules_tag = XML.SubElement(item_tag, "modules")
for module in modules:
- module_tag = XML.SubElement(modules_tag, prefix + 'CvsModule')
+ module_tag = XML.SubElement(modules_tag, prefix + "CvsModule")
mapping = [
- ('remote', 'remoteName', None),
- ('local-name', 'localName', ''),
+ ("remote", "remoteName", None),
+ ("local-name", "localName", ""),
]
helpers.convert_mapping_to_xml(
- module_tag, module, mapping, fail_required=True)
+ module_tag, module, mapping, fail_required=True
+ )
- excluded = repo.get('excluded-regions', [])
- excluded_tag = XML.SubElement(repo_tag, 'excludedRegions')
+ excluded = repo.get("excluded-regions", [])
+ excluded_tag = XML.SubElement(repo_tag, "excludedRegions")
for pattern in excluded:
- pattern_tag = XML.SubElement(excluded_tag,
- prefix + 'ExcludedRegion')
- XML.SubElement(pattern_tag, 'pattern').text = pattern
+ pattern_tag = XML.SubElement(excluded_tag, prefix + "ExcludedRegion")
+ XML.SubElement(pattern_tag, "pattern").text = pattern
mappings = [
- ('use-update', 'canUseUpdate', True),
- ('prune-empty', 'pruneEmptyDirectories', True),
- ('skip-changelog', 'skipChangeLog', False),
- ('show-all-output', 'disableCvsQuiet', False),
- ('clean-checkout', 'cleanOnFailedUpdate', False),
- ('clean-copy', 'forceCleanCopy', False),
+ ("use-update", "canUseUpdate", True),
+ ("prune-empty", "pruneEmptyDirectories", True),
+ ("skip-changelog", "skipChangeLog", False),
+ ("show-all-output", "disableCvsQuiet", False),
+ ("clean-checkout", "cleanOnFailedUpdate", False),
+ ("clean-copy", "forceCleanCopy", False),
]
helpers.convert_mapping_to_xml(cvs, data, mappings, fail_required=True)
@@ -855,43 +876,41 @@ def repo(registry, xml_parent, data):
.. literalinclude:: /../../tests/scm/fixtures/repo001.yaml
"""
- scm = XML.SubElement(xml_parent,
- 'scm', {'class': 'hudson.plugins.repo.RepoScm'})
+ scm = XML.SubElement(xml_parent, "scm", {"class": "hudson.plugins.repo.RepoScm"})
mapping = [
# option, xml name, default value
- ('manifest-url', 'manifestRepositoryUrl', None),
- ('jobs', 'jobs', 0),
- ('depth', 'depth', 0),
- ('current-branch', 'currentBranch', True),
- ('reset-first', 'resetFirst', False),
- ('quiet', 'quiet', True),
- ('force-sync', 'forceSync', False),
- ('no-tags', 'noTags', False),
- ('trace', 'trace', False),
- ('show-all-changes', 'showAllChanges', False),
+ ("manifest-url", "manifestRepositoryUrl", None),
+ ("jobs", "jobs", 0),
+ ("depth", "depth", 0),
+ ("current-branch", "currentBranch", True),
+ ("reset-first", "resetFirst", False),
+ ("quiet", "quiet", True),
+ ("force-sync", "forceSync", False),
+ ("no-tags", "noTags", False),
+ ("trace", "trace", False),
+ ("show-all-changes", "showAllChanges", False),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
optional_mapping = [
# option, xml name, default value
- ('manifest-branch', 'manifestBranch', None),
- ('manifest-file', 'manifestFile', None),
- ('manifest-group', 'manifestGroup', None),
- ('destination-dir', 'destinationDir', None),
- ('repo-url', 'repoUrl', None),
- ('mirror-dir', 'mirrorDir', None),
- ('local-manifest', 'localManifest', None),
+ ("manifest-branch", "manifestBranch", None),
+ ("manifest-file", "manifestFile", None),
+ ("manifest-group", "manifestGroup", None),
+ ("destination-dir", "destinationDir", None),
+ ("repo-url", "repoUrl", None),
+ ("mirror-dir", "mirrorDir", None),
+ ("local-manifest", "localManifest", None),
]
- helpers.convert_mapping_to_xml(
- scm, data, optional_mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(scm, data, optional_mapping, fail_required=False)
# ignore-projects does not follow the same pattern of the other parameters,
# so process it here:
- ip = XML.SubElement(scm, 'ignoreProjects', {'class': 'linked-hash-set'})
- ignored_projects = data.get('ignore-projects', [''])
+ ip = XML.SubElement(scm, "ignoreProjects", {"class": "linked-hash-set"})
+ ignored_projects = data.get("ignore-projects", [""])
for ignored_project in ignored_projects:
- XML.SubElement(ip, 'string').text = str(ignored_project)
+ XML.SubElement(ip, "string").text = str(ignored_project)
def store(registry, xml_parent, data):
@@ -917,41 +936,35 @@ def store(registry, xml_parent, data):
.. literalinclude:: /../../tests/scm/fixtures/store001.yaml
"""
- namespace = 'org.jenkinsci.plugins.visualworks_store'
- scm = XML.SubElement(xml_parent, 'scm',
- {'class': '{0}.StoreSCM'.format(namespace)})
- mapping = [
- ('script', 'scriptName', None),
- ('repository', 'repositoryName', None),
- ]
+ namespace = "org.jenkinsci.plugins.visualworks_store"
+ scm = XML.SubElement(xml_parent, "scm", {"class": "{0}.StoreSCM".format(namespace)})
+ mapping = [("script", "scriptName", None), ("repository", "repositoryName", None)]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
- pundle_specs = data.get('pundles', [])
+ pundle_specs = data.get("pundles", [])
if not pundle_specs:
raise JenkinsJobsException("At least one pundle must be specified")
- valid_pundle_types = ['PACKAGE', 'BUNDLE']
- pundles = XML.SubElement(scm, 'pundles')
+ valid_pundle_types = ["PACKAGE", "BUNDLE"]
+ pundles = XML.SubElement(scm, "pundles")
for pundle_spec in pundle_specs:
- pundle = XML.SubElement(pundles, '{0}.PundleSpec'.format(namespace))
+ pundle = XML.SubElement(pundles, "{0}.PundleSpec".format(namespace))
pundle_type = next(iter(pundle_spec))
pundle_name = pundle_spec[pundle_type]
mapping = [
- ('', 'name', pundle_name),
- ('', 'pundleType', pundle_type.upper(), valid_pundle_types),
+ ("", "name", pundle_name),
+ ("", "pundleType", pundle_type.upper(), valid_pundle_types),
]
- helpers.convert_mapping_to_xml(
- pundle, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(pundle, data, mapping, fail_required=True)
- generate_parcel = 'parcel-builder-file' in data
+ generate_parcel = "parcel-builder-file" in data
mapping_optional = [
- ('version-regex', 'versionRegex', None),
- ('minimum-blessing', 'minimumBlessingLevel', None),
- ('', 'generateParcelBuilderInputFile', generate_parcel),
- ('parcel-builder-file', 'parcelBuilderInputFilename', None),
+ ("version-regex", "versionRegex", None),
+ ("minimum-blessing", "minimumBlessingLevel", None),
+ ("", "generateParcelBuilderInputFile", generate_parcel),
+ ("parcel-builder-file", "parcelBuilderInputFilename", None),
]
- helpers.convert_mapping_to_xml(scm,
- data, mapping_optional, fail_required=False)
+ helpers.convert_mapping_to_xml(scm, data, mapping_optional, fail_required=False)
def svn(registry, xml_parent, data):
@@ -1015,93 +1028,87 @@ def svn(registry, xml_parent, data):
.. literalinclude:: /../../tests/scm/fixtures/svn-regions-001.yaml
"""
- scm = XML.SubElement(xml_parent, 'scm', {'class':
- 'hudson.scm.SubversionSCM'})
- if 'viewvc-url' in data:
+ scm = XML.SubElement(xml_parent, "scm", {"class": "hudson.scm.SubversionSCM"})
+ if "viewvc-url" in data:
browser = XML.SubElement(
- scm, 'browser', {'class': 'hudson.scm.browsers.ViewSVN'})
- mapping = [
- ('viewvc-url', 'url', None),
- ]
- helpers.convert_mapping_to_xml(
- browser, data, mapping, fail_required=True)
- locations = XML.SubElement(scm, 'locations')
+ scm, "browser", {"class": "hudson.scm.browsers.ViewSVN"}
+ )
+ mapping = [("viewvc-url", "url", None)]
+ helpers.convert_mapping_to_xml(browser, data, mapping, fail_required=True)
+ locations = XML.SubElement(scm, "locations")
def populate_repo_xml(parent, data):
- module = XML.SubElement(parent,
- 'hudson.scm.SubversionSCM_-ModuleLocation')
- mapping = [
- ('url', 'remote', None),
- ('basedir', 'local', '.'),
- ]
- helpers.convert_mapping_to_xml(
- module, data, mapping, fail_required=True)
+ module = XML.SubElement(parent, "hudson.scm.SubversionSCM_-ModuleLocation")
+ mapping = [("url", "remote", None), ("basedir", "local", ".")]
+ helpers.convert_mapping_to_xml(module, data, mapping, fail_required=True)
- repo_depths = ['infinity', 'empty', 'files', 'immediates', 'unknown']
+ repo_depths = ["infinity", "empty", "files", "immediates", "unknown"]
mapping_optional = [
- ('credentials-id', 'credentialsId', None),
- ('repo-depth', 'depthOption', 'infinity', repo_depths),
- ('ignore-externals', 'ignoreExternalsOption', False),
+ ("credentials-id", "credentialsId", None),
+ ("repo-depth", "depthOption", "infinity", repo_depths),
+ ("ignore-externals", "ignoreExternalsOption", False),
]
- helpers.convert_mapping_to_xml(module, data,
- mapping_optional, fail_required=False)
+ helpers.convert_mapping_to_xml(
+ module, data, mapping_optional, fail_required=False
+ )
- if 'repos' in data:
- repos = data['repos']
+ if "repos" in data:
+ repos = data["repos"]
for repo in repos:
populate_repo_xml(locations, repo)
- elif 'url' in data:
+ elif "url" in data:
populate_repo_xml(locations, data)
else:
raise JenkinsJobsException("A top level url or repos list must exist")
def populate_additional_credential_xml(parent, data):
- module = XML.SubElement(parent,
- 'hudson.scm.SubversionSCM_-AdditionalCredentials')
- XML.SubElement(module, 'realm').text = data['realm']
- if 'credentials-id' in data:
- XML.SubElement(module, 'credentialsId').text = data[
- 'credentials-id']
+ module = XML.SubElement(
+ parent, "hudson.scm.SubversionSCM_-AdditionalCredentials"
+ )
+ XML.SubElement(module, "realm").text = data["realm"]
+ if "credentials-id" in data:
+ XML.SubElement(module, "credentialsId").text = data["credentials-id"]
- if 'additional-credentials' in data:
- additional_credentials = XML.SubElement(scm, 'additionalCredentials')
- additional_credentials_data = data['additional-credentials']
+ if "additional-credentials" in data:
+ additional_credentials = XML.SubElement(scm, "additionalCredentials")
+ additional_credentials_data = data["additional-credentials"]
for additional_credential in additional_credentials_data:
- populate_additional_credential_xml(additional_credentials,
- additional_credential)
-
- updater = data.get('workspaceupdater', 'wipeworkspace')
- if updater == 'wipeworkspace':
- updaterclass = 'CheckoutUpdater'
- elif updater == 'revertupdate':
- updaterclass = 'UpdateWithRevertUpdater'
- elif updater == 'emulateclean':
- updaterclass = 'UpdateWithCleanUpdater'
- elif updater == 'update':
- updaterclass = 'UpdateUpdater'
- XML.SubElement(scm, 'workspaceUpdater', {'class':
- 'hudson.scm.subversion.' + updaterclass})
+ populate_additional_credential_xml(
+ additional_credentials, additional_credential
+ )
+
+ updater = data.get("workspaceupdater", "wipeworkspace")
+ if updater == "wipeworkspace":
+ updaterclass = "CheckoutUpdater"
+ elif updater == "revertupdate":
+ updaterclass = "UpdateWithRevertUpdater"
+ elif updater == "emulateclean":
+ updaterclass = "UpdateWithCleanUpdater"
+ elif updater == "update":
+ updaterclass = "UpdateUpdater"
+ XML.SubElement(
+ scm, "workspaceUpdater", {"class": "hudson.scm.subversion." + updaterclass}
+ )
mapping = [
# option, xml name, default value
- ("excluded-regions", 'excludedRegions', []),
- ("included-regions", 'includedRegions', []),
- ("excluded-users", 'excludedUsers', []),
- ("exclusion-revprop-name", 'excludedRevprop', ''),
- ("excluded-commit-messages", 'excludedCommitMessages', []),
- ("ignore-property-changes-on-directories", 'ignoreDirPropChanges',
- False),
- ("filter-changelog", 'filterChangelog', False),
+ ("excluded-regions", "excludedRegions", []),
+ ("included-regions", "includedRegions", []),
+ ("excluded-users", "excludedUsers", []),
+ ("exclusion-revprop-name", "excludedRevprop", ""),
+ ("excluded-commit-messages", "excludedCommitMessages", []),
+ ("ignore-property-changes-on-directories", "ignoreDirPropChanges", False),
+ ("filter-changelog", "filterChangelog", False),
]
for optname, xmlname, defvalue in mapping:
if isinstance(defvalue, list):
- val = '\n'.join(data.get(optname, defvalue))
+ val = "\n".join(data.get(optname, defvalue))
else:
val = data.get(optname, defvalue)
# Skip adding xml entry if default is empty and no value given
- if not val and (defvalue in ['', []]):
+ if not val and (defvalue in ["", []]):
continue
xe = XML.SubElement(scm, xmlname)
@@ -1177,34 +1184,42 @@ def tfs(registry, xml_parent, data):
"""
- tfs = XML.SubElement(xml_parent, 'scm',
- {'class': 'hudson.plugins.tfs.'
- 'TeamFoundationServerScm'})
+ tfs = XML.SubElement(
+ xml_parent, "scm", {"class": "hudson.plugins.tfs." "TeamFoundationServerScm"}
+ )
mapping = [
- ('server-url', 'serverUrl', ''),
- ('project-path', 'projectPath', ''),
- ('local-path', 'localPath', '.'),
- ('workspace', 'workspaceName', 'Hudson-${JOB_NAME}-${NODE_NAME}'),
+ ("server-url", "serverUrl", ""),
+ ("project-path", "projectPath", ""),
+ ("local-path", "localPath", "."),
+ ("workspace", "workspaceName", "Hudson-${JOB_NAME}-${NODE_NAME}"),
# TODO: In the future, it would be nice to have a place that can pull
# passwords into JJB without having to commit them in plaintext. This
# could also integrate nicely with global configuration options.
- ('', 'userPassword', ''),
- ('login', 'userName', ''),
- ('use-update', 'useUpdate', True),
+ ("", "userPassword", ""),
+ ("login", "userName", ""),
+ ("use-update", "useUpdate", True),
]
helpers.convert_mapping_to_xml(tfs, data, mapping, fail_required=True)
- store = data.get('web-access', None)
+ store = data.get("web-access", None)
if isinstance(store, list):
- web = XML.SubElement(tfs, 'repositoryBrowser',
- {'class': 'hudson.plugins.tfs.browsers.'
- 'TeamSystemWebAccessBrowser'})
- XML.SubElement(web, 'url').text = str(store[0].get('web-url', None))
- elif 'web-access' in data and store is None:
- XML.SubElement(tfs, 'repositoryBrowser', {'class': 'hudson.'
- 'plugins.tfs.browsers.'
- 'TeamSystemWebAccess'
- 'Browser'})
+ web = XML.SubElement(
+ tfs,
+ "repositoryBrowser",
+ {"class": "hudson.plugins.tfs.browsers." "TeamSystemWebAccessBrowser"},
+ )
+ XML.SubElement(web, "url").text = str(store[0].get("web-url", None))
+ elif "web-access" in data and store is None:
+ XML.SubElement(
+ tfs,
+ "repositoryBrowser",
+ {
+ "class": "hudson."
+ "plugins.tfs.browsers."
+ "TeamSystemWebAccess"
+ "Browser"
+ },
+ )
def workspace(registry, xml_parent, data):
@@ -1228,18 +1243,20 @@ def workspace(registry, xml_parent, data):
.. literalinclude:: /../../tests/scm/fixtures/workspace001.yaml
"""
- workspace = XML.SubElement(xml_parent, 'scm', {'class': 'hudson.plugins.'
- 'cloneworkspace.CloneWorkspaceSCM'})
- criteria_list = ['Any', 'Not Failed', 'Successful']
+ workspace = XML.SubElement(
+ xml_parent,
+ "scm",
+ {"class": "hudson.plugins." "cloneworkspace.CloneWorkspaceSCM"},
+ )
+ criteria_list = ["Any", "Not Failed", "Successful"]
- criteria = data.get('criteria', 'Any').title()
+ criteria = data.get("criteria", "Any").title()
mapping = [
- ('parent-job', 'parentJobName', ''),
- ('', 'criteria', criteria, criteria_list),
+ ("parent-job", "parentJobName", ""),
+ ("", "criteria", criteria, criteria_list),
]
- helpers.convert_mapping_to_xml(
- workspace, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(workspace, data, mapping, fail_required=True)
def hg(self, xml_parent, data):
@@ -1282,54 +1299,50 @@ def hg(self, xml_parent, data):
.. literalinclude:: ../../tests/scm/fixtures/hg02.yaml
"""
- revision_type_dict = {
- 'branch': 'BRANCH',
- 'tag': 'TAG',
- }
- browser = data.get('browser', 'auto')
+ revision_type_dict = {"branch": "BRANCH", "tag": "TAG"}
+ browser = data.get("browser", "auto")
browserdict = {
- 'auto': '',
- 'bitbucket': 'BitBucket', # deprecated
- 'bitbucketweb': 'BitBucket',
- 'fisheye': 'FishEye',
- 'googlecode': 'GoogleCode',
- 'hgweb': 'HgWeb',
- 'kilnhg': 'KilnHG',
- 'rhodecode': 'RhodeCode',
- 'rhodecode-pre-1.2.0': 'RhodeCodeLegacy'
+ "auto": "",
+ "bitbucket": "BitBucket", # deprecated
+ "bitbucketweb": "BitBucket",
+ "fisheye": "FishEye",
+ "googlecode": "GoogleCode",
+ "hgweb": "HgWeb",
+ "kilnhg": "KilnHG",
+ "rhodecode": "RhodeCode",
+ "rhodecode-pre-1.2.0": "RhodeCodeLegacy",
}
- scm = XML.SubElement(xml_parent, 'scm', {'class':
- 'hudson.plugins.mercurial.MercurialSCM'})
- mapping = [
- ('url', 'source', None),
- ]
+ scm = XML.SubElement(
+ xml_parent, "scm", {"class": "hudson.plugins.mercurial.MercurialSCM"}
+ )
+ mapping = [("url", "source", None)]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
mapping_optional = [
- ('credentials-id', 'credentialsId', None),
- ('revision-type', 'revisionType', 'branch', revision_type_dict),
- ('revision', 'revision', 'default'),
- ('subdir', 'subdir', None),
- ('clean', 'clean', False),
+ ("credentials-id", "credentialsId", None),
+ ("revision-type", "revisionType", "branch", revision_type_dict),
+ ("revision", "revision", "default"),
+ ("subdir", "subdir", None),
+ ("clean", "clean", False),
]
- helpers.convert_mapping_to_xml(
- scm, data, mapping_optional, fail_required=False)
+ helpers.convert_mapping_to_xml(scm, data, mapping_optional, fail_required=False)
- modules = data.get('modules', '')
+ modules = data.get("modules", "")
if isinstance(modules, list):
modules = " ".join(modules)
- XML.SubElement(scm, 'modules').text = modules
- XML.SubElement(scm, 'disableChangeLog').text = str(data.get(
- 'disable-changelog', False)).lower()
-
- if browser != 'auto':
- bc = XML.SubElement(scm, 'browser',
- {'class': 'hudson.plugins.mercurial.browser.' +
- browserdict[browser]})
- mapping = [
- ('browser-url', 'url', None, browserdict[browser]),
- ]
+ XML.SubElement(scm, "modules").text = modules
+ XML.SubElement(scm, "disableChangeLog").text = str(
+ data.get("disable-changelog", False)
+ ).lower()
+
+ if browser != "auto":
+ bc = XML.SubElement(
+ scm,
+ "browser",
+ {"class": "hudson.plugins.mercurial.browser." + browserdict[browser]},
+ )
+ mapping = [("browser-url", "url", None, browserdict[browser])]
helpers.convert_mapping_to_xml(bc, data, mapping, fail_required=True)
@@ -1372,18 +1385,19 @@ def openshift_img_streams(registry, xml_parent, data):
../../tests/scm/fixtures/openshift-img-streams002.yaml
:language: yaml
"""
- scm = XML.SubElement(xml_parent,
- 'scm', {'class':
- 'com.openshift.jenkins.plugins.pipeline.'
- 'OpenShiftImageStreams'})
+ scm = XML.SubElement(
+ xml_parent,
+ "scm",
+ {"class": "com.openshift.jenkins.plugins.pipeline." "OpenShiftImageStreams"},
+ )
mapping = [
# option, xml name, default value
- ("image-stream-name", 'imageStreamName', 'nodejs-010-centos7'),
- ("tag", 'tag', 'latest'),
- ("api-url", 'apiURL', 'https://openshift.default.svc.cluster.local'),
- ("namespace", 'namespace', 'test'),
- ("auth-token", 'authToken', ''),
- ("verbose", 'verbose', False),
+ ("image-stream-name", "imageStreamName", "nodejs-010-centos7"),
+ ("tag", "tag", "latest"),
+ ("api-url", "apiURL", "https://openshift.default.svc.cluster.local"),
+ ("namespace", "namespace", "test"),
+ ("auth-token", "authToken", ""),
+ ("verbose", "verbose", False),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
@@ -1418,42 +1432,38 @@ def bzr(registry, xml_parent, data):
"""
mapping = [
# option, xml name, default value (text), attributes (hard coded)
- ('url', 'source', None),
- ('clean-tree', 'cleantree', False),
- ('lightweight-checkout', 'checkout', False),
+ ("url", "source", None),
+ ("clean-tree", "cleantree", False),
+ ("lightweight-checkout", "checkout", False),
]
scm_element = XML.SubElement(
- xml_parent, 'scm', {'class': 'hudson.plugins.bazaar.BazaarSCM'})
- helpers.convert_mapping_to_xml(
- scm_element, data, mapping, fail_required=True)
+ xml_parent, "scm", {"class": "hudson.plugins.bazaar.BazaarSCM"}
+ )
+ helpers.convert_mapping_to_xml(scm_element, data, mapping, fail_required=True)
- browser_name_to_class = {
- 'loggerhead': 'Loggerhead',
- 'opengrok': 'OpenGrok',
- }
- browser = data.get('browser', 'auto')
- if browser == 'auto':
+ browser_name_to_class = {"loggerhead": "Loggerhead", "opengrok": "OpenGrok"}
+ browser = data.get("browser", "auto")
+ if browser == "auto":
return
if browser not in browser_name_to_class:
- raise InvalidAttributeError('browser', browser,
- browser_name_to_class.keys())
+ raise InvalidAttributeError("browser", browser, browser_name_to_class.keys())
browser_element = XML.SubElement(
scm_element,
- 'browser',
- {'class': 'hudson.plugins.bazaar.browsers.{0}'.format(
- browser_name_to_class[browser])})
- mapping = [
- ('browser-url', 'url', None),
- ]
- helpers.convert_mapping_to_xml(
- browser_element, data, mapping, fail_required=True)
+ "browser",
+ {
+ "class": "hudson.plugins.bazaar.browsers.{0}".format(
+ browser_name_to_class[browser]
+ )
+ },
+ )
+ mapping = [("browser-url", "url", None)]
+ helpers.convert_mapping_to_xml(browser_element, data, mapping, fail_required=True)
- if browser == 'opengrok':
- mapping = [
- ('opengrok-root-module', 'rootModule', None),
- ]
- helpers.convert_mapping_to_xml(browser_element,
- data, mapping, fail_required=True)
+ if browser == "opengrok":
+ mapping = [("opengrok-root-module", "rootModule", None)]
+ helpers.convert_mapping_to_xml(
+ browser_element, data, mapping, fail_required=True
+ )
def url(registry, xml_parent, data):
@@ -1474,20 +1484,13 @@ def url(registry, xml_parent, data):
:language: yaml
"""
- scm = XML.SubElement(xml_parent, 'scm', {'class':
- 'hudson.plugins.URLSCM.URLSCM'})
- urls = XML.SubElement(scm, 'urls')
- for data_url in data['url-list']:
- url_tuple = XML.SubElement(
- urls, 'hudson.plugins.URLSCM.URLSCM_-URLTuple')
- mapping = [
- ('', 'urlString', data_url),
- ]
- helpers.convert_mapping_to_xml(
- url_tuple, data, mapping, fail_required=True)
- mapping = [
- ('clear-workspace', 'clearWorkspace', False),
- ]
+ scm = XML.SubElement(xml_parent, "scm", {"class": "hudson.plugins.URLSCM.URLSCM"})
+ urls = XML.SubElement(scm, "urls")
+ for data_url in data["url-list"]:
+ url_tuple = XML.SubElement(urls, "hudson.plugins.URLSCM.URLSCM_-URLTuple")
+ mapping = [("", "urlString", data_url)]
+ helpers.convert_mapping_to_xml(url_tuple, data, mapping, fail_required=True)
+ mapping = [("clear-workspace", "clearWorkspace", False)]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
@@ -1543,56 +1546,55 @@ def dimensions(registry, xml_parent, data):
"""
scm = XML.SubElement(
- xml_parent,
- 'scm', {'class': 'hudson.plugins.dimensionsscm.DimensionsSCM'})
+ xml_parent, "scm", {"class": "hudson.plugins.dimensionsscm.DimensionsSCM"}
+ )
# List to check against for valid permission
- perm = ['DEFAULT', 'READONLY', 'WRITABLE']
+ perm = ["DEFAULT", "READONLY", "WRITABLE"]
# List to check against for valid end of line
- eol = ['DEFAULT', 'UNIX', 'WINDOWS', 'UNCHANGED']
+ eol = ["DEFAULT", "UNIX", "WINDOWS", "UNCHANGED"]
mapping = [
# option, xml name, default value (text), attributes (hard coded)
- ('project', 'project', None),
- ('permissions', 'permissions', 'DEFAULT', perm),
- ('eol', 'eol', 'DEFAULT', eol),
- ('update', 'canJobUpdate', False),
- ('clear-workspace', 'canJobDelete', False),
- ('force-build', 'canJobForce', False),
- ('overwrite-modified', 'canJobRevert', False),
- ('expand-vars', 'canJobExpand', False),
- ('no-metadata', 'canJobNoMetadata', False),
- ('maintain-timestamp', 'canJobNoTouch', False),
- ('slave-checkout', 'forceAsSlave', False),
+ ("project", "project", None),
+ ("permissions", "permissions", "DEFAULT", perm),
+ ("eol", "eol", "DEFAULT", eol),
+ ("update", "canJobUpdate", False),
+ ("clear-workspace", "canJobDelete", False),
+ ("force-build", "canJobForce", False),
+ ("overwrite-modified", "canJobRevert", False),
+ ("expand-vars", "canJobExpand", False),
+ ("no-metadata", "canJobNoMetadata", False),
+ ("maintain-timestamp", "canJobNoTouch", False),
+ ("slave-checkout", "forceAsSlave", False),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
# Folders to monitor. Default '/'
- folders = XML.SubElement(scm, 'folders')
- if 'folders' in data:
- for folder in data['folders']:
- XML.SubElement(folders, 'string').text = folder
+ folders = XML.SubElement(scm, "folders")
+ if "folders" in data:
+ for folder in data["folders"]:
+ XML.SubElement(folders, "string").text = folder
else:
- XML.SubElement(folders, 'string').text = '/'
+ XML.SubElement(folders, "string").text = "/"
# Excluded paths
- exclude = XML.SubElement(scm, 'pathsToExclude')
- if 'exclude' in data:
- for exc in data['exclude']:
- XML.SubElement(exclude, 'string').text = exc
+ exclude = XML.SubElement(scm, "pathsToExclude")
+ if "exclude" in data:
+ for exc in data["exclude"]:
+ XML.SubElement(exclude, "string").text = exc
optional_mapping = [
# option, xml name, default value (text), attributes (hard coded)
- ('username', 'jobUserName', None),
- ('password', 'jobPasswd', None),
- ('server', 'jobServer', None),
- ('database', 'jobDatabase', None),
- ('timezone', 'jobTimeZone', None),
- ('web-url', 'jobWebUrl', None),
+ ("username", "jobUserName", None),
+ ("password", "jobPasswd", None),
+ ("server", "jobServer", None),
+ ("database", "jobDatabase", None),
+ ("timezone", "jobTimeZone", None),
+ ("web-url", "jobWebUrl", None),
]
- helpers.convert_mapping_to_xml(
- scm, data, optional_mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(scm, data, optional_mapping, fail_required=False)
def accurev(registry, xml_parent, data):
@@ -1630,61 +1632,61 @@ def accurev(registry, xml_parent, data):
.. literalinclude:: /../../tests/scm/fixtures/accurev001.yaml
"""
- scm = XML.SubElement(xml_parent,
- 'scm', {'class': 'hudson.plugins.accurev.AccurevSCM'})
+ scm = XML.SubElement(
+ xml_parent, "scm", {"class": "hudson.plugins.accurev.AccurevSCM"}
+ )
mapping = [
- ('depot', 'depot', None),
- ('stream', 'stream', None),
- ('server-name', 'serverName', None),
- ('ignore-parent-changes', 'ignoreStreamParent', False),
- ('clean-reference-tree', 'cleanreftree', False),
- ('build-from-snapshot', 'useSnapshot', False),
- ('do-not-pop-content', 'dontPopContent', False),
+ ("depot", "depot", None),
+ ("stream", "stream", None),
+ ("server-name", "serverName", None),
+ ("ignore-parent-changes", "ignoreStreamParent", False),
+ ("clean-reference-tree", "cleanreftree", False),
+ ("build-from-snapshot", "useSnapshot", False),
+ ("do-not-pop-content", "dontPopContent", False),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
additional_mapping = [
- ('workspace', 'workspace', None),
- ('reference-tree', 'reftree', None),
- ('directory-offset', 'directoryOffset', None),
- ('sub-path', 'subPath', None),
- ('filter-poll-scm', 'filterForPollSCM', None),
- ('snapshot-name-format', 'snapshotNameFormat', None),
+ ("workspace", "workspace", None),
+ ("reference-tree", "reftree", None),
+ ("directory-offset", "directoryOffset", None),
+ ("sub-path", "subPath", None),
+ ("filter-poll-scm", "filterForPollSCM", None),
+ ("snapshot-name-format", "snapshotNameFormat", None),
]
- helpers.convert_mapping_to_xml(
- scm, data, additional_mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(scm, data, additional_mapping, fail_required=False)
class SCM(jenkins_jobs.modules.base.Base):
sequence = 30
- component_type = 'scm'
- component_list_type = 'scm'
+ component_type = "scm"
+ component_list_type = "scm"
def gen_xml(self, xml_parent, data):
# multibranch-pipeline scm implementation is incompatible with SCM
- if data.get('project-type') in ['multibranch', 'multibranch-defaults']:
+ if data.get("project-type") in ["multibranch", "multibranch-defaults"]:
logging.debug("SCM Module skipped for multibranch project-type.")
return
- scms_parent = XML.Element('scms')
- for scm in data.get('scm', []):
- self.registry.dispatch('scm', scms_parent, scm)
+ scms_parent = XML.Element("scms")
+ for scm in data.get("scm", []):
+ self.registry.dispatch("scm", scms_parent, scm)
scms_count = len(scms_parent)
if scms_count == 0:
- XML.SubElement(xml_parent, 'scm', {'class': 'hudson.scm.NullSCM'})
+ XML.SubElement(xml_parent, "scm", {"class": "hudson.scm.NullSCM"})
elif scms_count == 1:
xml_parent.append(scms_parent[0])
else:
- class_name = 'org.jenkinsci.plugins.multiplescms.MultiSCM'
- xml_attribs = {'class': class_name}
- xml_parent = XML.SubElement(xml_parent, 'scm', xml_attribs)
+ class_name = "org.jenkinsci.plugins.multiplescms.MultiSCM"
+ xml_attribs = {"class": class_name}
+ xml_parent = XML.SubElement(xml_parent, "scm", xml_attribs)
for scms_child in scms_parent:
try:
- scms_child.tag = scms_child.attrib['class']
- del(scms_child.attrib['class'])
+ scms_child.tag = scms_child.attrib["class"]
+ del scms_child.attrib["class"]
except KeyError:
pass
@@ -1694,27 +1696,27 @@ class SCM(jenkins_jobs.modules.base.Base):
class PipelineSCM(jenkins_jobs.modules.base.Base):
sequence = 30
- component_type = 'pipeline-scm'
- component_list_type = 'pipeline-scm'
+ component_type = "pipeline-scm"
+ component_list_type = "pipeline-scm"
def gen_xml(self, xml_parent, data):
- definition_parent = xml_parent.find('definition')
+ definition_parent = xml_parent.find("definition")
pipeline_dict = data.get(self.component_type, {})
- scms = pipeline_dict.get('scm')
+ scms = pipeline_dict.get("scm")
if scms:
scms_count = len(scms)
if scms_count == 0:
raise JenkinsJobsException("'scm' missing or empty")
elif scms_count == 1:
- self.registry.dispatch('scm', definition_parent, scms[0])
+ self.registry.dispatch("scm", definition_parent, scms[0])
mapping = [
- ('script-path', 'scriptPath', 'Jenkinsfile'),
- ('lightweight-checkout', 'lightweight', None,
- [True, False]),
+ ("script-path", "scriptPath", "Jenkinsfile"),
+ ("lightweight-checkout", "lightweight", None, [True, False]),
]
helpers.convert_mapping_to_xml(
- definition_parent, pipeline_dict, mapping,
- fail_required=False)
+ definition_parent, pipeline_dict, mapping, fail_required=False
+ )
else:
- raise JenkinsJobsException('Only one SCM can be specified '
- 'as pipeline-scm')
+ raise JenkinsJobsException(
+ "Only one SCM can be specified " "as pipeline-scm"
+ )
diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py
index fcd93390..5831f4ba 100644
--- a/jenkins_jobs/modules/triggers.py
+++ b/jenkins_jobs/modules/triggers.py
@@ -53,8 +53,7 @@ def gerrit_handle_legacy_configuration(data):
def hyphenize(attr):
"""Convert strings like triggerOn to trigger-on.
"""
- return hyphenizer.sub(lambda x: "-%s" % x.group(0).lower(),
- attr)
+ return hyphenizer.sub(lambda x: "-%s" % x.group(0).lower(), attr)
def convert_dict(d, old_keys):
for old_key in old_keys:
@@ -62,150 +61,176 @@ def gerrit_handle_legacy_configuration(data):
new_key = hyphenize(old_key)
logger.warning(
"'%s' is deprecated and will be removed after "
- "1.0.0, please use '%s' instead", old_key, new_key)
+ "1.0.0, please use '%s' instead",
+ old_key,
+ new_key,
+ )
d[new_key] = d[old_key]
del d[old_key]
- convert_dict(data, [
- 'triggerOnPatchsetUploadedEvent',
- 'triggerOnChangeAbandonedEvent',
- 'triggerOnChangeMergedEvent',
- 'triggerOnChangeRestoredEvent',
- 'triggerOnCommentAddedEvent',
- 'triggerOnDraftPublishedEvent',
- 'triggerOnRefUpdatedEvent',
- 'triggerApprovalCategory',
- 'triggerApprovalValue',
- 'overrideVotes',
- 'gerritBuildSuccessfulVerifiedValue',
- 'gerritBuildFailedVerifiedValue',
- 'failureMessage',
- 'skipVote',
- ])
-
- for project in data.get('projects', []):
- convert_dict(project, [
- 'projectCompareType',
- 'projectPattern',
- 'branchCompareType',
- 'branchPattern',
- ])
+ convert_dict(
+ data,
+ [
+ "triggerOnPatchsetUploadedEvent",
+ "triggerOnChangeAbandonedEvent",
+ "triggerOnChangeMergedEvent",
+ "triggerOnChangeRestoredEvent",
+ "triggerOnCommentAddedEvent",
+ "triggerOnDraftPublishedEvent",
+ "triggerOnRefUpdatedEvent",
+ "triggerApprovalCategory",
+ "triggerApprovalValue",
+ "overrideVotes",
+ "gerritBuildSuccessfulVerifiedValue",
+ "gerritBuildFailedVerifiedValue",
+ "failureMessage",
+ "skipVote",
+ ],
+ )
+
+ for project in data.get("projects", []):
+ convert_dict(
+ project,
+ [
+ "projectCompareType",
+ "projectPattern",
+ "branchCompareType",
+ "branchPattern",
+ ],
+ )
mapping_obj_type = type(data)
old_format_events = mapping_obj_type(
- (key, should_register) for key, should_register in six.iteritems(data)
- if key.startswith('trigger-on-'))
- trigger_on = data.setdefault('trigger-on', [])
+ (key, should_register)
+ for key, should_register in six.iteritems(data)
+ if key.startswith("trigger-on-")
+ )
+ trigger_on = data.setdefault("trigger-on", [])
if old_format_events:
logger.warning(
"The events: %s; which you used is/are deprecated. "
"Please use 'trigger-on' instead.",
- ', '.join(old_format_events))
+ ", ".join(old_format_events),
+ )
if old_format_events and trigger_on:
raise JenkinsJobsException(
- 'Both, the new format (trigger-on) and old format (trigger-on-*) '
- 'gerrit events format found. Please use either the new or the old '
- 'format of trigger events definition.')
-
- trigger_on.extend(event_name[len('trigger-on-'):]
- for event_name, should_register
- in six.iteritems(old_format_events) if should_register)
+ "Both, the new format (trigger-on) and old format (trigger-on-*) "
+ "gerrit events format found. Please use either the new or the old "
+ "format of trigger events definition."
+ )
+
+ trigger_on.extend(
+ event_name[len("trigger-on-") :]
+ for event_name, should_register in six.iteritems(old_format_events)
+ if should_register
+ )
for idx, event in enumerate(trigger_on):
- if event == 'comment-added-event':
+ if event == "comment-added-event":
trigger_on[idx] = events = mapping_obj_type()
try:
- events['comment-added-event'] = mapping_obj_type((
- ('approval-category', data['trigger-approval-category']),
- ('approval-value', data['trigger-approval-value'])
- ))
+ events["comment-added-event"] = mapping_obj_type(
+ (
+ ("approval-category", data["trigger-approval-category"]),
+ ("approval-value", data["trigger-approval-value"]),
+ )
+ )
except KeyError:
raise JenkinsJobsException(
- 'The comment-added-event trigger requires which approval '
- 'category and value you want to trigger the job. '
- 'It should be specified by the approval-category '
- 'and approval-value properties.')
+ "The comment-added-event trigger requires which approval "
+ "category and value you want to trigger the job. "
+ "It should be specified by the approval-category "
+ "and approval-value properties."
+ )
def build_gerrit_triggers(xml_parent, data):
available_simple_triggers = {
- 'change-abandoned-event': 'PluginChangeAbandonedEvent',
- 'change-merged-event': 'PluginChangeMergedEvent',
- 'change-restored-event': 'PluginChangeRestoredEvent',
- 'draft-published-event': 'PluginDraftPublishedEvent',
- 'patchset-uploaded-event': 'PluginPatchsetCreatedEvent',
- 'patchset-created-event': 'PluginPatchsetCreatedEvent',
- 'ref-updated-event': 'PluginRefUpdatedEvent',
+ "change-abandoned-event": "PluginChangeAbandonedEvent",
+ "change-merged-event": "PluginChangeMergedEvent",
+ "change-restored-event": "PluginChangeRestoredEvent",
+ "draft-published-event": "PluginDraftPublishedEvent",
+ "patchset-uploaded-event": "PluginPatchsetCreatedEvent",
+ "patchset-created-event": "PluginPatchsetCreatedEvent",
+ "ref-updated-event": "PluginRefUpdatedEvent",
}
- tag_namespace = 'com.sonyericsson.hudson.plugins.gerrit.trigger.' \
- 'hudsontrigger.events'
+ tag_namespace = (
+ "com.sonyericsson.hudson.plugins.gerrit.trigger." "hudsontrigger.events"
+ )
- trigger_on_events = XML.SubElement(xml_parent, 'triggerOnEvents')
+ trigger_on_events = XML.SubElement(xml_parent, "triggerOnEvents")
- for event in data.get('trigger-on', []):
+ for event in data.get("trigger-on", []):
if isinstance(event, six.string_types):
tag_name = available_simple_triggers.get(event)
- if event == 'patchset-uploaded-event':
+ if event == "patchset-uploaded-event":
logger.warning(
"'%s' is deprecated. Use 'patchset-created-event' "
- "format instead.", event)
+ "format instead.",
+ event,
+ )
if not tag_name:
- known = ', '.join(available_simple_triggers.keys() +
- ['comment-added-event',
- 'comment-added-contains-event'])
- msg = ("The event '%s' under 'trigger-on' is not one of the "
- "known: %s.") % (event, known)
+ known = ", ".join(
+ available_simple_triggers.keys()
+ + ["comment-added-event", "comment-added-contains-event"]
+ )
+ msg = (
+ "The event '%s' under 'trigger-on' is not one of the " "known: %s."
+ ) % (event, known)
raise JenkinsJobsException(msg)
- XML.SubElement(trigger_on_events,
- '%s.%s' % (tag_namespace, tag_name))
+ XML.SubElement(trigger_on_events, "%s.%s" % (tag_namespace, tag_name))
else:
- if 'patchset-created-event' in event.keys():
- pce = event['patchset-created-event']
+ if "patchset-created-event" in event.keys():
+ pce = event["patchset-created-event"]
pc = XML.SubElement(
trigger_on_events,
- '%s.%s' % (tag_namespace, 'PluginPatchsetCreatedEvent'))
+ "%s.%s" % (tag_namespace, "PluginPatchsetCreatedEvent"),
+ )
mapping = [
- ('exclude-drafts', 'excludeDrafts', False),
- ('exclude-trivial-rebase', 'excludeTrivialRebase', False),
- ('exclude-no-code-change', 'excludeNoCodeChange', False),
+ ("exclude-drafts", "excludeDrafts", False),
+ ("exclude-trivial-rebase", "excludeTrivialRebase", False),
+ ("exclude-no-code-change", "excludeNoCodeChange", False),
]
- helpers.convert_mapping_to_xml(
- pc, pce, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(pc, pce, mapping, fail_required=True)
- if 'comment-added-event' in event.keys():
- comment_added_event = event['comment-added-event']
+ if "comment-added-event" in event.keys():
+ comment_added_event = event["comment-added-event"]
cadded = XML.SubElement(
trigger_on_events,
- '%s.%s' % (tag_namespace, 'PluginCommentAddedEvent'))
+ "%s.%s" % (tag_namespace, "PluginCommentAddedEvent"),
+ )
mapping = [
- ('approval-category', 'verdictCategory', None),
- ('approval-value',
- 'commentAddedTriggerApprovalValue', None),
+ ("approval-category", "verdictCategory", None),
+ ("approval-value", "commentAddedTriggerApprovalValue", None),
]
- helpers.convert_mapping_to_xml(cadded,
- comment_added_event, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ cadded, comment_added_event, mapping, fail_required=True
+ )
- if 'comment-added-contains-event' in event.keys():
- comment_added_event = event['comment-added-contains-event']
+ if "comment-added-contains-event" in event.keys():
+ comment_added_event = event["comment-added-contains-event"]
caddedc = XML.SubElement(
trigger_on_events,
- '%s.%s' % (tag_namespace,
- 'PluginCommentAddedContainsEvent'))
- XML.SubElement(caddedc, 'commentAddedCommentContains').text = \
- comment_added_event['comment-contains-value']
+ "%s.%s" % (tag_namespace, "PluginCommentAddedContainsEvent"),
+ )
+ XML.SubElement(
+ caddedc, "commentAddedCommentContains"
+ ).text = comment_added_event["comment-contains-value"]
def build_gerrit_skip_votes(xml_parent, data):
- outcomes = [('successful', 'onSuccessful'),
- ('failed', 'onFailed'),
- ('unstable', 'onUnstable'),
- ('notbuilt', 'onNotBuilt')]
+ outcomes = [
+ ("successful", "onSuccessful"),
+ ("failed", "onFailed"),
+ ("unstable", "onUnstable"),
+ ("notbuilt", "onNotBuilt"),
+ ]
- skip_vote_node = XML.SubElement(xml_parent, 'skipVote')
- skip_vote = data.get('skip-vote', {})
+ skip_vote_node = XML.SubElement(xml_parent, "skipVote")
+ skip_vote = data.get("skip-vote", {})
for result_kind, tag_name in outcomes:
setting = skip_vote.get(result_kind, False)
XML.SubElement(skip_vote_node, tag_name).text = str(setting).lower()
@@ -455,171 +480,198 @@ def gerrit(registry, xml_parent, data):
"""
def get_compare_type(xml_tag, compare_type):
- valid_compare_types = ['PLAIN',
- 'ANT',
- 'REG_EXP']
+ valid_compare_types = ["PLAIN", "ANT", "REG_EXP"]
if compare_type not in valid_compare_types:
- raise InvalidAttributeError(xml_tag, compare_type,
- valid_compare_types)
+ raise InvalidAttributeError(xml_tag, compare_type, valid_compare_types)
return compare_type
gerrit_handle_legacy_configuration(data)
- projects = data.get('projects', [])
- gtrig = XML.SubElement(xml_parent,
- 'com.sonyericsson.hudson.plugins.gerrit.trigger.'
- 'hudsontrigger.GerritTrigger')
- XML.SubElement(gtrig, 'spec')
- gprojects = XML.SubElement(gtrig, 'gerritProjects')
+ projects = data.get("projects", [])
+ gtrig = XML.SubElement(
+ xml_parent,
+ "com.sonyericsson.hudson.plugins.gerrit.trigger." "hudsontrigger.GerritTrigger",
+ )
+ XML.SubElement(gtrig, "spec")
+ gprojects = XML.SubElement(gtrig, "gerritProjects")
for project in projects:
- gproj = XML.SubElement(gprojects,
- 'com.sonyericsson.hudson.plugins.gerrit.'
- 'trigger.hudsontrigger.data.GerritProject')
- XML.SubElement(gproj, 'compareType').text = get_compare_type(
- 'project-compare-type', project.get(
- 'project-compare-type', 'PLAIN'))
- XML.SubElement(gproj, 'pattern').text = project['project-pattern']
-
- branches = XML.SubElement(gproj, 'branches')
- project_branches = project.get('branches', [])
-
- if 'branch-compare-type' in project and 'branch-pattern' in project:
- warning = 'branch-compare-type and branch-pattern at project ' \
- 'level are deprecated and support will be removed ' \
- 'in a later version of Jenkins Job Builder; '
+ gproj = XML.SubElement(
+ gprojects,
+ "com.sonyericsson.hudson.plugins.gerrit."
+ "trigger.hudsontrigger.data.GerritProject",
+ )
+ XML.SubElement(gproj, "compareType").text = get_compare_type(
+ "project-compare-type", project.get("project-compare-type", "PLAIN")
+ )
+ XML.SubElement(gproj, "pattern").text = project["project-pattern"]
+
+ branches = XML.SubElement(gproj, "branches")
+ project_branches = project.get("branches", [])
+
+ if "branch-compare-type" in project and "branch-pattern" in project:
+ warning = (
+ "branch-compare-type and branch-pattern at project "
+ "level are deprecated and support will be removed "
+ "in a later version of Jenkins Job Builder; "
+ )
if project_branches:
- warning += 'discarding values and using values from ' \
- 'branches section'
+ warning += "discarding values and using values from " "branches section"
else:
- warning += 'please use branches section instead'
+ warning += "please use branches section instead"
logger.warning(warning)
if not project_branches:
project_branches = [
- {'branch-compare-type': project.get(
- 'branch-compare-type', 'PLAIN'),
- 'branch-pattern': project['branch-pattern']}]
+ {
+ "branch-compare-type": project.get("branch-compare-type", "PLAIN"),
+ "branch-pattern": project["branch-pattern"],
+ }
+ ]
for branch in project_branches:
gbranch = XML.SubElement(
- branches, 'com.sonyericsson.hudson.plugins.'
- 'gerrit.trigger.hudsontrigger.data.Branch')
- XML.SubElement(gbranch, 'compareType').text = get_compare_type(
- 'branch-compare-type', branch.get(
- 'branch-compare-type', 'PLAIN'))
- XML.SubElement(gbranch, 'pattern').text = branch['branch-pattern']
-
- project_file_paths = project.get('file-paths', [])
+ branches,
+ "com.sonyericsson.hudson.plugins."
+ "gerrit.trigger.hudsontrigger.data.Branch",
+ )
+ XML.SubElement(gbranch, "compareType").text = get_compare_type(
+ "branch-compare-type", branch.get("branch-compare-type", "PLAIN")
+ )
+ XML.SubElement(gbranch, "pattern").text = branch["branch-pattern"]
+
+ project_file_paths = project.get("file-paths", [])
if project_file_paths:
- fps_tag = XML.SubElement(gproj, 'filePaths')
+ fps_tag = XML.SubElement(gproj, "filePaths")
for file_path in project_file_paths:
- fp_tag = XML.SubElement(fps_tag,
- 'com.sonyericsson.hudson.plugins.'
- 'gerrit.trigger.hudsontrigger.data.'
- 'FilePath')
- XML.SubElement(fp_tag, 'compareType').text = get_compare_type(
- 'compare-type', file_path.get('compare-type', 'PLAIN'))
- XML.SubElement(fp_tag, 'pattern').text = file_path['pattern']
-
- project_forbidden_file_paths = project.get('forbidden-file-paths', [])
+ fp_tag = XML.SubElement(
+ fps_tag,
+ "com.sonyericsson.hudson.plugins."
+ "gerrit.trigger.hudsontrigger.data."
+ "FilePath",
+ )
+ XML.SubElement(fp_tag, "compareType").text = get_compare_type(
+ "compare-type", file_path.get("compare-type", "PLAIN")
+ )
+ XML.SubElement(fp_tag, "pattern").text = file_path["pattern"]
+
+ project_forbidden_file_paths = project.get("forbidden-file-paths", [])
if project_forbidden_file_paths:
- ffps_tag = XML.SubElement(gproj, 'forbiddenFilePaths')
+ ffps_tag = XML.SubElement(gproj, "forbiddenFilePaths")
for forbidden_file_path in project_forbidden_file_paths:
- ffp_tag = XML.SubElement(ffps_tag,
- 'com.sonyericsson.hudson.plugins.'
- 'gerrit.trigger.hudsontrigger.data.'
- 'FilePath')
- XML.SubElement(ffp_tag, 'compareType').text = get_compare_type(
- 'compare-type', forbidden_file_path.get('compare-type',
- 'PLAIN'))
- XML.SubElement(ffp_tag, 'pattern').text = \
- forbidden_file_path['pattern']
-
- topics = project.get('topics', [])
+ ffp_tag = XML.SubElement(
+ ffps_tag,
+ "com.sonyericsson.hudson.plugins."
+ "gerrit.trigger.hudsontrigger.data."
+ "FilePath",
+ )
+ XML.SubElement(ffp_tag, "compareType").text = get_compare_type(
+ "compare-type", forbidden_file_path.get("compare-type", "PLAIN")
+ )
+ XML.SubElement(ffp_tag, "pattern").text = forbidden_file_path["pattern"]
+
+ topics = project.get("topics", [])
if topics:
- topics_tag = XML.SubElement(gproj, 'topics')
+ topics_tag = XML.SubElement(gproj, "topics")
for topic in topics:
- topic_tag = XML.SubElement(topics_tag,
- 'com.sonyericsson.hudson.plugins.'
- 'gerrit.trigger.hudsontrigger.data.'
- 'Topic')
- XML.SubElement(topic_tag, 'compareType').text = \
- get_compare_type('compare-type', topic.get('compare-type',
- 'PLAIN'))
- XML.SubElement(topic_tag, 'pattern').text = topic['pattern']
-
- XML.SubElement(gproj,
- 'disableStrictForbiddenFileVerification').text = str(
- project.get('disable-strict-forbidden-file-verification',
- False)).lower()
+ topic_tag = XML.SubElement(
+ topics_tag,
+ "com.sonyericsson.hudson.plugins."
+ "gerrit.trigger.hudsontrigger.data."
+ "Topic",
+ )
+ XML.SubElement(topic_tag, "compareType").text = get_compare_type(
+ "compare-type", topic.get("compare-type", "PLAIN")
+ )
+ XML.SubElement(topic_tag, "pattern").text = topic["pattern"]
+
+ XML.SubElement(gproj, "disableStrictForbiddenFileVerification").text = str(
+ project.get("disable-strict-forbidden-file-verification", False)
+ ).lower()
build_gerrit_skip_votes(gtrig, data)
general_mappings = [
- ('silent', 'silentMode', False),
- ('silent-start', 'silentStartMode', False),
- ('escape-quotes', 'escapeQuotes', True),
- ('no-name-and-email', 'noNameAndEmailParameters', False),
- ('readable-message', 'readableMessage', False),
- ('dependency-jobs', 'dependencyJobsNames', ''),
+ ("silent", "silentMode", False),
+ ("silent-start", "silentStartMode", False),
+ ("escape-quotes", "escapeQuotes", True),
+ ("no-name-and-email", "noNameAndEmailParameters", False),
+ ("readable-message", "readableMessage", False),
+ ("dependency-jobs", "dependencyJobsNames", ""),
]
- helpers.convert_mapping_to_xml(
- gtrig, data, general_mappings, fail_required=True)
- notification_levels = ['NONE', 'OWNER', 'OWNER_REVIEWERS', 'ALL',
- 'SERVER_DEFAULT']
- notification_level = data.get('notification-level', 'SERVER_DEFAULT')
+ helpers.convert_mapping_to_xml(gtrig, data, general_mappings, fail_required=True)
+ notification_levels = ["NONE", "OWNER", "OWNER_REVIEWERS", "ALL", "SERVER_DEFAULT"]
+ notification_level = data.get("notification-level", "SERVER_DEFAULT")
if notification_level not in notification_levels:
- raise InvalidAttributeError('notification-level', notification_level,
- notification_levels)
- if notification_level == 'SERVER_DEFAULT':
- XML.SubElement(gtrig, 'notificationLevel').text = ''
+ raise InvalidAttributeError(
+ "notification-level", notification_level, notification_levels
+ )
+ if notification_level == "SERVER_DEFAULT":
+ XML.SubElement(gtrig, "notificationLevel").text = ""
else:
- XML.SubElement(gtrig, 'notificationLevel').text = notification_level
- XML.SubElement(gtrig, 'dynamicTriggerConfiguration').text = str(
- data.get('dynamic-trigger-enabled', False))
- XML.SubElement(gtrig, 'triggerConfigURL').text = str(
- data.get('dynamic-trigger-url', ''))
- XML.SubElement(gtrig, 'triggerInformationAction').text = str(
- data.get('trigger-information-action', ''))
- XML.SubElement(gtrig, 'allowTriggeringUnreviewedPatches').text = str(
- data.get('trigger-for-unreviewed-patches', False)).lower()
+ XML.SubElement(gtrig, "notificationLevel").text = notification_level
+ XML.SubElement(gtrig, "dynamicTriggerConfiguration").text = str(
+ data.get("dynamic-trigger-enabled", False)
+ )
+ XML.SubElement(gtrig, "triggerConfigURL").text = str(
+ data.get("dynamic-trigger-url", "")
+ )
+ XML.SubElement(gtrig, "triggerInformationAction").text = str(
+ data.get("trigger-information-action", "")
+ )
+ XML.SubElement(gtrig, "allowTriggeringUnreviewedPatches").text = str(
+ data.get("trigger-for-unreviewed-patches", False)
+ ).lower()
build_gerrit_triggers(gtrig, data)
- override = str(data.get('override-votes', False)).lower()
- if override == 'true':
- for yamlkey, xmlkey in [('gerrit-build-started-verified-value',
- 'gerritBuildStartedVerifiedValue'),
- ('gerrit-build-successful-verified-value',
- 'gerritBuildSuccessfulVerifiedValue'),
- ('gerrit-build-failed-verified-value',
- 'gerritBuildFailedVerifiedValue'),
- ('gerrit-build-unstable-verified-value',
- 'gerritBuildUnstableVerifiedValue'),
- ('gerrit-build-notbuilt-verified-value',
- 'gerritBuildNotBuiltVerifiedValue'),
- ('gerrit-build-started-codereview-value',
- 'gerritBuildStartedCodeReviewValue'),
- ('gerrit-build-successful-codereview-value',
- 'gerritBuildSuccessfulCodeReviewValue'),
- ('gerrit-build-failed-codereview-value',
- 'gerritBuildFailedCodeReviewValue'),
- ('gerrit-build-unstable-codereview-value',
- 'gerritBuildUnstableCodeReviewValue'),
- ('gerrit-build-notbuilt-codereview-value',
- 'gerritBuildNotBuiltCodeReviewValue')]:
+ override = str(data.get("override-votes", False)).lower()
+ if override == "true":
+ for yamlkey, xmlkey in [
+ ("gerrit-build-started-verified-value", "gerritBuildStartedVerifiedValue"),
+ (
+ "gerrit-build-successful-verified-value",
+ "gerritBuildSuccessfulVerifiedValue",
+ ),
+ ("gerrit-build-failed-verified-value", "gerritBuildFailedVerifiedValue"),
+ (
+ "gerrit-build-unstable-verified-value",
+ "gerritBuildUnstableVerifiedValue",
+ ),
+ (
+ "gerrit-build-notbuilt-verified-value",
+ "gerritBuildNotBuiltVerifiedValue",
+ ),
+ (
+ "gerrit-build-started-codereview-value",
+ "gerritBuildStartedCodeReviewValue",
+ ),
+ (
+ "gerrit-build-successful-codereview-value",
+ "gerritBuildSuccessfulCodeReviewValue",
+ ),
+ (
+ "gerrit-build-failed-codereview-value",
+ "gerritBuildFailedCodeReviewValue",
+ ),
+ (
+ "gerrit-build-unstable-codereview-value",
+ "gerritBuildUnstableCodeReviewValue",
+ ),
+ (
+ "gerrit-build-notbuilt-codereview-value",
+ "gerritBuildNotBuiltCodeReviewValue",
+ ),
+ ]:
if data.get(yamlkey) is not None:
# str(int(x)) makes input values like '+1' work
- XML.SubElement(gtrig, xmlkey).text = str(
- int(data.get(yamlkey)))
+ XML.SubElement(gtrig, xmlkey).text = str(int(data.get(yamlkey)))
message_mappings = [
- ('start-message', 'buildStartMessage', ''),
- ('failure-message', 'buildFailureMessage', ''),
- ('successful-message', 'buildSuccessfulMessage', ''),
- ('unstable-message', 'buildUnstableMessage', ''),
- ('notbuilt-message', 'buildNotBuiltMessage', ''),
- ('failure-message-file', 'buildUnsuccessfulFilepath', ''),
- ('custom-url', 'customUrl', ''),
- ('server-name', 'serverName', '__ANY__'),
+ ("start-message", "buildStartMessage", ""),
+ ("failure-message", "buildFailureMessage", ""),
+ ("successful-message", "buildSuccessfulMessage", ""),
+ ("unstable-message", "buildUnstableMessage", ""),
+ ("notbuilt-message", "buildNotBuiltMessage", ""),
+ ("failure-message-file", "buildUnsuccessfulFilepath", ""),
+ ("custom-url", "customUrl", ""),
+ ("server-name", "serverName", "__ANY__"),
]
- helpers.convert_mapping_to_xml(
- gtrig, data, message_mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(gtrig, data, message_mappings, fail_required=True)
def dockerhub_notification(registry, xml_parent, data):
@@ -647,26 +699,32 @@ def dockerhub_notification(registry, xml_parent, data):
/../../tests/triggers/fixtures/dockerhub-notification-full.yaml
:language: yaml
"""
- dockerhub = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.'
- 'registry.notification.DockerHubTrigger')
- dockerhub.set('plugin', 'dockerhub-notification')
-
- option = XML.SubElement(dockerhub, 'options', {'class': 'vector'})
-
- if data.get('referenced-image'):
- XML.SubElement(option, 'org.jenkinsci.plugins.'
- 'registry.notification.'
- 'opt.impl.TriggerForAllUsedInJob')
- repos = data.get('repositories', [])
+ dockerhub = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins." "registry.notification.DockerHubTrigger"
+ )
+ dockerhub.set("plugin", "dockerhub-notification")
+
+ option = XML.SubElement(dockerhub, "options", {"class": "vector"})
+
+ if data.get("referenced-image"):
+ XML.SubElement(
+ option,
+ "org.jenkinsci.plugins."
+ "registry.notification."
+ "opt.impl.TriggerForAllUsedInJob",
+ )
+ repos = data.get("repositories", [])
if repos:
- specified_names = XML.SubElement(option,
- 'org.jenkinsci.plugins.registry.'
- 'notification.opt.impl.'
- 'TriggerOnSpecifiedImageNames')
-
- repo_tag = XML.SubElement(specified_names, 'repoNames')
+ specified_names = XML.SubElement(
+ option,
+ "org.jenkinsci.plugins.registry."
+ "notification.opt.impl."
+ "TriggerOnSpecifiedImageNames",
+ )
+
+ repo_tag = XML.SubElement(specified_names, "repoNames")
for repo in repos:
- XML.SubElement(repo_tag, 'string').text = repo
+ XML.SubElement(repo_tag, "string").text = repo
def pollscm(registry, xml_parent, data):
@@ -691,8 +749,8 @@ def pollscm(registry, xml_parent, data):
"""
try:
- cron = data['cron']
- ipch = str(data.get('ignore-post-commit-hooks', False)).lower()
+ cron = data["cron"]
+ ipch = str(data.get("ignore-post-commit-hooks", False)).lower()
except KeyError as e:
# ensure specific error on the attribute not being set is raised
# for new format
@@ -702,28 +760,38 @@ def pollscm(registry, xml_parent, data):
logger.warning(
"Your pollscm usage is deprecated, please use"
" the syntax described in the documentation"
- " instead")
+ " instead"
+ )
cron = data
- ipch = 'false'
-
- if not cron and cron != '':
- raise InvalidAttributeError('cron', cron)
-
- scmtrig = XML.SubElement(xml_parent, 'hudson.triggers.SCMTrigger')
- XML.SubElement(scmtrig, 'spec').text = cron
- XML.SubElement(scmtrig, 'ignorePostCommitHooks').text = ipch
-
-
-def build_content_type(xml_parent, entries, namespace, collection_suffix,
- entry_suffix, prefix, collection_name, element_name):
+ ipch = "false"
+
+ if not cron and cron != "":
+ raise InvalidAttributeError("cron", cron)
+
+ scmtrig = XML.SubElement(xml_parent, "hudson.triggers.SCMTrigger")
+ XML.SubElement(scmtrig, "spec").text = cron
+ XML.SubElement(scmtrig, "ignorePostCommitHooks").text = ipch
+
+
+def build_content_type(
+ xml_parent,
+ entries,
+ namespace,
+ collection_suffix,
+ entry_suffix,
+ prefix,
+ collection_name,
+ element_name,
+):
content_type = XML.SubElement(
- xml_parent, '{0}.{1}{2}'.format(namespace, prefix, collection_suffix))
+ xml_parent, "{0}.{1}{2}".format(namespace, prefix, collection_suffix)
+ )
if entries:
collection = XML.SubElement(content_type, collection_name)
for entry in entries:
content_entry = XML.SubElement(
- collection, '{0}.{1}{2}'.format(namespace, prefix,
- entry_suffix))
+ collection, "{0}.{1}{2}".format(namespace, prefix, entry_suffix)
+ )
XML.SubElement(content_entry, element_name).text = entry
@@ -768,65 +836,70 @@ def pollurl(registry, xml_parent, data):
.. literalinclude:: /../../tests/triggers/fixtures/pollurl001.yaml
"""
- namespace = 'org.jenkinsci.plugins.urltrigger.'
+ namespace = "org.jenkinsci.plugins.urltrigger."
valid_content_types = {
- 'simple': ['Simple', '', '', []],
- 'json': ['JSON', 'jsonPaths', 'jsonPath', None],
- 'text': ['TEXT', 'regExElements', 'regEx', None],
- 'xml': ['XML', 'xPaths', 'xPath', None]
+ "simple": ["Simple", "", "", []],
+ "json": ["JSON", "jsonPaths", "jsonPath", None],
+ "text": ["TEXT", "regExElements", "regEx", None],
+ "xml": ["XML", "xPaths", "xPath", None],
}
- urltrig = XML.SubElement(xml_parent,
- namespace + 'URLTrigger')
- node = data.get('polling-node')
- XML.SubElement(urltrig, 'spec').text = data.get('cron', '')
- XML.SubElement(urltrig, 'labelRestriction').text = str(bool(node)).lower()
+ urltrig = XML.SubElement(xml_parent, namespace + "URLTrigger")
+ node = data.get("polling-node")
+ XML.SubElement(urltrig, "spec").text = data.get("cron", "")
+ XML.SubElement(urltrig, "labelRestriction").text = str(bool(node)).lower()
if node:
- XML.SubElement(urltrig, 'triggerLabel').text = node
- entries = XML.SubElement(urltrig, 'entries')
- urls = data.get('urls', [])
+ XML.SubElement(urltrig, "triggerLabel").text = node
+ entries = XML.SubElement(urltrig, "entries")
+ urls = data.get("urls", [])
if not urls:
- raise JenkinsJobsException('At least one url must be provided')
+ raise JenkinsJobsException("At least one url must be provided")
mapping = [
- ('proxy', 'proxyActivated', False),
- ('timeout', 'timeout', 300),
- ('check-etag', 'checkETag', False),
- ('check-date', 'checkLastModificationDate', False)
+ ("proxy", "proxyActivated", False),
+ ("timeout", "timeout", 300),
+ ("check-etag", "checkETag", False),
+ ("check-date", "checkLastModificationDate", False),
]
for url in urls:
- entry = XML.SubElement(entries, namespace + 'URLTriggerEntry')
- XML.SubElement(entry, 'url').text = url['url']
- if 'username' in url:
- XML.SubElement(entry, 'username').text = url['username']
- if 'password' in url:
- XML.SubElement(entry, 'password').text = url['password']
- if 'check-status' in url:
- XML.SubElement(entry, 'checkStatus').text = 'true'
- mapping.append(('check-status', 'statusCode', ''))
+ entry = XML.SubElement(entries, namespace + "URLTriggerEntry")
+ XML.SubElement(entry, "url").text = url["url"]
+ if "username" in url:
+ XML.SubElement(entry, "username").text = url["username"]
+ if "password" in url:
+ XML.SubElement(entry, "password").text = url["password"]
+ if "check-status" in url:
+ XML.SubElement(entry, "checkStatus").text = "true"
+ mapping.append(("check-status", "statusCode", ""))
else:
- XML.SubElement(entry, 'checkStatus').text = 'false'
- XML.SubElement(entry, 'statusCode').text = '200'
-
- helpers.convert_mapping_to_xml(
- entry, url, mapping, fail_required=False)
- check_content = url.get('check-content', [])
- XML.SubElement(entry, 'inspectingContent').text = \
- str(bool(check_content)).lower()
- content_types = XML.SubElement(entry, 'contentTypes')
+ XML.SubElement(entry, "checkStatus").text = "false"
+ XML.SubElement(entry, "statusCode").text = "200"
+
+ helpers.convert_mapping_to_xml(entry, url, mapping, fail_required=False)
+ check_content = url.get("check-content", [])
+ XML.SubElement(entry, "inspectingContent").text = str(
+ bool(check_content)
+ ).lower()
+ content_types = XML.SubElement(entry, "contentTypes")
for entry in check_content:
type_name = next(iter(entry.keys()))
if type_name not in valid_content_types:
- raise JenkinsJobsException('check-content must be one of : %s'
- % ', '.join(valid_content_types.
- keys()))
+ raise JenkinsJobsException(
+ "check-content must be one of : %s"
+ % ", ".join(valid_content_types.keys())
+ )
content_type = valid_content_types.get(type_name)
if entry[type_name]:
sub_entries = content_type[3]
if sub_entries is None:
sub_entries = entry[type_name]
- build_content_type(content_types, sub_entries,
- namespace + 'content', 'ContentType',
- 'ContentEntry', *content_type[0:3])
+ build_content_type(
+ content_types,
+ sub_entries,
+ namespace + "content",
+ "ContentType",
+ "ContentEntry",
+ *content_type[0:3]
+ )
def jms_messaging(registry, xml_parent, data):
@@ -871,35 +944,30 @@ def jms_messaging(registry, xml_parent, data):
../../tests/triggers/fixtures/jms-messaging002.yaml
:language: yaml
"""
- namespace = 'com.redhat.jenkins.plugins.ci.'
- jmsm = XML.SubElement(xml_parent,
- namespace + 'CIBuildTrigger')
+ namespace = "com.redhat.jenkins.plugins.ci."
+ jmsm = XML.SubElement(xml_parent, namespace + "CIBuildTrigger")
- if 'override-topic' in data:
- overrides = XML.SubElement(jmsm, 'overrides')
- XML.SubElement(overrides,
- 'topic').text = str(data['override-topic'])
+ if "override-topic" in data:
+ overrides = XML.SubElement(jmsm, "overrides")
+ XML.SubElement(overrides, "topic").text = str(data["override-topic"])
mapping = [
# option, xml name, default value
- ("spec", 'spec', ''),
- ("selector", 'selector', ''),
- ("provider-name", 'providerName', ''),
+ ("spec", "spec", ""),
+ ("selector", "selector", ""),
+ ("provider-name", "providerName", ""),
]
helpers.convert_mapping_to_xml(jmsm, data, mapping, fail_required=True)
- checks = data.get('checks', [])
+ checks = data.get("checks", [])
if len(checks) > 0:
- msgchecks = XML.SubElement(jmsm, 'checks')
+ msgchecks = XML.SubElement(jmsm, "checks")
for check in checks:
- msgcheck = XML.SubElement(msgchecks, namespace +
- 'messaging.checks.MsgCheck')
- mapping = [
- ('field', 'field', ''),
- ('expected-value', 'expectedValue', ''),
- ]
- helpers.convert_mapping_to_xml(
- msgcheck, check, mapping, fail_required=True)
+ msgcheck = XML.SubElement(
+ msgchecks, namespace + "messaging.checks.MsgCheck"
+ )
+ mapping = [("field", "field", ""), ("expected-value", "expectedValue", "")]
+ helpers.convert_mapping_to_xml(msgcheck, check, mapping, fail_required=True)
def timed(registry, xml_parent, data):
@@ -913,8 +981,8 @@ def timed(registry, xml_parent, data):
triggers:
- timed: "@midnight"
"""
- scmtrig = XML.SubElement(xml_parent, 'hudson.triggers.TimerTrigger')
- XML.SubElement(scmtrig, 'spec').text = data
+ scmtrig = XML.SubElement(xml_parent, "hudson.triggers.TimerTrigger")
+ XML.SubElement(scmtrig, "spec").text = data
def bitbucket(registry, xml_parent, data):
@@ -927,9 +995,10 @@ def bitbucket(registry, xml_parent, data):
.. literalinclude:: /../../tests/triggers/fixtures/bitbucket.yaml
"""
- bbtrig = XML.SubElement(xml_parent, 'com.cloudbees.jenkins.'
- 'plugins.BitBucketTrigger')
- XML.SubElement(bbtrig, 'spec').text = ''
+ bbtrig = XML.SubElement(
+ xml_parent, "com.cloudbees.jenkins." "plugins.BitBucketTrigger"
+ )
+ XML.SubElement(bbtrig, "spec").text = ""
def github(registry, xml_parent, data):
@@ -942,9 +1011,8 @@ def github(registry, xml_parent, data):
triggers:
- github
"""
- ghtrig = XML.SubElement(xml_parent, 'com.cloudbees.jenkins.'
- 'GitHubPushTrigger')
- XML.SubElement(ghtrig, 'spec').text = ''
+ ghtrig = XML.SubElement(xml_parent, "com.cloudbees.jenkins." "GitHubPushTrigger")
+ XML.SubElement(ghtrig, "spec").text = ""
def github_pull_request(registry, xml_parent, data):
@@ -1028,183 +1096,174 @@ def github_pull_request(registry, xml_parent, data):
/../../tests/triggers/fixtures/github-pull-request-minimal.yaml
:language: yaml
"""
- ghprb = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.ghprb.'
- 'GhprbTrigger')
+ ghprb = XML.SubElement(xml_parent, "org.jenkinsci.plugins.ghprb." "GhprbTrigger")
mapping = [
- ('cron', 'spec', ''),
- ('allow-whitelist-orgs-as-admins',
- 'allowMembersOfWhitelistedOrgsAsAdmin', False),
- ('cron', 'cron', ''),
- ('trigger-phrase', 'triggerPhrase', ''),
- ('skip-build-phrase', 'skipBuildPhrase', ''),
- ('only-trigger-phrase', 'onlyTriggerPhrase', False),
- ('github-hooks', 'useGitHubHooks', False),
- ('permit-all', 'permitAll', False),
- ('auto-close-on-fail',
- 'autoCloseFailedPullRequests', False),
+ ("cron", "spec", ""),
+ (
+ "allow-whitelist-orgs-as-admins",
+ "allowMembersOfWhitelistedOrgsAsAdmin",
+ False,
+ ),
+ ("cron", "cron", ""),
+ ("trigger-phrase", "triggerPhrase", ""),
+ ("skip-build-phrase", "skipBuildPhrase", ""),
+ ("only-trigger-phrase", "onlyTriggerPhrase", False),
+ ("github-hooks", "useGitHubHooks", False),
+ ("permit-all", "permitAll", False),
+ ("auto-close-on-fail", "autoCloseFailedPullRequests", False),
]
- admin_string = "\n".join(data.get('admin-list', []))
- XML.SubElement(ghprb, 'adminlist').text = admin_string
- white_string = "\n".join(data.get('white-list', []))
- XML.SubElement(ghprb, 'whitelist').text = white_string
- org_string = "\n".join(data.get('org-list', []))
- XML.SubElement(ghprb, 'orgslist').text = org_string
- white_list_labels_string = "\n".join(data.get('white-list-labels', []))
- XML.SubElement(ghprb, 'whiteListLabels').text = white_list_labels_string
- black_list_labels_string = "\n".join(data.get('black-list-labels', []))
- XML.SubElement(ghprb, 'blackListLabels').text = black_list_labels_string
- excluded_regions_string = "\n".join(data.get('excluded-regions', []))
- XML.SubElement(ghprb, 'excludedRegions').text = excluded_regions_string
- included_regions_string = "\n".join(data.get('included-regions', []))
- XML.SubElement(ghprb, 'includedRegions').text = included_regions_string
-
- build_desc_template = data.get('build-desc-template', '')
+ admin_string = "\n".join(data.get("admin-list", []))
+ XML.SubElement(ghprb, "adminlist").text = admin_string
+ white_string = "\n".join(data.get("white-list", []))
+ XML.SubElement(ghprb, "whitelist").text = white_string
+ org_string = "\n".join(data.get("org-list", []))
+ XML.SubElement(ghprb, "orgslist").text = org_string
+ white_list_labels_string = "\n".join(data.get("white-list-labels", []))
+ XML.SubElement(ghprb, "whiteListLabels").text = white_list_labels_string
+ black_list_labels_string = "\n".join(data.get("black-list-labels", []))
+ XML.SubElement(ghprb, "blackListLabels").text = black_list_labels_string
+ excluded_regions_string = "\n".join(data.get("excluded-regions", []))
+ XML.SubElement(ghprb, "excludedRegions").text = excluded_regions_string
+ included_regions_string = "\n".join(data.get("included-regions", []))
+ XML.SubElement(ghprb, "includedRegions").text = included_regions_string
+
+ build_desc_template = data.get("build-desc-template", "")
if build_desc_template:
- XML.SubElement(ghprb, 'buildDescTemplate').text = str(
- build_desc_template)
+ XML.SubElement(ghprb, "buildDescTemplate").text = str(build_desc_template)
- helpers.convert_mapping_to_xml(
- ghprb, data, mapping, fail_required=False)
- white_list_target_branches = data.get('white-list-target-branches', [])
+ helpers.convert_mapping_to_xml(ghprb, data, mapping, fail_required=False)
+ white_list_target_branches = data.get("white-list-target-branches", [])
if white_list_target_branches:
- ghprb_wltb = XML.SubElement(ghprb, 'whiteListTargetBranches')
+ ghprb_wltb = XML.SubElement(ghprb, "whiteListTargetBranches")
for branch in white_list_target_branches:
- be = XML.SubElement(ghprb_wltb, 'org.jenkinsci.plugins.'
- 'ghprb.GhprbBranch')
- XML.SubElement(be, 'branch').text = str(branch)
+ be = XML.SubElement(
+ ghprb_wltb, "org.jenkinsci.plugins." "ghprb.GhprbBranch"
+ )
+ XML.SubElement(be, "branch").text = str(branch)
- black_list_target_branches = data.get('black-list-target-branches', [])
+ black_list_target_branches = data.get("black-list-target-branches", [])
if black_list_target_branches:
- ghprb_bltb = XML.SubElement(ghprb, 'blackListTargetBranches')
+ ghprb_bltb = XML.SubElement(ghprb, "blackListTargetBranches")
for branch in black_list_target_branches:
- be = XML.SubElement(ghprb_bltb, 'org.jenkinsci.plugins.'
- 'ghprb.GhprbBranch')
- XML.SubElement(be, 'branch').text = str(branch)
+ be = XML.SubElement(
+ ghprb_bltb, "org.jenkinsci.plugins." "ghprb.GhprbBranch"
+ )
+ XML.SubElement(be, "branch").text = str(branch)
- auth_id = data.get('auth-id', '')
+ auth_id = data.get("auth-id", "")
if auth_id:
- XML.SubElement(ghprb, 'gitHubAuthId').text = str(auth_id)
+ XML.SubElement(ghprb, "gitHubAuthId").text = str(auth_id)
# PR status update fields
- status_context = data.get('status-context', '')
- triggered_status = data.get('triggered-status', '')
- started_status = data.get('started-status', '')
- status_url = data.get('status-url', '')
- status_add_test_results = data.get('status-add-test-results', '')
- success_status = data.get('success-status', '')
- failure_status = data.get('failure-status', '')
- error_status = data.get('error-status', '')
+ status_context = data.get("status-context", "")
+ triggered_status = data.get("triggered-status", "")
+ started_status = data.get("started-status", "")
+ status_url = data.get("status-url", "")
+ status_add_test_results = data.get("status-add-test-results", "")
+ success_status = data.get("success-status", "")
+ failure_status = data.get("failure-status", "")
+ error_status = data.get("error-status", "")
# is status handling is required?
requires_status = (
- status_context or
- triggered_status or
- started_status or
- status_url or
- status_add_test_results or
- success_status or
- failure_status or
- error_status
+ status_context
+ or triggered_status
+ or started_status
+ or status_url
+ or status_add_test_results
+ or success_status
+ or failure_status
+ or error_status
)
# is status message handling required?
- requires_status_message = (
- success_status or
- failure_status or
- error_status
- )
+ requires_status_message = success_status or failure_status or error_status
# is comment handling required?
- success_comment = data.get('success-comment', '')
- failure_comment = data.get('failure-comment', '')
- error_comment = data.get('error-comment', '')
- requires_job_comment = (
- success_comment or
- failure_comment or
- error_comment
- )
+ success_comment = data.get("success-comment", "")
+ failure_comment = data.get("failure-comment", "")
+ error_comment = data.get("error-comment", "")
+ requires_job_comment = success_comment or failure_comment or error_comment
# When the value of cancel-builds-on-update comes from deep_formatter,
# the value is of type 'str', otherwise the value is of type 'bool'
- cancel_builds_on_update = str(
- data.get('cancel-builds-on-update', False)).lower() == 'true'
+ cancel_builds_on_update = (
+ str(data.get("cancel-builds-on-update", False)).lower() == "true"
+ )
# We want to have only one 'extensions' subelement, even if status
# handling, comment handling and other extensions are enabled.
if requires_status or requires_job_comment or cancel_builds_on_update:
- extensions = XML.SubElement(ghprb, 'extensions')
+ extensions = XML.SubElement(ghprb, "extensions")
# Both comment and status elements have this same type. Using a const is
# much easier to read than repeating the tokens for this class each time
# it's used
- comment_type = 'org.jenkinsci.plugins.ghprb.extensions.comments.'
- comment_type = comment_type + 'GhprbBuildResultMessage'
+ comment_type = "org.jenkinsci.plugins.ghprb.extensions.comments."
+ comment_type = comment_type + "GhprbBuildResultMessage"
if requires_status:
- simple_status = XML.SubElement(extensions,
- 'org.jenkinsci.plugins'
- '.ghprb.extensions.status.'
- 'GhprbSimpleStatus')
+ simple_status = XML.SubElement(
+ extensions,
+ "org.jenkinsci.plugins" ".ghprb.extensions.status." "GhprbSimpleStatus",
+ )
if status_context:
- XML.SubElement(simple_status, 'commitStatusContext').text = str(
- status_context)
+ XML.SubElement(simple_status, "commitStatusContext").text = str(
+ status_context
+ )
if triggered_status:
- XML.SubElement(simple_status, 'triggeredStatus').text = str(
- triggered_status)
+ XML.SubElement(simple_status, "triggeredStatus").text = str(
+ triggered_status
+ )
if started_status:
- XML.SubElement(simple_status, 'startedStatus').text = str(
- started_status)
+ XML.SubElement(simple_status, "startedStatus").text = str(started_status)
if status_url:
- XML.SubElement(simple_status, 'statusUrl').text = str(
- status_url)
+ XML.SubElement(simple_status, "statusUrl").text = str(status_url)
if status_add_test_results:
- XML.SubElement(simple_status, 'addTestResults').text = str(
- status_add_test_results).lower()
+ XML.SubElement(simple_status, "addTestResults").text = str(
+ status_add_test_results
+ ).lower()
if requires_status_message:
- completed_elem = XML.SubElement(simple_status, 'completedStatus')
+ completed_elem = XML.SubElement(simple_status, "completedStatus")
if success_status:
success_elem = XML.SubElement(completed_elem, comment_type)
- XML.SubElement(success_elem, 'message').text = str(
- success_status)
- XML.SubElement(success_elem, 'result').text = 'SUCCESS'
+ XML.SubElement(success_elem, "message").text = str(success_status)
+ XML.SubElement(success_elem, "result").text = "SUCCESS"
if failure_status:
failure_elem = XML.SubElement(completed_elem, comment_type)
- XML.SubElement(failure_elem, 'message').text = str(
- failure_status)
- XML.SubElement(failure_elem, 'result').text = 'FAILURE'
+ XML.SubElement(failure_elem, "message").text = str(failure_status)
+ XML.SubElement(failure_elem, "result").text = "FAILURE"
if error_status:
error_elem = XML.SubElement(completed_elem, comment_type)
- XML.SubElement(error_elem, 'message').text = str(error_status)
- XML.SubElement(error_elem, 'result').text = 'ERROR'
+ XML.SubElement(error_elem, "message").text = str(error_status)
+ XML.SubElement(error_elem, "result").text = "ERROR"
# job comment handling
if requires_job_comment:
- build_status = XML.SubElement(extensions,
- 'org.jenkinsci.plugins.ghprb.extensions'
- '.comments.'
- 'GhprbBuildStatus')
- messages_elem = XML.SubElement(build_status, 'messages')
+ build_status = XML.SubElement(
+ extensions,
+ "org.jenkinsci.plugins.ghprb.extensions" ".comments." "GhprbBuildStatus",
+ )
+ messages_elem = XML.SubElement(build_status, "messages")
if success_comment:
success_comment_elem = XML.SubElement(messages_elem, comment_type)
- XML.SubElement(success_comment_elem, 'message').text = str(
- success_comment)
- XML.SubElement(success_comment_elem, 'result').text = 'SUCCESS'
+ XML.SubElement(success_comment_elem, "message").text = str(success_comment)
+ XML.SubElement(success_comment_elem, "result").text = "SUCCESS"
if failure_comment:
failure_comment_elem = XML.SubElement(messages_elem, comment_type)
- XML.SubElement(failure_comment_elem, 'message').text = str(
- failure_comment)
- XML.SubElement(failure_comment_elem, 'result').text = 'FAILURE'
+ XML.SubElement(failure_comment_elem, "message").text = str(failure_comment)
+ XML.SubElement(failure_comment_elem, "result").text = "FAILURE"
if error_comment:
error_comment_elem = XML.SubElement(messages_elem, comment_type)
- XML.SubElement(error_comment_elem, 'message').text = str(
- error_comment)
- XML.SubElement(error_comment_elem, 'result').text = 'ERROR'
+ XML.SubElement(error_comment_elem, "message").text = str(error_comment)
+ XML.SubElement(error_comment_elem, "result").text = "ERROR"
if cancel_builds_on_update:
- XML.SubElement(extensions,
- 'org.jenkinsci.plugins.ghprb.extensions.'
- 'build.GhprbCancelBuildsOnUpdate')
+ XML.SubElement(
+ extensions,
+ "org.jenkinsci.plugins.ghprb.extensions." "build.GhprbCancelBuildsOnUpdate",
+ )
def gitlab_merge_request(registry, xml_parent, data):
@@ -1246,26 +1305,28 @@ def gitlab_merge_request(registry, xml_parent, data):
.. literalinclude:: \
/../../tests/triggers/fixtures/gitlab-merge-request002.yaml
"""
- ghprb = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.gitlab.'
- 'GitlabBuildTrigger')
+ ghprb = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.gitlab." "GitlabBuildTrigger"
+ )
- plugin_info = registry.get_plugin_info('Gitlab Merge Request Builder')
+ plugin_info = registry.get_plugin_info("Gitlab Merge Request Builder")
# Note: Assume latest version of plugin is preferred config format
plugin_ver = pkg_resources.parse_version(
- plugin_info.get('version', str(sys.maxsize)))
+ plugin_info.get("version", str(sys.maxsize))
+ )
if plugin_ver >= pkg_resources.parse_version("2.0.0"):
mapping = [
- ('cron', 'spec', None),
- ('project-path', 'projectPath', None),
- ('target-branch-regex', 'targetBranchRegex', ''),
- ('use-http-url', 'useHttpUrl', False),
- ('assignee-filter', 'assigneeFilter', 'jenkins'),
- ('tag-filter', 'tagFilter', 'Build'),
- ('trigger-comment', 'triggerComment', ''),
- ('auto-close-failed', 'autoCloseFailed', False),
- ('auto-merge-passed', 'autoMergePassed', False),
+ ("cron", "spec", None),
+ ("project-path", "projectPath", None),
+ ("target-branch-regex", "targetBranchRegex", ""),
+ ("use-http-url", "useHttpUrl", False),
+ ("assignee-filter", "assigneeFilter", "jenkins"),
+ ("tag-filter", "tagFilter", "Build"),
+ ("trigger-comment", "triggerComment", ""),
+ ("auto-close-failed", "autoCloseFailed", False),
+ ("auto-merge-passed", "autoMergePassed", False),
]
else:
# The plugin version is < 2.0.0
@@ -1275,17 +1336,16 @@ def gitlab_merge_request(registry, xml_parent, data):
# have them take effect. Also, cron and projectPath are prefixed with
# underscores in the plugin, but spec is not.
mapping = [
- ('cron', 'spec', None),
- ('cron', '__cron', None),
- ('project-path', '__projectPath', None),
- ('use-http-url', '__useHttpUrl', False),
- ('assignee-filter', '__assigneeFilter', 'jenkins'),
- ('tag-filter', '__tagFilter', 'Build'),
- ('trigger-comment', '__triggerComment', ''),
- ('publish-build-progress-messages',
- '__publishBuildProgressMessages', True),
- ('auto-close-failed', '__autoCloseFailed', False),
- ('auto-merge-passed', '__autoMergePassed', False),
+ ("cron", "spec", None),
+ ("cron", "__cron", None),
+ ("project-path", "__projectPath", None),
+ ("use-http-url", "__useHttpUrl", False),
+ ("assignee-filter", "__assigneeFilter", "jenkins"),
+ ("tag-filter", "__tagFilter", "Build"),
+ ("trigger-comment", "__triggerComment", ""),
+ ("publish-build-progress-messages", "__publishBuildProgressMessages", True),
+ ("auto-close-failed", "__autoCloseFailed", False),
+ ("auto-merge-passed", "__autoMergePassed", False),
]
helpers.convert_mapping_to_xml(ghprb, data, mapping, True)
@@ -1381,82 +1441,77 @@ def gitlab(registry, xml_parent, data):
.. literalinclude:: /../../tests/triggers/fixtures/gitlab004.yaml
:language: yaml
"""
+
def _add_xml(elem, name, value):
XML.SubElement(elem, name).text = value
gitlab = XML.SubElement(
- xml_parent, 'com.dabsquared.gitlabjenkins.GitLabPushTrigger'
+ xml_parent, "com.dabsquared.gitlabjenkins.GitLabPushTrigger"
)
- plugin_info = registry.get_plugin_info('GitLab Plugin')
+ plugin_info = registry.get_plugin_info("GitLab Plugin")
# Note: Assume latest version of plugin is preferred config format
plugin_ver = pkg_resources.parse_version(
- plugin_info.get('version', str(sys.maxsize)))
+ plugin_info.get("version", str(sys.maxsize))
+ )
- valid_merge_request = ['never', 'source', 'both']
+ valid_merge_request = ["never", "source", "both"]
if plugin_ver >= pkg_resources.parse_version("1.1.26"):
mapping = [
- ('trigger-open-merge-request-push',
- 'triggerOpenMergeRequestOnPush', 'never', valid_merge_request),
+ (
+ "trigger-open-merge-request-push",
+ "triggerOpenMergeRequestOnPush",
+ "never",
+ valid_merge_request,
+ )
]
- helpers.convert_mapping_to_xml(
- gitlab, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
else:
mapping = [
- ('trigger-open-merge-request-push',
- 'triggerOpenMergeRequestOnPush', True),
- ]
- helpers.convert_mapping_to_xml(
- gitlab, data, mapping, fail_required=True)
-
- if plugin_ver < pkg_resources.parse_version('1.2.0'):
- if data.get('branch-filter-type', '') == 'All':
- data['branch-filter-type'] = ''
- valid_filters = ['', 'NameBasedFilter', 'RegexBasedFilter']
- mapping = [
- ('branch-filter-type', 'branchFilterName', '', valid_filters),
+ ("trigger-open-merge-request-push", "triggerOpenMergeRequestOnPush", True)
]
- helpers.convert_mapping_to_xml(
- gitlab, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
+
+ if plugin_ver < pkg_resources.parse_version("1.2.0"):
+ if data.get("branch-filter-type", "") == "All":
+ data["branch-filter-type"] = ""
+ valid_filters = ["", "NameBasedFilter", "RegexBasedFilter"]
+ mapping = [("branch-filter-type", "branchFilterName", "", valid_filters)]
+ helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
else:
- valid_filters = ['All', 'NameBasedFilter', 'RegexBasedFilter']
- mapping = [
- ('branch-filter-type', 'branchFilterType', 'All', valid_filters),
- ]
- helpers.convert_mapping_to_xml(
- gitlab, data, mapping, fail_required=True)
+ valid_filters = ["All", "NameBasedFilter", "RegexBasedFilter"]
+ mapping = [("branch-filter-type", "branchFilterType", "All", valid_filters)]
+ helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
- XML.SubElement(gitlab, 'spec').text = ''
+ XML.SubElement(gitlab, "spec").text = ""
mapping = [
- ('trigger-push', 'triggerOnPush', True),
- ('trigger-merge-request', 'triggerOnMergeRequest', True),
- ('trigger-accepted-merge-request', 'triggerOnAcceptedMergeRequest',
- False),
- ('trigger-closed-merge-request', 'triggerOnClosedMergeRequest', False),
- ('trigger-note', 'triggerOnNoteRequest', True),
- ('note-regex', 'noteRegex', 'Jenkins please retry a build'),
- ('ci-skip', 'ciSkip', True),
- ('wip-skip', 'skipWorkInProgressMergeRequest', True),
- ('set-build-description', 'setBuildDescription', True),
- ('add-note-merge-request', 'addNoteOnMergeRequest', True),
- ('add-vote-merge-request', 'addVoteOnMergeRequest', True),
- ('accept-merge-request-on-success', 'acceptMergeRequestOnSuccess',
- False),
- ('add-ci-message', 'addCiMessage', False),
- ('allow-all-branches', 'allowAllBranches', False),
- ('target-branch-regex', 'targetBranchRegex', ''),
- ('secret-token', 'secretToken', '')
+ ("trigger-push", "triggerOnPush", True),
+ ("trigger-merge-request", "triggerOnMergeRequest", True),
+ ("trigger-accepted-merge-request", "triggerOnAcceptedMergeRequest", False),
+ ("trigger-closed-merge-request", "triggerOnClosedMergeRequest", False),
+ ("trigger-note", "triggerOnNoteRequest", True),
+ ("note-regex", "noteRegex", "Jenkins please retry a build"),
+ ("ci-skip", "ciSkip", True),
+ ("wip-skip", "skipWorkInProgressMergeRequest", True),
+ ("set-build-description", "setBuildDescription", True),
+ ("add-note-merge-request", "addNoteOnMergeRequest", True),
+ ("add-vote-merge-request", "addVoteOnMergeRequest", True),
+ ("accept-merge-request-on-success", "acceptMergeRequestOnSuccess", False),
+ ("add-ci-message", "addCiMessage", False),
+ ("allow-all-branches", "allowAllBranches", False),
+ ("target-branch-regex", "targetBranchRegex", ""),
+ ("secret-token", "secretToken", ""),
]
list_mapping = (
- ('include-branches', 'includeBranchesSpec', []),
- ('exclude-branches', 'excludeBranchesSpec', []),
+ ("include-branches", "includeBranchesSpec", []),
+ ("exclude-branches", "excludeBranchesSpec", []),
)
helpers.convert_mapping_to_xml(gitlab, data, mapping, fail_required=True)
for yaml_name, xml_name, default_val in list_mapping:
- value = ', '.join(data.get(yaml_name, default_val))
+ value = ", ".join(data.get(yaml_name, default_val))
_add_xml(gitlab, xml_name, value)
@@ -1487,40 +1542,40 @@ def build_result(registry, xml_parent, data):
/../../tests/triggers/fixtures/build-result-minimal.yaml
:language: yaml
"""
- brt = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.'
- 'buildresulttrigger.BuildResultTrigger')
- brt.set('plugin', 'buildresult-trigger')
- mapping = [
- ('cron', 'spec', ''),
- ('combine', 'combinedJobs', False),
- ]
+ brt = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins." "buildresulttrigger.BuildResultTrigger"
+ )
+ brt.set("plugin", "buildresult-trigger")
+ mapping = [("cron", "spec", ""), ("combine", "combinedJobs", False)]
helpers.convert_mapping_to_xml(brt, data, mapping, fail_required=True)
- jobs_info = XML.SubElement(brt, 'jobsInfo')
- result_dict = {'success': 'SUCCESS',
- 'unstable': 'UNSTABLE',
- 'failure': 'FAILURE',
- 'not-built': 'NOT_BUILT',
- 'aborted': 'ABORTED'}
- for group in data['groups']:
- brti = XML.SubElement(jobs_info, 'org.jenkinsci.plugins.'
- 'buildresulttrigger.model.'
- 'BuildResultTriggerInfo')
- jobs_string = ",".join(group['jobs'])
- mapping = [
- ('', 'jobNames', jobs_string, group),
- ]
- helpers.convert_mapping_to_xml(
- brti, group, mapping, fail_required=True)
- checked_results = XML.SubElement(brti, 'checkedResults')
- for result in group.get('results', ['success']):
- model_checked = XML.SubElement(checked_results, 'org.jenkinsci.'
- 'plugins.buildresulttrigger.model.'
- 'CheckedResult')
- mapping = [
- ('', 'checked', result, result_dict),
- ]
+ jobs_info = XML.SubElement(brt, "jobsInfo")
+ result_dict = {
+ "success": "SUCCESS",
+ "unstable": "UNSTABLE",
+ "failure": "FAILURE",
+ "not-built": "NOT_BUILT",
+ "aborted": "ABORTED",
+ }
+ for group in data["groups"]:
+ brti = XML.SubElement(
+ jobs_info,
+ "org.jenkinsci.plugins."
+ "buildresulttrigger.model."
+ "BuildResultTriggerInfo",
+ )
+ jobs_string = ",".join(group["jobs"])
+ mapping = [("", "jobNames", jobs_string, group)]
+ helpers.convert_mapping_to_xml(brti, group, mapping, fail_required=True)
+ checked_results = XML.SubElement(brti, "checkedResults")
+ for result in group.get("results", ["success"]):
+ model_checked = XML.SubElement(
+ checked_results,
+ "org.jenkinsci." "plugins.buildresulttrigger.model." "CheckedResult",
+ )
+ mapping = [("", "checked", result, result_dict)]
helpers.convert_mapping_to_xml(
- model_checked, result_dict, mapping, fail_required=True)
+ model_checked, result_dict, mapping, fail_required=True
+ )
def reverse(registry, xml_parent, data):
@@ -1550,32 +1605,33 @@ def reverse(registry, xml_parent, data):
.. literalinclude:: /../../tests/triggers/fixtures/reverse-list.yaml
"""
reserveBuildTrigger = XML.SubElement(
- xml_parent, 'jenkins.triggers.ReverseBuildTrigger')
+ xml_parent, "jenkins.triggers.ReverseBuildTrigger"
+ )
- supported_thresholds = ['SUCCESS', 'UNSTABLE', 'FAILURE']
+ supported_thresholds = ["SUCCESS", "UNSTABLE", "FAILURE"]
- XML.SubElement(reserveBuildTrigger, 'spec').text = ''
+ XML.SubElement(reserveBuildTrigger, "spec").text = ""
- jobs = data.get('jobs')
+ jobs = data.get("jobs")
if isinstance(jobs, list):
jobs = ",".join(jobs)
- XML.SubElement(reserveBuildTrigger, 'upstreamProjects').text = \
- jobs
+ XML.SubElement(reserveBuildTrigger, "upstreamProjects").text = jobs
- threshold = XML.SubElement(reserveBuildTrigger, 'threshold')
- result = str(data.get('result', 'success')).upper()
+ threshold = XML.SubElement(reserveBuildTrigger, "threshold")
+ result = str(data.get("result", "success")).upper()
if result not in supported_thresholds:
raise jenkins_jobs.errors.JenkinsJobsException(
- "Choice should be one of the following options: %s." %
- ", ".join(supported_thresholds))
- XML.SubElement(threshold, 'name').text = \
- hudson_model.THRESHOLDS[result]['name']
- XML.SubElement(threshold, 'ordinal').text = \
- hudson_model.THRESHOLDS[result]['ordinal']
- XML.SubElement(threshold, 'color').text = \
- hudson_model.THRESHOLDS[result]['color']
- XML.SubElement(threshold, 'completeBuild').text = \
- str(hudson_model.THRESHOLDS[result]['complete']).lower()
+ "Choice should be one of the following options: %s."
+ % ", ".join(supported_thresholds)
+ )
+ XML.SubElement(threshold, "name").text = hudson_model.THRESHOLDS[result]["name"]
+ XML.SubElement(threshold, "ordinal").text = hudson_model.THRESHOLDS[result][
+ "ordinal"
+ ]
+ XML.SubElement(threshold, "color").text = hudson_model.THRESHOLDS[result]["color"]
+ XML.SubElement(threshold, "completeBuild").text = str(
+ hudson_model.THRESHOLDS[result]["complete"]
+ ).lower()
def monitor_folders(registry, xml_parent, data):
@@ -1609,25 +1665,26 @@ def monitor_folders(registry, xml_parent, data):
/../../tests/triggers/fixtures/monitor-folders-minimal.yaml
:language: yaml
"""
- ft = XML.SubElement(xml_parent, ('org.jenkinsci.plugins.fstrigger.'
- 'triggers.FolderContentTrigger'))
- ft.set('plugin', 'fstrigger')
+ ft = XML.SubElement(
+ xml_parent, ("org.jenkinsci.plugins.fstrigger." "triggers.FolderContentTrigger")
+ )
+ ft.set("plugin", "fstrigger")
- mappings = [
- ('path', 'path', ''),
- ('cron', 'spec', ''),
- ]
+ mappings = [("path", "path", ""), ("cron", "spec", "")]
helpers.convert_mapping_to_xml(ft, data, mappings, fail_required=True)
- includes = data.get('includes', '')
- XML.SubElement(ft, 'includes').text = ",".join(includes)
- XML.SubElement(ft, 'excludes').text = data.get('excludes', '')
- XML.SubElement(ft, 'excludeCheckLastModificationDate').text = str(
- not data.get('check-modification-date', True)).lower()
- XML.SubElement(ft, 'excludeCheckContent').text = str(
- not data.get('check-content', True)).lower()
- XML.SubElement(ft, 'excludeCheckFewerOrMoreFiles').text = str(
- not data.get('check-fewer', True)).lower()
+ includes = data.get("includes", "")
+ XML.SubElement(ft, "includes").text = ",".join(includes)
+ XML.SubElement(ft, "excludes").text = data.get("excludes", "")
+ XML.SubElement(ft, "excludeCheckLastModificationDate").text = str(
+ not data.get("check-modification-date", True)
+ ).lower()
+ XML.SubElement(ft, "excludeCheckContent").text = str(
+ not data.get("check-content", True)
+ ).lower()
+ XML.SubElement(ft, "excludeCheckFewerOrMoreFiles").text = str(
+ not data.get("check-fewer", True)
+ ).lower()
def monitor_files(registry, xml_parent, data):
@@ -1707,73 +1764,83 @@ def monitor_files(registry, xml_parent, data):
/../../tests/triggers/fixtures/monitor-files-full.yaml
:language: yaml
"""
- ft_prefix = 'org.jenkinsci.plugins.fstrigger.triggers.'
- valid_strategies = ['LATEST', 'IGNORE']
+ ft_prefix = "org.jenkinsci.plugins.fstrigger.triggers."
+ valid_strategies = ["LATEST", "IGNORE"]
valid_content_types = {
- 'simple': ['Simple', '', '', []],
- 'jar': ['JAR', '', '', []],
- 'tar': ['Tar', '', '', []],
- 'zip': ['ZIP', '', '', []],
- 'source-manifest': ['SourceManifest'],
- 'jar-manifest': ['JARManifest'],
- 'properties': ['Properties'],
- 'xml': ['XML', 'expressions', 'expression', None],
- 'text': ['Text', 'regexElements', 'regex', None]
+ "simple": ["Simple", "", "", []],
+ "jar": ["JAR", "", "", []],
+ "tar": ["Tar", "", "", []],
+ "zip": ["ZIP", "", "", []],
+ "source-manifest": ["SourceManifest"],
+ "jar-manifest": ["JARManifest"],
+ "properties": ["Properties"],
+ "xml": ["XML", "expressions", "expression", None],
+ "text": ["Text", "regexElements", "regex", None],
}
- ft = XML.SubElement(xml_parent, ft_prefix + 'FileNameTrigger')
- XML.SubElement(ft, 'spec').text = str(data.get('cron', ''))
- files = data.get('files', [])
+ ft = XML.SubElement(xml_parent, ft_prefix + "FileNameTrigger")
+ XML.SubElement(ft, "spec").text = str(data.get("cron", ""))
+ files = data.get("files", [])
if not files:
- raise JenkinsJobsException('At least one file must be provided')
+ raise JenkinsJobsException("At least one file must be provided")
- files_tag = XML.SubElement(ft, 'fileInfo')
+ files_tag = XML.SubElement(ft, "fileInfo")
for file_info in files:
- file_tag = XML.SubElement(files_tag, ft_prefix + 'FileNameTriggerInfo')
- check_content = file_info.get('check-content', [])
+ file_tag = XML.SubElement(files_tag, ft_prefix + "FileNameTriggerInfo")
+ check_content = file_info.get("check-content", [])
files_mapping = [
- ('path', 'filePathPattern', None),
- ('strategy', 'strategy', 'LATEST', valid_strategies),
- ('', 'inspectingContentFile', bool(check_content)),
+ ("path", "filePathPattern", None),
+ ("strategy", "strategy", "LATEST", valid_strategies),
+ ("", "inspectingContentFile", bool(check_content)),
]
helpers.convert_mapping_to_xml(
- file_tag, file_info, files_mapping, fail_required=True)
+ file_tag, file_info, files_mapping, fail_required=True
+ )
- base_content_tag = XML.SubElement(file_tag, 'contentFileTypes')
+ base_content_tag = XML.SubElement(file_tag, "contentFileTypes")
for content in check_content:
type_name = next(iter(content.keys()))
if type_name not in valid_content_types:
- raise InvalidAttributeError('check-content', type_name,
- valid_content_types.keys())
+ raise InvalidAttributeError(
+ "check-content", type_name, valid_content_types.keys()
+ )
content_type = valid_content_types.get(type_name)
if len(content_type) == 1:
- class_name = '{0}filecontent.{1}FileContent'.format(
- ft_prefix, content_type[0])
+ class_name = "{0}filecontent.{1}FileContent".format(
+ ft_prefix, content_type[0]
+ )
content_data = content.get(type_name)
if not content_data:
- raise JenkinsJobsException("Need to specify something "
- "under " + type_name)
+ raise JenkinsJobsException(
+ "Need to specify something " "under " + type_name
+ )
for entry in content_data:
content_tag = XML.SubElement(base_content_tag, class_name)
- keys = entry.get('keys', [])
+ keys = entry.get("keys", [])
if keys:
- XML.SubElement(content_tag, 'keys2Inspect'
- ).text = ",".join(keys)
- XML.SubElement(content_tag, 'allKeys').text = str(
- entry.get('all-keys', True)).lower()
+ XML.SubElement(content_tag, "keys2Inspect").text = ",".join(
+ keys
+ )
+ XML.SubElement(content_tag, "allKeys").text = str(
+ entry.get("all-keys", True)
+ ).lower()
else:
if content[type_name]:
sub_entries = content_type[3]
if sub_entries is None:
sub_entries = content[type_name]
- build_content_type(base_content_tag, sub_entries,
- ft_prefix + 'filecontent',
- 'FileContent', 'FileContentEntry',
- *content_type[0:3])
+ build_content_type(
+ base_content_tag,
+ sub_entries,
+ ft_prefix + "filecontent",
+ "FileContent",
+ "FileContentEntry",
+ *content_type[0:3]
+ )
if bool(check_content):
- XML.SubElement(file_tag,
- 'doNotCheckLastModificationDate').text = str(
- file_info.get('ignore-modificaton-date', True)).lower()
+ XML.SubElement(file_tag, "doNotCheckLastModificationDate").text = str(
+ file_info.get("ignore-modificaton-date", True)
+ ).lower()
def ivy(registry, xml_parent, data):
@@ -1799,27 +1866,25 @@ def ivy(registry, xml_parent, data):
.. literalinclude:: /../../tests/triggers/fixtures/ivy.yaml
"""
- it = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.ivytrigger.IvyTrigger')
+ it = XML.SubElement(xml_parent, "org.jenkinsci.plugins.ivytrigger.IvyTrigger")
mapping = [
- ('path', 'ivyPath', None),
- ('settings-path', 'ivySettingsPath', None),
- ('properties-content', 'propertiesContent', None),
- ('debug', 'debug', False),
- ('download-artifacts', 'downloadArtifacts', True),
- ('enable-concurrent', 'enableConcurrentBuild', False),
- ('cron', 'spec', ''),
+ ("path", "ivyPath", None),
+ ("settings-path", "ivySettingsPath", None),
+ ("properties-content", "propertiesContent", None),
+ ("debug", "debug", False),
+ ("download-artifacts", "downloadArtifacts", True),
+ ("enable-concurrent", "enableConcurrentBuild", False),
+ ("cron", "spec", ""),
]
helpers.convert_mapping_to_xml(it, data, mapping, fail_required=False)
- properties_file_path = data.get('properties-file', [])
- XML.SubElement(it, 'propertiesFilePath').text = ";".join(
- properties_file_path)
+ properties_file_path = data.get("properties-file", [])
+ XML.SubElement(it, "propertiesFilePath").text = ";".join(properties_file_path)
- label = data.get('label')
- XML.SubElement(it, 'labelRestriction').text = str(bool(label)).lower()
+ label = data.get("label")
+ XML.SubElement(it, "labelRestriction").text = str(bool(label)).lower()
if label:
- XML.SubElement(it, 'triggerLabel').text = label
+ XML.SubElement(it, "triggerLabel").text = label
def script(registry, xml_parent, data):
@@ -1847,20 +1912,17 @@ def script(registry, xml_parent, data):
.. literalinclude:: /../../tests/triggers/fixtures/script-minimal.yaml
:language: yaml
"""
- st = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.scripttrigger.ScriptTrigger'
- )
- st.set('plugin', 'scripttrigger')
- label = data.get('label')
+ st = XML.SubElement(xml_parent, "org.jenkinsci.plugins.scripttrigger.ScriptTrigger")
+ st.set("plugin", "scripttrigger")
+ label = data.get("label")
mappings = [
- ('script', 'script', ''),
- ('script-file-path', 'scriptFilePath', ''),
- ('cron', 'spec', ''),
- ('enable-concurrent', 'enableConcurrentBuild', False),
- ('exit-code', 'exitCode', 0),
- ('', 'labelRestriction', bool(label)),
- ('', 'triggerLabel', label),
+ ("script", "script", ""),
+ ("script-file-path", "scriptFilePath", ""),
+ ("cron", "spec", ""),
+ ("enable-concurrent", "enableConcurrentBuild", False),
+ ("exit-code", "exitCode", 0),
+ ("", "labelRestriction", bool(label)),
+ ("", "triggerLabel", label),
]
helpers.convert_mapping_to_xml(st, data, mappings, fail_required=False)
@@ -1896,21 +1958,20 @@ def groovy_script(registry, xml_parent, data):
:language: yaml
"""
gst = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger'
+ xml_parent, "org.jenkinsci.plugins.scripttrigger.groovy.GroovyScriptTrigger"
)
- gst.set('plugin', 'scripttrigger')
+ gst.set("plugin", "scripttrigger")
- label = data.get('label')
+ label = data.get("label")
mappings = [
- ('system-script', 'groovySystemScript', False),
- ('script', 'groovyExpression', ''),
- ('script-file-path', 'groovyFilePath', ''),
- ('property-file-path', 'propertiesFilePath', ''),
- ('enable-concurrent', 'enableConcurrentBuild', False),
- ('cron', 'spec', ''),
- ('', 'labelRestriction', bool(label)),
- ('', 'triggerLabel', label),
+ ("system-script", "groovySystemScript", False),
+ ("script", "groovyExpression", ""),
+ ("script-file-path", "groovyFilePath", ""),
+ ("property-file-path", "propertiesFilePath", ""),
+ ("enable-concurrent", "enableConcurrentBuild", False),
+ ("cron", "spec", ""),
+ ("", "labelRestriction", bool(label)),
+ ("", "triggerLabel", label),
]
helpers.convert_mapping_to_xml(gst, data, mappings, fail_required=False)
@@ -1939,27 +2000,18 @@ def rabbitmq(registry, xml_parent, data):
:language: yaml
"""
- rabbitmq_prefix = 'org.jenkinsci.plugins.rabbitmqbuildtrigger.'
- rabbitmq = XML.SubElement(
- xml_parent,
- rabbitmq_prefix + 'RemoteBuildTrigger')
- filters = data.get('filters', [])
- filter_mapping = [
- ('field', 'field', None),
- ('value', 'value', None),
- ]
+ rabbitmq_prefix = "org.jenkinsci.plugins.rabbitmqbuildtrigger."
+ rabbitmq = XML.SubElement(xml_parent, rabbitmq_prefix + "RemoteBuildTrigger")
+ filters = data.get("filters", [])
+ filter_mapping = [("field", "field", None), ("value", "value", None)]
if filters:
- filters_tag = XML.SubElement(rabbitmq, 'filters')
+ filters_tag = XML.SubElement(rabbitmq, "filters")
for filter_data in filters:
- filter_tag = XML.SubElement(
- filters_tag,
- rabbitmq_prefix + 'Filter')
+ filter_tag = XML.SubElement(filters_tag, rabbitmq_prefix + "Filter")
helpers.convert_mapping_to_xml(
- filter_tag, filter_data, filter_mapping, fail_required=True)
- mapping = [
- ('', 'spec', ''),
- ('token', 'remoteBuildToken', None),
- ]
+ filter_tag, filter_data, filter_mapping, fail_required=True
+ )
+ mapping = [("", "spec", ""), ("token", "remoteBuildToken", None)]
helpers.convert_mapping_to_xml(rabbitmq, data, mapping, fail_required=True)
@@ -1981,14 +2033,10 @@ def parameterized_timer(parser, xml_parent, data):
param_timer = XML.SubElement(
xml_parent,
- 'org.jenkinsci.plugins.parameterizedscheduler.'
- 'ParameterizedTimerTrigger')
- mapping = [
- ('', 'spec', ''),
- ('cron', 'parameterizedSpecification', None),
- ]
- helpers.convert_mapping_to_xml(
- param_timer, data, mapping, fail_required=True)
+ "org.jenkinsci.plugins.parameterizedscheduler." "ParameterizedTimerTrigger",
+ )
+ mapping = [("", "spec", ""), ("cron", "parameterizedSpecification", None)]
+ helpers.convert_mapping_to_xml(param_timer, data, mapping, fail_required=True)
def jira_changelog(registry, xml_parent, data):
@@ -2045,52 +2093,62 @@ def jira_changelog(registry, xml_parent, data):
/../../tests/triggers/fixtures/jira-changelog-full.yaml
:language: yaml
"""
- jcht = XML.SubElement(xml_parent, 'com.ceilfors.jenkins.plugins.'
- 'jiratrigger.JiraChangelogTrigger')
- jcht.set('plugin', 'jira-trigger')
+ jcht = XML.SubElement(
+ xml_parent, "com.ceilfors.jenkins.plugins." "jiratrigger.JiraChangelogTrigger"
+ )
+ jcht.set("plugin", "jira-trigger")
- mapping = [
- ('jql-filter', 'jqlFilter', ''),
- ]
+ mapping = [("jql-filter", "jqlFilter", "")]
helpers.convert_mapping_to_xml(jcht, data, mapping, fail_required=True)
- changelog = XML.SubElement(jcht, 'changelogMatchers')
+ changelog = XML.SubElement(jcht, "changelogMatchers")
mappings = [
- ('field', 'field', ''),
- ('new-value', 'newValue', ''),
- ('old-value', 'oldValue', ''),
- ('compare-new-value', 'comparingNewValue', False),
- ('compare-old-value', 'comparingOldValue', False),
+ ("field", "field", ""),
+ ("new-value", "newValue", ""),
+ ("old-value", "oldValue", ""),
+ ("compare-new-value", "comparingNewValue", False),
+ ("compare-old-value", "comparingOldValue", False),
]
- for matcher in data.get('changelog-matchers', []):
+ for matcher in data.get("changelog-matchers", []):
+
+ fieldtype = matcher.get("field-type")
+ if fieldtype == "CUSTOM":
+ parent_tag = XML.SubElement(
+ changelog,
+ "com.ceilfors.jenkins."
+ "plugins.jiratrigger.changelog."
+ "CustomFieldChangelogMatcher",
+ )
+ XML.SubElement(parent_tag, "fieldType").text = "CUSTOM"
+
+ elif fieldtype == "JIRA":
+ parent_tag = XML.SubElement(
+ changelog,
+ "com.ceilfors.jenkins."
+ "plugins.jiratrigger.changelog."
+ "JiraFieldChangelogMatcher",
+ )
+ XML.SubElement(parent_tag, "fieldType").text = "JIRA"
- fieldtype = matcher.get('field-type')
- if fieldtype == 'CUSTOM':
- parent_tag = XML.SubElement(changelog, 'com.ceilfors.jenkins.'
- 'plugins.jiratrigger.changelog.'
- 'CustomFieldChangelogMatcher')
- XML.SubElement(parent_tag, 'fieldType').text = 'CUSTOM'
-
- elif fieldtype == 'JIRA':
- parent_tag = XML.SubElement(changelog, 'com.ceilfors.jenkins.'
- 'plugins.jiratrigger.changelog.'
- 'JiraFieldChangelogMatcher')
- XML.SubElement(parent_tag, 'fieldType').text = 'JIRA'
-
- helpers.convert_mapping_to_xml(parent_tag, matcher,
- mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ parent_tag, matcher, mappings, fail_required=True
+ )
- param = XML.SubElement(jcht, 'parameterMappings')
+ param = XML.SubElement(jcht, "parameterMappings")
parameter_mappings = [
- ('jenkins-parameter', 'jenkinsParameter', ''),
- ('issue-attribute-path', 'issueAttributePath', ''),
+ ("jenkins-parameter", "jenkinsParameter", ""),
+ ("issue-attribute-path", "issueAttributePath", ""),
]
- for parameter in data.get('parameter-mapping', []):
- parent = XML.SubElement(param, 'com.ceilfors.jenkins.plugins.'
- 'jiratrigger.parameter.'
- 'IssueAttributePathParameterMapping')
+ for parameter in data.get("parameter-mapping", []):
+ parent = XML.SubElement(
+ param,
+ "com.ceilfors.jenkins.plugins."
+ "jiratrigger.parameter."
+ "IssueAttributePathParameterMapping",
+ )
helpers.convert_mapping_to_xml(
- parent, parameter, parameter_mappings, fail_required=True)
+ parent, parameter, parameter_mappings, fail_required=True
+ )
def jira_comment_trigger(registry, xml_parent, data):
@@ -2122,26 +2180,31 @@ def jira_comment_trigger(registry, xml_parent, data):
/../../tests/triggers/fixtures/jira-comment-trigger-full.yaml
:language: yaml
"""
- jct = XML.SubElement(xml_parent, 'com.ceilfors.jenkins.plugins.'
- 'jiratrigger.JiraCommentTrigger')
- jct.set('plugin', 'jira-trigger')
+ jct = XML.SubElement(
+ xml_parent, "com.ceilfors.jenkins.plugins." "jiratrigger.JiraCommentTrigger"
+ )
+ jct.set("plugin", "jira-trigger")
mapping = [
- ('jql-filter', 'jqlFilter', ''),
- ('comment-pattern', 'commentPattern', '(?i)build this please'),
+ ("jql-filter", "jqlFilter", ""),
+ ("comment-pattern", "commentPattern", "(?i)build this please"),
]
helpers.convert_mapping_to_xml(jct, data, mapping, fail_required=True)
- param = XML.SubElement(jct, 'parameterMappings')
- for parameter in data.get('parameter-mapping', []):
- parent = XML.SubElement(param, 'com.ceilfors.jenkins.plugins.'
- 'jiratrigger.parameter.'
- 'IssueAttributePathParameterMapping')
+ param = XML.SubElement(jct, "parameterMappings")
+ for parameter in data.get("parameter-mapping", []):
+ parent = XML.SubElement(
+ param,
+ "com.ceilfors.jenkins.plugins."
+ "jiratrigger.parameter."
+ "IssueAttributePathParameterMapping",
+ )
parameter_mappings = [
- ('jenkins-parameter', 'jenkinsParameter', ''),
- ('issue-attribute-path', 'issueAttributePath', ''),
+ ("jenkins-parameter", "jenkinsParameter", ""),
+ ("issue-attribute-path", "issueAttributePath", ""),
]
helpers.convert_mapping_to_xml(
- parent, parameter, parameter_mappings, fail_required=True)
+ parent, parameter, parameter_mappings, fail_required=True
+ )
def stash_pull_request(registry, xml_parent, data):
@@ -2188,32 +2251,34 @@ def stash_pull_request(registry, xml_parent, data):
"""
pr_trigger = XML.SubElement(
- xml_parent,
- 'stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger')
- pr_trigger.set('plugin', 'stash-pullrequest-builder')
+ xml_parent, "stashpullrequestbuilder.stashpullrequestbuilder.StashBuildTrigger"
+ )
+ pr_trigger.set("plugin", "stash-pullrequest-builder")
mappings = [
- ('cron', 'spec', None), # Spec needs to be set to the same as cron
- ('cron', 'cron', None),
- ('stash-host', 'stashHost', None),
- ('credentials-id', 'credentialsId', None),
- ('project', 'projectCode', None),
- ('repository', 'repositoryName', None),
- ('ci-skip-phrases', 'ciSkipPhrases', 'NO TEST'),
- ('ci-build-phrases', 'ciBuildPhrases', 'test this please'),
- ('target-branches', 'targetBranchesToBuild', ''),
- ('ignore-ssl', 'ignoreSsl', False),
- ('check-destination-commit', 'checkDestinationCommit', False),
- ('check-mergable', 'checkMergeable', False),
- ('merge-on-success', 'mergeOnSuccess', False),
- ('check-not-conflicted', 'checkNotConflicted', True),
- ('only-build-on-comment', 'onlyBuildOnComment', False),
- ('delete-previous-build-finish-comments',
- 'deletePreviousBuildFinishComments', False),
- ('cancel-outdated-jobs', 'cancelOutdatedJobsEnabled', False),
+ ("cron", "spec", None), # Spec needs to be set to the same as cron
+ ("cron", "cron", None),
+ ("stash-host", "stashHost", None),
+ ("credentials-id", "credentialsId", None),
+ ("project", "projectCode", None),
+ ("repository", "repositoryName", None),
+ ("ci-skip-phrases", "ciSkipPhrases", "NO TEST"),
+ ("ci-build-phrases", "ciBuildPhrases", "test this please"),
+ ("target-branches", "targetBranchesToBuild", ""),
+ ("ignore-ssl", "ignoreSsl", False),
+ ("check-destination-commit", "checkDestinationCommit", False),
+ ("check-mergable", "checkMergeable", False),
+ ("merge-on-success", "mergeOnSuccess", False),
+ ("check-not-conflicted", "checkNotConflicted", True),
+ ("only-build-on-comment", "onlyBuildOnComment", False),
+ (
+ "delete-previous-build-finish-comments",
+ "deletePreviousBuildFinishComments",
+ False,
+ ),
+ ("cancel-outdated-jobs", "cancelOutdatedJobsEnabled", False),
]
- helpers.convert_mapping_to_xml(
- pr_trigger, data, mappings, fail_required=True)
+ helpers.convert_mapping_to_xml(pr_trigger, data, mappings, fail_required=True)
def generic_webhook_trigger(registry, xml_parent, data):
@@ -2264,29 +2329,28 @@ def generic_webhook_trigger(registry, xml_parent, data):
/../../tests/triggers/fixtures/generic-webhook-trigger-full.yaml
"""
- namespace = 'org.jenkinsci.plugins.gwt.'
- gwtrig = XML.SubElement(xml_parent,
- namespace + 'GenericTrigger')
- gwtrig.set('plugin', 'generic-webhook-trigger')
- XML.SubElement(gwtrig, 'spec')
+ namespace = "org.jenkinsci.plugins.gwt."
+ gwtrig = XML.SubElement(xml_parent, namespace + "GenericTrigger")
+ gwtrig.set("plugin", "generic-webhook-trigger")
+ XML.SubElement(gwtrig, "spec")
# Generic Varibles (Post content parameters in UI)
try:
- if data.get('post-content-params'):
- gen_vars = XML.SubElement(gwtrig, 'genericVariables')
+ if data.get("post-content-params"):
+ gen_vars = XML.SubElement(gwtrig, "genericVariables")
mappings = [
- ('type', 'expressionType', '', ['JSONPath', 'XPath']),
- ('key', 'key', ''),
- ('value', 'value', ''),
- ('regex-filter', 'regexpFilter', ''),
- ('default-value', 'defaultValue', ''),
+ ("type", "expressionType", "", ["JSONPath", "XPath"]),
+ ("key", "key", ""),
+ ("value", "value", ""),
+ ("regex-filter", "regexpFilter", ""),
+ ("default-value", "defaultValue", ""),
]
- for gen_var_list in data.get('post-content-params'):
- gen_var_tag = XML.SubElement(
- gen_vars, namespace + 'GenericVariable')
+ for gen_var_list in data.get("post-content-params"):
+ gen_var_tag = XML.SubElement(gen_vars, namespace + "GenericVariable")
helpers.convert_mapping_to_xml(
- gen_var_tag, gen_var_list, mappings, fail_required=True)
+ gen_var_tag, gen_var_list, mappings, fail_required=True
+ )
except AttributeError:
pass
@@ -2294,50 +2358,47 @@ def generic_webhook_trigger(registry, xml_parent, data):
# done. It probably doesn't need to be, but since this is the first
# swing..
mapping = [
- ('regex-filter-text', 'regexpFilterText', ''),
- ('regex-filter-expression', 'regexpFilterExpression', '')
+ ("regex-filter-text", "regexpFilterText", ""),
+ ("regex-filter-expression", "regexpFilterExpression", ""),
]
helpers.convert_mapping_to_xml(gwtrig, data, mapping, fail_required=False)
# Generic Request Variables (Request parameters in UI)
try:
- if data.get('request-params'):
- gen_req_vars = XML.SubElement(gwtrig, 'genericRequestVariables')
- mappings = [
- ('key', 'key', ''),
- ('regex-filter', 'regexpFilter', '')
- ]
+ if data.get("request-params"):
+ gen_req_vars = XML.SubElement(gwtrig, "genericRequestVariables")
+ mappings = [("key", "key", ""), ("regex-filter", "regexpFilter", "")]
- for gen_req_list in data.get('request-params'):
+ for gen_req_list in data.get("request-params"):
gen_req_tag = XML.SubElement(
- gen_req_vars, namespace + 'GenericRequestVariable')
+ gen_req_vars, namespace + "GenericRequestVariable"
+ )
helpers.convert_mapping_to_xml(
- gen_req_tag, gen_req_list, mappings, fail_required=False)
+ gen_req_tag, gen_req_list, mappings, fail_required=False
+ )
except AttributeError:
pass
try:
- if data.get('header-params'):
- gen_header_vars = XML.SubElement(gwtrig, 'genericHeaderVariables')
- mappings = [
- ('key', 'key', ''),
- ('regex-filter', 'regexpFilter', '')
- ]
- for gen_header_list in data.get('header-params'):
+ if data.get("header-params"):
+ gen_header_vars = XML.SubElement(gwtrig, "genericHeaderVariables")
+ mappings = [("key", "key", ""), ("regex-filter", "regexpFilter", "")]
+ for gen_header_list in data.get("header-params"):
gen_header_tag = XML.SubElement(
- gen_header_vars, namespace + 'GenericHeaderVariable')
+ gen_header_vars, namespace + "GenericHeaderVariable"
+ )
helpers.convert_mapping_to_xml(
- gen_header_tag, gen_header_list, mappings,
- fail_required=False)
+ gen_header_tag, gen_header_list, mappings, fail_required=False
+ )
except AttributeError:
pass
mapping = [
- ('print-post-content', 'printPostContent', False),
- ('print-contrib-var', 'printContributedVariables', False),
- ('cause', 'causeString', ''),
- ('token', 'token', ''),
- ('silent-response', 'silentResponse', False),
+ ("print-post-content", "printPostContent", False),
+ ("print-contrib-var", "printContributedVariables", False),
+ ("cause", "causeString", ""),
+ ("token", "token", ""),
+ ("silent-response", "silentResponse", False),
]
# This should cover all the top level
helpers.convert_mapping_to_xml(gwtrig, data, mapping, fail_required=False)
@@ -2346,14 +2407,14 @@ def generic_webhook_trigger(registry, xml_parent, data):
class Triggers(jenkins_jobs.modules.base.Base):
sequence = 50
- component_type = 'trigger'
- component_list_type = 'triggers'
+ component_type = "trigger"
+ component_list_type = "triggers"
def gen_xml(self, xml_parent, data):
- triggers = data.get('triggers', [])
+ triggers = data.get("triggers", [])
if not triggers:
return
- trig_e = XML.SubElement(xml_parent, 'triggers', {'class': 'vector'})
+ trig_e = XML.SubElement(xml_parent, "triggers", {"class": "vector"})
for trigger in triggers:
- self.registry.dispatch('trigger', trig_e, trigger)
+ self.registry.dispatch("trigger", trig_e, trigger)
diff --git a/jenkins_jobs/modules/view_all.py b/jenkins_jobs/modules/view_all.py
index aa41d5c3..cf320eee 100644
--- a/jenkins_jobs/modules/view_all.py
+++ b/jenkins_jobs/modules/view_all.py
@@ -33,17 +33,16 @@ class All(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- root = XML.Element('hudson.model.AllView')
+ root = XML.Element("hudson.model.AllView")
mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ('filter-executors', 'filterExecutors', False),
- ('filter-queue', 'filterQueue', False),
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("filter-executors", "filterExecutors", False),
+ ("filter-queue", "filterQueue", False),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
- XML.SubElement(root, 'properties',
- {'class': 'hudson.model.View$PropertyList'})
+ XML.SubElement(root, "properties", {"class": "hudson.model.View$PropertyList"})
return root
diff --git a/jenkins_jobs/modules/view_jobfilters.py b/jenkins_jobs/modules/view_jobfilters.py
index 6fd52f28..09e3c51b 100644
--- a/jenkins_jobs/modules/view_jobfilters.py
+++ b/jenkins_jobs/modules/view_jobfilters.py
@@ -17,195 +17,189 @@ import jenkins_jobs.modules.helpers as helpers
def build_duration(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.BuildDurationFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.BuildDurationFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('build-duration-type', 'buildCountTypeString', 'Latest'),
- ('amount-type', 'amountTypeString', 'Hours'),
- ('amount', 'amount', '0'),
- ('less-than', 'lessThan', True),
- ('build-duration-minutes', 'buildDurationMinutes', '0'),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("build-duration-type", "buildCountTypeString", "Latest"),
+ ("amount-type", "amountTypeString", "Hours"),
+ ("amount", "amount", "0"),
+ ("less-than", "lessThan", True),
+ ("build-duration-minutes", "buildDurationMinutes", "0"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_status(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.BuildStatusFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.BuildStatusFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('never-built', 'neverBuilt', False),
- ('building', 'building', False),
- ('in-build-queue', 'inBuildQueue', False),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("never-built", "neverBuilt", False),
+ ("building", "building", False),
+ ("in-build-queue", "inBuildQueue", False),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def build_trend(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.BuildTrendFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.BuildTrendFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('build-trend-type', 'buildCountTypeString', 'Latest'),
- ('amount-type', 'amountTypeString', 'Hours'),
- ('amount', 'amount', '0'),
- ('status', 'statusTypeString', 'Completed'),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("build-trend-type", "buildCountTypeString", "Latest"),
+ ("amount-type", "amountTypeString", "Hours"),
+ ("amount", "amount", "0"),
+ ("status", "statusTypeString", "Completed"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def fallback(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.AddRemoveFallbackFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.AddRemoveFallbackFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('fallback-type', 'fallbackTypeString', 'REMOVE_ALL_IF_ALL_INCLUDED'),
- ('fallback-type', 'fallbackType', 'REMOVE_ALL_IF_ALL_INCLUDED'),
+ ("fallback-type", "fallbackTypeString", "REMOVE_ALL_IF_ALL_INCLUDED"),
+ ("fallback-type", "fallbackType", "REMOVE_ALL_IF_ALL_INCLUDED"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def job_status(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.JobStatusFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.JobStatusFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('unstable', 'unstable', False),
- ('failed', 'failed', False),
- ('aborted', 'aborted', False),
- ('disabled', 'disabled', False),
- ('stable', 'stable', False),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("unstable", "unstable", False),
+ ("failed", "failed", False),
+ ("aborted", "aborted", False),
+ ("disabled", "disabled", False),
+ ("stable", "stable", False),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def job_type(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.JobTypeFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.JobTypeFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('job-type', 'jobType', 'hudson.model.FreeStyleProject'),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("job-type", "jobType", "hudson.model.FreeStyleProject"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def most_recent(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.MostRecentJobsFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.MostRecentJobsFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('max-to-include', 'maxToInclude', '0'),
- ('check-start-time', 'checkStartTime', False),
+ ("max-to-include", "maxToInclude", "0"),
+ ("check-start-time", "checkStartTime", False),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def other_views(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.OtherViewsFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.OtherViewsFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('view-name', 'otherViewName',
- '&lt;select a view other than this one&gt;'),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("view-name", "otherViewName", "&lt;select a view other than this one&gt;"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def parameter(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.ParameterFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.ParameterFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('name', 'nameRegex', ''),
- ('value', 'valueRegex', ''),
- ('description', 'descriptionRegex', ''),
- ('use-default', 'useDefaultValue', False),
- ('match-builds-in-progress', 'matchBuildsInProgress', False),
- ('match-all-builds', 'matchAllBuilds', False),
- ('max-builds-to-match', 'maxBuildsToMatch', 0),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("name", "nameRegex", ""),
+ ("value", "valueRegex", ""),
+ ("description", "descriptionRegex", ""),
+ ("use-default", "useDefaultValue", False),
+ ("match-builds-in-progress", "matchBuildsInProgress", False),
+ ("match-all-builds", "matchAllBuilds", False),
+ ("max-builds-to-match", "maxBuildsToMatch", 0),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def scm(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.ScmTypeFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.ScmTypeFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('scm-type', 'scmType', 'hudson.scm.NullSCM'),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("scm-type", "scmType", "hudson.scm.NullSCM"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def secured_job(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.SecuredJobsFilter')
- xml.set('plugin', 'view-job-filters')
- mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ]
+ xml = XML.SubElement(xml_parent, "hudson.views.SecuredJobsFilter")
+ xml.set("plugin", "view-job-filters")
+ mapping = [("match-type", "includeExcludeTypeString", "includeMatched")]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def regex_job(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.RegExJobFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.RegExJobFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('regex-name', 'valueTypeString', ''),
- ('regex', 'regex', ''),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("regex-name", "valueTypeString", ""),
+ ("regex", "regex", ""),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def unclassified(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.UnclassifiedJobsFilter')
- xml.set('plugin', 'view-job-filters')
- mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ]
+ xml = XML.SubElement(xml_parent, "hudson.views.UnclassifiedJobsFilter")
+ xml.set("plugin", "view-job-filters")
+ mapping = [("match-type", "includeExcludeTypeString", "includeMatched")]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def upstream_downstream(xml_parent, data):
- xml = XML.SubElement(
- xml_parent, 'hudson.views.UpstreamDownstreamJobsFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.UpstreamDownstreamJobsFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('include-upstream', 'includeUpstream', False),
- ('include-downstream', 'includeDownstream', False),
- ('recursive', 'recursive', False),
- ('exclude-originals', 'excludeOriginals', False),
+ ("include-upstream", "includeUpstream", False),
+ ("include-downstream", "includeDownstream", False),
+ ("recursive", "recursive", False),
+ ("exclude-originals", "excludeOriginals", False),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def user_permissions(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.SecurityFilter')
- xml.set('plugin', 'view-job-filters')
+ xml = XML.SubElement(xml_parent, "hudson.views.SecurityFilter")
+ xml.set("plugin", "view-job-filters")
mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('configure', 'configure', False),
- ('build', 'build', False),
- ('workspace', 'workspace', False),
- ('permission-check', 'permissionCheckType', 'MustMatchAll'),
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("configure", "configure", False),
+ ("build", "build", False),
+ ("workspace", "workspace", False),
+ ("permission-check", "permissionCheckType", "MustMatchAll"),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
def user_relevence(xml_parent, data):
- xml = XML.SubElement(xml_parent, 'hudson.views.UserRelevanceFilter')
- xml.set('plugin', 'view-job-filters')
- mapping = [
- ('match-type', 'includeExcludeTypeString', 'includeMatched'),
- ('build-count', 'buildCountTypeString', 'AtLeastOne'),
- ('amount-type', 'amountTypeString', 'Hours'),
- ('amount', 'amount', '0'),
- ('match-user-id', 'matchUserId', False),
- ('match-user-fullname', 'matchUserFullName', False),
- ('ignore-case', 'ignoreCase', False),
- ('ignore-whitespace', 'ignoreWhitespace', False),
- ('ignore-non-alphaNumeric', 'ignoreNonAlphaNumeric', False),
- ('match-builder', 'matchBuilder', False),
- ('match-email', 'matchEmail', False),
- ('match-scm-changes', 'matchScmChanges', False),
+ xml = XML.SubElement(xml_parent, "hudson.views.UserRelevanceFilter")
+ xml.set("plugin", "view-job-filters")
+ mapping = [
+ ("match-type", "includeExcludeTypeString", "includeMatched"),
+ ("build-count", "buildCountTypeString", "AtLeastOne"),
+ ("amount-type", "amountTypeString", "Hours"),
+ ("amount", "amount", "0"),
+ ("match-user-id", "matchUserId", False),
+ ("match-user-fullname", "matchUserFullName", False),
+ ("ignore-case", "ignoreCase", False),
+ ("ignore-whitespace", "ignoreWhitespace", False),
+ ("ignore-non-alphaNumeric", "ignoreNonAlphaNumeric", False),
+ ("match-builder", "matchBuilder", False),
+ ("match-email", "matchEmail", False),
+ ("match-scm-changes", "matchScmChanges", False),
]
helpers.convert_mapping_to_xml(xml, data, mapping, fail_required=True)
diff --git a/jenkins_jobs/modules/view_list.py b/jenkins_jobs/modules/view_list.py
index 5b542bfb..2931cc4b 100644
--- a/jenkins_jobs/modules/view_list.py
+++ b/jenkins_jobs/modules/view_list.py
@@ -227,147 +227,153 @@ import jenkins_jobs.modules.helpers as helpers
import jenkins_jobs.modules.view_jobfilters as view_jobfilters
COLUMN_DICT = {
- 'status': 'hudson.views.StatusColumn',
- 'weather': 'hudson.views.WeatherColumn',
- 'job': 'hudson.views.JobColumn',
- 'last-success': 'hudson.views.LastSuccessColumn',
- 'last-failure': 'hudson.views.LastFailureColumn',
- 'last-duration': 'hudson.views.LastDurationColumn',
- 'build-button': 'hudson.views.BuildButtonColumn',
- 'last-stable': 'hudson.views.LastStableColumn',
- 'robot-list': 'hudson.plugins.robot.view.RobotListViewColumn',
- 'find-bugs': 'hudson.plugins.findbugs.FindBugsColumn',
- 'jacoco': 'hudson.plugins.jacococoveragecolumn.JaCoCoColumn',
- 'git-branch': 'hudson.plugins.git.GitBranchSpecifierColumn',
- 'schedule-build':
- 'org.jenkinsci.plugins.schedulebuild.ScheduleBuildButtonColumn',
- 'priority-sorter': 'jenkins.advancedqueue.PrioritySorterJobColumn',
- 'build-filter': 'hudson.views.BuildFilterColumn',
- 'desc': 'jenkins.branch.DescriptionColumn',
- 'policy-violations':
- 'com.sonatype.insight.ci.hudson.QualityColumn '
- 'plugin="sonatype-clm-ci"',
- 'member-graph-view':
- 'com.barchart.jenkins.cascade.GraphViewColumn '
- 'plugin="maven-release-cascade"',
- 'extra-tests-total': [
- ['jenkins.plugins.extracolumns.TestResultColumn',
- {'plugin': 'extra-columns'}],
- '<testResultFormat>2</testResultFormat>'],
- 'extra-tests-failed': [
- ['jenkins.plugins.extracolumns.TestResultColumn',
- {'plugin': 'extra-columns'}],
- '<testResultFormat>3</testResultFormat>'],
- 'extra-tests-passed': [
- ['jenkins.plugins.extracolumns.TestResultColumn',
- {'plugin': 'extra-columns'}],
- '<testResultFormat>4</testResultFormat>'],
- 'extra-tests-skipped': [
- ['jenkins.plugins.extracolumns.TestResultColumn',
- {'plugin': 'extra-columns'}],
- '<testResultFormat>5</testResultFormat>'],
- 'extra-tests-format-0': [
- ['jenkins.plugins.extracolumns.TestResultColumn',
- {'plugin': 'extra-columns'}],
- '<testResultFormat>0</testResultFormat>'],
- 'extra-tests-format-1': [
- ['jenkins.plugins.extracolumns.TestResultColumn',
- {'plugin': 'extra-columns'}],
- '<testResultFormat>1</testResultFormat>'],
- 'extra-build-description': [
- ['jenkins.plugins.extracolumns.BuildDescriptionColumn',
- {'plugin': 'extra-columns'}],
- '<columnWidth>3</columnWidth>', '<forceWidth>false</forceWidth>'],
- 'extra-build-parameters': [
- ['jenkins.plugins.extracolumns.BuildParametersColumn',
- {'plugin': 'extra-columns'}],
- '<singlePara>false</singlePara>', '<parameterName/>'],
- 'extra-last-user-name':
- 'jenkins.plugins.extracolumns.UserNameColumn'
- ' plugin="extra-columns"',
- 'extra-last-output':
- 'jenkins.plugins.extracolumns.LastBuildConsoleColumn'
- ' plugin="extra-columns"',
- 'extra-workspace-link':
- 'jenkins.plugins.extracolumns.WorkspaceColumn '
- 'plugin="extra-columns"',
- 'extra-configure-button':
- 'jenkins.plugins.extracolumns.ConfigureProjectColumn'
- ' plugin="extra-columns"',
+ "status": "hudson.views.StatusColumn",
+ "weather": "hudson.views.WeatherColumn",
+ "job": "hudson.views.JobColumn",
+ "last-success": "hudson.views.LastSuccessColumn",
+ "last-failure": "hudson.views.LastFailureColumn",
+ "last-duration": "hudson.views.LastDurationColumn",
+ "build-button": "hudson.views.BuildButtonColumn",
+ "last-stable": "hudson.views.LastStableColumn",
+ "robot-list": "hudson.plugins.robot.view.RobotListViewColumn",
+ "find-bugs": "hudson.plugins.findbugs.FindBugsColumn",
+ "jacoco": "hudson.plugins.jacococoveragecolumn.JaCoCoColumn",
+ "git-branch": "hudson.plugins.git.GitBranchSpecifierColumn",
+ "schedule-build": "org.jenkinsci.plugins.schedulebuild.ScheduleBuildButtonColumn",
+ "priority-sorter": "jenkins.advancedqueue.PrioritySorterJobColumn",
+ "build-filter": "hudson.views.BuildFilterColumn",
+ "desc": "jenkins.branch.DescriptionColumn",
+ "policy-violations": "com.sonatype.insight.ci.hudson.QualityColumn "
+ 'plugin="sonatype-clm-ci"',
+ "member-graph-view": "com.barchart.jenkins.cascade.GraphViewColumn "
+ 'plugin="maven-release-cascade"',
+ "extra-tests-total": [
+ ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
+ "<testResultFormat>2</testResultFormat>",
+ ],
+ "extra-tests-failed": [
+ ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
+ "<testResultFormat>3</testResultFormat>",
+ ],
+ "extra-tests-passed": [
+ ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
+ "<testResultFormat>4</testResultFormat>",
+ ],
+ "extra-tests-skipped": [
+ ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
+ "<testResultFormat>5</testResultFormat>",
+ ],
+ "extra-tests-format-0": [
+ ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
+ "<testResultFormat>0</testResultFormat>",
+ ],
+ "extra-tests-format-1": [
+ ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
+ "<testResultFormat>1</testResultFormat>",
+ ],
+ "extra-build-description": [
+ [
+ "jenkins.plugins.extracolumns.BuildDescriptionColumn",
+ {"plugin": "extra-columns"},
+ ],
+ "<columnWidth>3</columnWidth>",
+ "<forceWidth>false</forceWidth>",
+ ],
+ "extra-build-parameters": [
+ [
+ "jenkins.plugins.extracolumns.BuildParametersColumn",
+ {"plugin": "extra-columns"},
+ ],
+ "<singlePara>false</singlePara>",
+ "<parameterName/>",
+ ],
+ "extra-last-user-name": "jenkins.plugins.extracolumns.UserNameColumn"
+ ' plugin="extra-columns"',
+ "extra-last-output": "jenkins.plugins.extracolumns.LastBuildConsoleColumn"
+ ' plugin="extra-columns"',
+ "extra-workspace-link": "jenkins.plugins.extracolumns.WorkspaceColumn "
+ 'plugin="extra-columns"',
+ "extra-configure-button": "jenkins.plugins.extracolumns.ConfigureProjectColumn"
+ ' plugin="extra-columns"',
}
-DEFAULT_COLUMNS = ['status', 'weather', 'job', 'last-success', 'last-failure',
- 'last-duration', 'build-button']
+DEFAULT_COLUMNS = [
+ "status",
+ "weather",
+ "job",
+ "last-success",
+ "last-failure",
+ "last-duration",
+ "build-button",
+]
class List(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- root = XML.Element('hudson.model.ListView')
+ root = XML.Element("hudson.model.ListView")
mapping = [
- ('name', 'name', None),
- ('description', 'description', ''),
- ('filter-executors', 'filterExecutors', False),
- ('filter-queue', 'filterQueue', False),
+ ("name", "name", None),
+ ("description", "description", ""),
+ ("filter-executors", "filterExecutors", False),
+ ("filter-queue", "filterQueue", False),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
- XML.SubElement(root, 'properties',
- {'class': 'hudson.model.View$PropertyList'})
+ XML.SubElement(root, "properties", {"class": "hudson.model.View$PropertyList"})
- jn_xml = XML.SubElement(root, 'jobNames')
- jobnames = data.get('job-name', None)
+ jn_xml = XML.SubElement(root, "jobNames")
+ jobnames = data.get("job-name", None)
XML.SubElement(
- jn_xml,
- 'comparator', {
- 'class': 'hudson.util.CaseInsensitiveComparator'
- }
+ jn_xml, "comparator", {"class": "hudson.util.CaseInsensitiveComparator"}
)
if jobnames is not None:
# Job names must be sorted in the xml
jobnames = sorted(jobnames, key=str.lower)
for jobname in jobnames:
- XML.SubElement(jn_xml, 'string').text = str(jobname)
+ XML.SubElement(jn_xml, "string").text = str(jobname)
- job_filter_xml = XML.SubElement(root, 'jobFilters')
- jobfilters = data.get('job-filters', [])
+ job_filter_xml = XML.SubElement(root, "jobFilters")
+ jobfilters = data.get("job-filters", [])
for jobfilter in jobfilters:
- filter = getattr(view_jobfilters, jobfilter.replace('-', '_'))
+ filter = getattr(view_jobfilters, jobfilter.replace("-", "_"))
filter(job_filter_xml, jobfilters.get(jobfilter))
- c_xml = XML.SubElement(root, 'columns')
- columns = data.get('columns', DEFAULT_COLUMNS)
+ c_xml = XML.SubElement(root, "columns")
+ columns = data.get("columns", DEFAULT_COLUMNS)
for column in columns:
if isinstance(column, dict):
- if 'extra-build-parameter' in column:
- p_name = column['extra-build-parameter']
+ if "extra-build-parameter" in column:
+ p_name = column["extra-build-parameter"]
x = XML.SubElement(
c_xml,
- 'jenkins.plugins.extracolumns.BuildParametersColumn',
- plugin='extra-columns'
+ "jenkins.plugins.extracolumns.BuildParametersColumn",
+ plugin="extra-columns",
+ )
+ x.append(XML.fromstring("<singlePara>true</singlePara>"))
+ x.append(
+ XML.fromstring("<parameterName>%s</parameterName>" % p_name)
)
- x.append(XML.fromstring(
- '<singlePara>true</singlePara>'))
- x.append(XML.fromstring(
- '<parameterName>%s</parameterName>' % p_name))
else:
if column in COLUMN_DICT:
if isinstance(COLUMN_DICT[column], list):
- x = XML.SubElement(c_xml, COLUMN_DICT[column][0][0],
- **COLUMN_DICT[column][0][1])
+ x = XML.SubElement(
+ c_xml,
+ COLUMN_DICT[column][0][0],
+ **COLUMN_DICT[column][0][1]
+ )
for tag in COLUMN_DICT[column][1:]:
x.append(XML.fromstring(tag))
else:
XML.SubElement(c_xml, COLUMN_DICT[column])
mapping = [
- ('regex', 'includeRegex', None),
- ('recurse', 'recurse', False),
- ('status-filter', 'statusFilter', None),
+ ("regex", "includeRegex", None),
+ ("recurse", "recurse", False),
+ ("status-filter", "statusFilter", None),
]
- helpers.convert_mapping_to_xml(
- root, data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
return root
diff --git a/jenkins_jobs/modules/view_pipeline.py b/jenkins_jobs/modules/view_pipeline.py
index 5f7f61bc..3ec25b10 100644
--- a/jenkins_jobs/modules/view_pipeline.py
+++ b/jenkins_jobs/modules/view_pipeline.py
@@ -69,43 +69,45 @@ class Pipeline(jenkins_jobs.modules.base.Base):
sequence = 0
def root_xml(self, data):
- linktypes = ['Lightbox', 'New Window']
- root = XML.Element('au.com.centrumsystems.hudson.'
- 'plugin.buildpipeline.BuildPipelineView',
- {'plugin': 'build-pipeline-plugin'})
+ linktypes = ["Lightbox", "New Window"]
+ root = XML.Element(
+ "au.com.centrumsystems.hudson." "plugin.buildpipeline.BuildPipelineView",
+ {"plugin": "build-pipeline-plugin"},
+ )
mapping_optional = [
- ('description', 'description', None),
- ('filter-executors', 'filterExecutors', False),
- ('filter-queue', 'filterQueue', False),
+ ("description", "description", None),
+ ("filter-executors", "filterExecutors", False),
+ ("filter-queue", "filterQueue", False),
]
- helpers.convert_mapping_to_xml(root, data,
- mapping_optional, fail_required=False)
+ helpers.convert_mapping_to_xml(
+ root, data, mapping_optional, fail_required=False
+ )
- XML.SubElement(root, 'properties',
- {'class': 'hudson.model.View$PropertyList'})
+ XML.SubElement(root, "properties", {"class": "hudson.model.View$PropertyList"})
- GBurl = ('au.com.centrumsystems.hudson.plugin.buildpipeline.'
- 'DownstreamProjectGridBuilder')
- gridBuilder = XML.SubElement(root, 'gridBuilder', {'class': GBurl})
+ GBurl = (
+ "au.com.centrumsystems.hudson.plugin.buildpipeline."
+ "DownstreamProjectGridBuilder"
+ )
+ gridBuilder = XML.SubElement(root, "gridBuilder", {"class": GBurl})
- jobname = data.get('first-job', '')
- XML.SubElement(gridBuilder, 'firstJob').text = jobname
+ jobname = data.get("first-job", "")
+ XML.SubElement(gridBuilder, "firstJob").text = jobname
mapping = [
- ('name', 'name', None),
- ('no-of-displayed-builds', 'noOfDisplayedBuilds', 1),
- ('title', 'buildViewTitle', ''),
- ('link-style', 'consoleOutputLinkStyle', 'Lightbox', linktypes),
- ('css-Url', 'cssUrl', ''),
- ('latest-job-only', 'triggerOnlyLatestJob', False),
- ('manual-trigger', 'alwaysAllowManualTrigger', False),
- ('show-parameters', 'showPipelineParameters', False),
- ('parameters-in-headers',
- 'showPipelineParametersInHeaders', False),
- ('start-with-parameters', 'startsWithParameters', False),
- ('refresh-frequency', 'refreshFrequency', 3),
- ('definition-header', 'showPipelineDefinitionHeader', False),
+ ("name", "name", None),
+ ("no-of-displayed-builds", "noOfDisplayedBuilds", 1),
+ ("title", "buildViewTitle", ""),
+ ("link-style", "consoleOutputLinkStyle", "Lightbox", linktypes),
+ ("css-Url", "cssUrl", ""),
+ ("latest-job-only", "triggerOnlyLatestJob", False),
+ ("manual-trigger", "alwaysAllowManualTrigger", False),
+ ("show-parameters", "showPipelineParameters", False),
+ ("parameters-in-headers", "showPipelineParametersInHeaders", False),
+ ("start-with-parameters", "startsWithParameters", False),
+ ("refresh-frequency", "refreshFrequency", 3),
+ ("definition-header", "showPipelineDefinitionHeader", False),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py
index ab5dc2b3..26de754c 100644
--- a/jenkins_jobs/modules/wrappers.py
+++ b/jenkins_jobs/modules/wrappers.py
@@ -99,68 +99,68 @@ def docker_custom_build_env(registry, xml_parent, data):
/../../tests/wrappers/fixtures/docker-custom-build-env001.yaml
:language: yaml
"""
- core_prefix = 'com.cloudbees.jenkins.plugins.okidocki.'
- entry_xml = XML.SubElement(
- xml_parent, core_prefix + 'DockerBuildWrapper')
- entry_xml.set('plugin', 'docker-custom-build-environment')
-
- selectorobj = XML.SubElement(entry_xml, 'selector')
- image_type = data['image-type']
- if image_type == 'dockerfile':
- selectorobj.set('class', core_prefix + 'DockerfileImageSelector')
+ core_prefix = "com.cloudbees.jenkins.plugins.okidocki."
+ entry_xml = XML.SubElement(xml_parent, core_prefix + "DockerBuildWrapper")
+ entry_xml.set("plugin", "docker-custom-build-environment")
+
+ selectorobj = XML.SubElement(entry_xml, "selector")
+ image_type = data["image-type"]
+ if image_type == "dockerfile":
+ selectorobj.set("class", core_prefix + "DockerfileImageSelector")
dockerfile_mapping = [
- ('context-path', 'contextPath', '.'),
- ('dockerfile', 'dockerfile', 'Dockerfile'),
+ ("context-path", "contextPath", "."),
+ ("dockerfile", "dockerfile", "Dockerfile"),
]
- helpers.convert_mapping_to_xml(selectorobj, data,
- dockerfile_mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ selectorobj, data, dockerfile_mapping, fail_required=True
+ )
- elif image_type == 'pull':
- selectorobj.set('class', core_prefix + 'PullDockerImageSelector')
- pull_mapping = [
- ('image', 'image', ''),
- ]
- helpers.convert_mapping_to_xml(selectorobj, data,
- pull_mapping, fail_required=True)
+ elif image_type == "pull":
+ selectorobj.set("class", core_prefix + "PullDockerImageSelector")
+ pull_mapping = [("image", "image", "")]
+ helpers.convert_mapping_to_xml(
+ selectorobj, data, pull_mapping, fail_required=True
+ )
- XML.SubElement(entry_xml, 'dockerInstallation').text = data.get(
- 'docker-tool', 'Default')
+ XML.SubElement(entry_xml, "dockerInstallation").text = data.get(
+ "docker-tool", "Default"
+ )
- host = XML.SubElement(entry_xml, 'dockerHost')
- host.set('plugin', 'docker-commons')
+ host = XML.SubElement(entry_xml, "dockerHost")
+ host.set("plugin", "docker-commons")
mapping_optional = [
- ('host', 'uri', None),
- ('credentials-id', 'credentialsId', None),
+ ("host", "uri", None),
+ ("credentials-id", "credentialsId", None),
]
- helpers.convert_mapping_to_xml(
- host, data, mapping_optional, fail_required=False)
+ helpers.convert_mapping_to_xml(host, data, mapping_optional, fail_required=False)
- XML.SubElement(entry_xml, 'dockerRegistryCredentials').text = data.get(
- 'registry-credentials-id', '')
- volumesobj = XML.SubElement(entry_xml, 'volumes')
- volumes = data.get('volumes', [])
+ XML.SubElement(entry_xml, "dockerRegistryCredentials").text = data.get(
+ "registry-credentials-id", ""
+ )
+ volumesobj = XML.SubElement(entry_xml, "volumes")
+ volumes = data.get("volumes", [])
if not volumes:
- volumesobj.set('class', 'empty-list')
+ volumesobj.set("class", "empty-list")
else:
for volume in volumes:
volumeobj = XML.SubElement(
- volumesobj, 'com.cloudbees.jenkins.plugins.okidocki.Volume')
- XML.SubElement(volumeobj, 'hostPath').text = volume['volume'].get(
- 'host-path', '')
- XML.SubElement(volumeobj, 'path').text = volume['volume'].get(
- 'path', '')
+ volumesobj, "com.cloudbees.jenkins.plugins.okidocki.Volume"
+ )
+ XML.SubElement(volumeobj, "hostPath").text = volume["volume"].get(
+ "host-path", ""
+ )
+ XML.SubElement(volumeobj, "path").text = volume["volume"].get("path", "")
mapping = [
- ('force-pull', 'forcePull', False),
- ('privileged', 'privileged', False),
- ('verbose', 'verbose', False),
- ('group', 'group', ''),
- ('command', 'command', '/bin/cat'),
- ('net', 'net', 'bridge'),
- ('memory-limit', 'memory', ''),
- ('cpu-shares', 'cpu', ''),
+ ("force-pull", "forcePull", False),
+ ("privileged", "privileged", False),
+ ("verbose", "verbose", False),
+ ("group", "group", ""),
+ ("command", "command", "/bin/cat"),
+ ("net", "net", "bridge"),
+ ("memory-limit", "memory", ""),
+ ("cpu-shares", "cpu", ""),
]
- helpers.convert_mapping_to_xml(
- entry_xml, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(entry_xml, data, mapping, fail_required=True)
def ci_skip(registry, xml_parent, data):
@@ -174,24 +174,20 @@ def ci_skip(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/ci-skip001.yaml
"""
- rpobj = XML.SubElement(xml_parent, 'ruby-proxy-object')
- robj = XML.SubElement(rpobj, 'ruby-object', {
- 'pluginid': 'ci-skip',
- 'ruby-class': 'Jenkins::Tasks::BuildWrapperProxy'
- })
- pluginid = XML.SubElement(robj, 'pluginid', {
- 'pluginid': 'ci-skip',
- 'ruby-class': 'String'
- })
- pluginid.text = 'ci-skip'
- obj = XML.SubElement(robj, 'object', {
- 'pluginid': 'ci-skip',
- 'ruby-class': 'CiSkipWrapper',
- })
- XML.SubElement(obj, 'ci__skip', {
- 'pluginid': 'ci-skip',
- 'ruby-class': 'NilClass'
- })
+ rpobj = XML.SubElement(xml_parent, "ruby-proxy-object")
+ robj = XML.SubElement(
+ rpobj,
+ "ruby-object",
+ {"pluginid": "ci-skip", "ruby-class": "Jenkins::Tasks::BuildWrapperProxy"},
+ )
+ pluginid = XML.SubElement(
+ robj, "pluginid", {"pluginid": "ci-skip", "ruby-class": "String"}
+ )
+ pluginid.text = "ci-skip"
+ obj = XML.SubElement(
+ robj, "object", {"pluginid": "ci-skip", "ruby-class": "CiSkipWrapper"}
+ )
+ XML.SubElement(obj, "ci__skip", {"pluginid": "ci-skip", "ruby-class": "NilClass"})
def config_file_provider(registry, xml_parent, data):
@@ -224,9 +220,11 @@ def config_file_provider(registry, xml_parent, data):
.. literalinclude::
/../../tests/wrappers/fixtures/config-file-provider-minimal.yaml
"""
- cfp = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.configfiles.'
- 'buildwrapper.ConfigFileBuildWrapper')
- cfp.set('plugin', 'config-file-provider')
+ cfp = XML.SubElement(
+ xml_parent,
+ "org.jenkinsci.plugins.configfiles." "buildwrapper.ConfigFileBuildWrapper",
+ )
+ cfp.set("plugin", "config-file-provider")
helpers.config_file_provider_builder(cfp, data)
@@ -251,18 +249,17 @@ def logfilesize(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/logfilesize-minimal.yaml
"""
- lfswrapper = XML.SubElement(xml_parent,
- 'hudson.plugins.logfilesizechecker.'
- 'LogfilesizecheckerWrapper')
+ lfswrapper = XML.SubElement(
+ xml_parent, "hudson.plugins.logfilesizechecker." "LogfilesizecheckerWrapper"
+ )
lfswrapper.set("plugin", "logfilesizechecker")
mapping = [
- ('set-own', 'setOwn', False),
- ('size', 'maxLogSize', 128),
- ('fail', 'failBuild', False),
+ ("set-own", "setOwn", False),
+ ("size", "maxLogSize", 128),
+ ("fail", "failBuild", False),
]
- helpers.convert_mapping_to_xml(
- lfswrapper, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(lfswrapper, data, mapping, fail_required=True)
def timeout(registry, xml_parent, data):
@@ -326,8 +323,8 @@ def timeout(registry, xml_parent, data):
/../../tests/wrappers/fixtures/timeout/version-1.15/deadline001.yaml
"""
- prefix = 'hudson.plugins.build__timeout.'
- twrapper = XML.SubElement(xml_parent, prefix + 'BuildTimeoutWrapper')
+ prefix = "hudson.plugins.build__timeout."
+ twrapper = XML.SubElement(xml_parent, prefix + "BuildTimeoutWrapper")
plugin_info = registry.get_plugin_info("Build Timeout")
if "version" not in plugin_info:
@@ -336,89 +333,113 @@ def timeout(registry, xml_parent, data):
if version:
version = pkg_resources.parse_version(version)
- valid_strategies = ['absolute', 'no-activity', 'likely-stuck', 'elastic',
- 'deadline']
+ valid_strategies = [
+ "absolute",
+ "no-activity",
+ "likely-stuck",
+ "elastic",
+ "deadline",
+ ]
# NOTE(toabctl): if we don't know the version assume that we
# use a newer version of the plugin
if not version or version >= pkg_resources.parse_version("1.14"):
- strategy = data.get('type', 'absolute')
+ strategy = data.get("type", "absolute")
if strategy not in valid_strategies:
- InvalidAttributeError('type', strategy, valid_strategies)
+ InvalidAttributeError("type", strategy, valid_strategies)
if strategy == "absolute":
strategy_element = XML.SubElement(
- twrapper, 'strategy',
- {'class': "hudson.plugins.build_timeout."
- "impl.AbsoluteTimeOutStrategy"})
- mapping = [
- ('timeout', 'timeoutMinutes', 3),
- ]
- helpers.convert_mapping_to_xml(strategy_element,
- data, mapping, fail_required=True)
+ twrapper,
+ "strategy",
+ {
+ "class": "hudson.plugins.build_timeout."
+ "impl.AbsoluteTimeOutStrategy"
+ },
+ )
+ mapping = [("timeout", "timeoutMinutes", 3)]
+ helpers.convert_mapping_to_xml(
+ strategy_element, data, mapping, fail_required=True
+ )
elif strategy == "no-activity":
strategy_element = XML.SubElement(
- twrapper, 'strategy',
- {'class': "hudson.plugins.build_timeout."
- "impl.NoActivityTimeOutStrategy"})
- timeout_sec = int(data.get('timeout', 3)) * MIN_TO_SEC
- mapping = [
- ('', 'timeoutSecondsString', timeout_sec),
- ]
- helpers.convert_mapping_to_xml(strategy_element,
- data, mapping, fail_required=True)
+ twrapper,
+ "strategy",
+ {
+ "class": "hudson.plugins.build_timeout."
+ "impl.NoActivityTimeOutStrategy"
+ },
+ )
+ timeout_sec = int(data.get("timeout", 3)) * MIN_TO_SEC
+ mapping = [("", "timeoutSecondsString", timeout_sec)]
+ helpers.convert_mapping_to_xml(
+ strategy_element, data, mapping, fail_required=True
+ )
elif strategy == "likely-stuck":
strategy_element = XML.SubElement(
- twrapper, 'strategy',
- {'class': "hudson.plugins.build_timeout."
- "impl.LikelyStuckTimeOutStrategy"})
- mapping = [
- ('timeout', 'timeoutMinutes', 3),
- ]
- helpers.convert_mapping_to_xml(strategy_element,
- data, mapping, fail_required=True)
+ twrapper,
+ "strategy",
+ {
+ "class": "hudson.plugins.build_timeout."
+ "impl.LikelyStuckTimeOutStrategy"
+ },
+ )
+ mapping = [("timeout", "timeoutMinutes", 3)]
+ helpers.convert_mapping_to_xml(
+ strategy_element, data, mapping, fail_required=True
+ )
elif strategy == "elastic":
strategy_element = XML.SubElement(
- twrapper, 'strategy',
- {'class': "hudson.plugins.build_timeout."
- "impl.ElasticTimeOutStrategy"})
+ twrapper,
+ "strategy",
+ {
+ "class": "hudson.plugins.build_timeout."
+ "impl.ElasticTimeOutStrategy"
+ },
+ )
mapping = [
- ('elastic-percentage', 'timeoutPercentage', 0),
- ('elastic-number-builds', 'numberOfBuilds', 0),
- ('elastic-default-timeout', 'timeoutMinutesElasticDefault', 3),
+ ("elastic-percentage", "timeoutPercentage", 0),
+ ("elastic-number-builds", "numberOfBuilds", 0),
+ ("elastic-default-timeout", "timeoutMinutesElasticDefault", 3),
]
- helpers.convert_mapping_to_xml(strategy_element,
- data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ strategy_element, data, mapping, fail_required=True
+ )
elif strategy == "deadline":
strategy_element = XML.SubElement(
- twrapper, 'strategy',
- {'class': "hudson.plugins.build_timeout."
- "impl.DeadlineTimeOutStrategy"})
- deadline_time = str(data.get('deadline-time', '0:00:00'))
- deadline_tolerance = int(data.get('deadline-tolerance', 1))
+ twrapper,
+ "strategy",
+ {
+ "class": "hudson.plugins.build_timeout."
+ "impl.DeadlineTimeOutStrategy"
+ },
+ )
+ deadline_time = str(data.get("deadline-time", "0:00:00"))
+ deadline_tolerance = int(data.get("deadline-tolerance", 1))
mapping = [
- ('', 'deadlineTime', deadline_time),
- ('', 'deadlineToleranceInMinutes', deadline_tolerance),
+ ("", "deadlineTime", deadline_time),
+ ("", "deadlineToleranceInMinutes", deadline_tolerance),
]
- helpers.convert_mapping_to_xml(strategy_element,
- data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ strategy_element, data, mapping, fail_required=True
+ )
actions = []
- for action in ['fail', 'abort']:
- if str(data.get(action, 'false')).lower() == 'true':
+ for action in ["fail", "abort"]:
+ if str(data.get(action, "false")).lower() == "true":
actions.append(action)
# Set the default action to "abort"
if len(actions) == 0:
actions.append("abort")
- description = data.get('write-description', None)
+ description = data.get("write-description", None)
if description is not None:
- actions.append('write-description')
+ actions.append("write-description")
- operation_list = XML.SubElement(twrapper, 'operationList')
+ operation_list = XML.SubElement(twrapper, "operationList")
for action in actions:
fmt_str = prefix + "operations.{0}Operation"
@@ -428,33 +449,31 @@ def timeout(registry, xml_parent, data):
XML.SubElement(operation_list, fmt_str.format("Fail"))
elif action == "write-description":
write_description = XML.SubElement(
- operation_list, fmt_str.format("WriteDescription"))
- XML.SubElement(write_description, "description"
- ).text = description
+ operation_list, fmt_str.format("WriteDescription")
+ )
+ XML.SubElement(write_description, "description").text = description
else:
- raise JenkinsJobsException("Unsupported BuiltTimeoutWrapper "
- "plugin action: {0}".format(action))
- mapping = [
- ('timeout-var', 'timeoutEnvVar', None),
- ]
- helpers.convert_mapping_to_xml(twrapper,
- data, mapping, fail_required=False)
+ raise JenkinsJobsException(
+ "Unsupported BuiltTimeoutWrapper "
+ "plugin action: {0}".format(action)
+ )
+ mapping = [("timeout-var", "timeoutEnvVar", None)]
+ helpers.convert_mapping_to_xml(twrapper, data, mapping, fail_required=False)
else:
mapping = [
- ('timeout', 'timeoutMinutes', 3),
- ('timeout-var', 'timeoutEnvVar', None),
- ('fail', 'failBuild', 'false'),
- ('write-description', 'writingDescription', 'false'),
- ('elastic-percentage', 'timeoutPercentage', 0),
- ('elastic-default-timeout', 'timeoutMinutesElasticDefault', 3),
+ ("timeout", "timeoutMinutes", 3),
+ ("timeout-var", "timeoutEnvVar", None),
+ ("fail", "failBuild", "false"),
+ ("write-description", "writingDescription", "false"),
+ ("elastic-percentage", "timeoutPercentage", 0),
+ ("elastic-default-timeout", "timeoutMinutesElasticDefault", 3),
]
- helpers.convert_mapping_to_xml(twrapper,
- data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(twrapper, data, mapping, fail_required=False)
- tout_type = str(data.get('type', 'absolute')).lower()
- if tout_type == 'likely-stuck':
- tout_type = 'likelyStuck'
- XML.SubElement(twrapper, 'timeoutType').text = tout_type
+ tout_type = str(data.get("type", "absolute")).lower()
+ if tout_type == "likely-stuck":
+ tout_type = "likelyStuck"
+ XML.SubElement(twrapper, "timeoutType").text = tout_type
def timestamps(registry, xml_parent, data):
@@ -467,8 +486,7 @@ def timestamps(registry, xml_parent, data):
wrappers:
- timestamps
"""
- XML.SubElement(xml_parent,
- 'hudson.plugins.timestamper.TimestamperBuildWrapper')
+ XML.SubElement(xml_parent, "hudson.plugins.timestamper.TimestamperBuildWrapper")
def ansicolor(registry, xml_parent, data):
@@ -489,15 +507,12 @@ def ansicolor(registry, xml_parent, data):
:language: yaml
"""
cwrapper = XML.SubElement(
- xml_parent,
- 'hudson.plugins.ansicolor.AnsiColorBuildWrapper')
+ xml_parent, "hudson.plugins.ansicolor.AnsiColorBuildWrapper"
+ )
- valid_types = ['xterm', 'vga', 'css', 'gnome-terminal']
- mapping = [
- ('colormap', 'colorMapName', 'xterm', valid_types),
- ]
- helpers.convert_mapping_to_xml(
- cwrapper, data, mapping, fail_required=False)
+ valid_types = ["xterm", "vga", "css", "gnome-terminal"]
+ mapping = [("colormap", "colorMapName", "xterm", valid_types)]
+ helpers.convert_mapping_to_xml(cwrapper, data, mapping, fail_required=False)
def build_keeper(registry, xml_parent, data):
@@ -548,160 +563,228 @@ def build_keeper(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/build-keeper0002.yaml
"""
- root = XML.SubElement(xml_parent,
- 'org.jenkins__ci.plugins.build__keeper.BuildKeeper')
+ root = XML.SubElement(
+ xml_parent, "org.jenkins__ci.plugins.build__keeper.BuildKeeper"
+ )
- valid_policies = ('by-day', 'keep-since', 'build-number',
- 'keep-first-failed', 'run-condition')
- policy = data.get('policy')
+ valid_policies = (
+ "by-day",
+ "keep-since",
+ "build-number",
+ "keep-first-failed",
+ "run-condition",
+ )
+ policy = data.get("policy")
mapping = [
- ('build-period', 'buildPeriod', 0),
- ('dont-keep-failed', 'dontKeepFailed', False),
+ ("build-period", "buildPeriod", 0),
+ ("dont-keep-failed", "dontKeepFailed", False),
]
- if policy == 'by-day':
- policy_element = XML.SubElement(root,
- 'policy',
- {'class': 'org.jenkins_ci.plugins.'
- 'build_keeper.ByDayPolicy'})
- elif policy == 'keep-since':
- policy_element = XML.SubElement(root,
- 'policy',
- {'class': 'org.jenkins_ci.plugins.'
- 'build_keeper.KeepSincePolicy'})
- elif policy == 'build-number':
- policy_element = XML.SubElement(root,
- 'policy',
- {'class': 'org.jenkins_ci.plugins.'
- 'build_keeper.BuildNumberPolicy'})
- elif policy == 'keep-first-failed':
- policy_element = XML.SubElement(root,
- 'policy',
- {'class': 'org.jenkins_ci.plugins.'
- 'build_keeper.KeepFirstFailedPolicy'})
- mapping = [
- ('number-of-fails', 'numberOfFails', 0),
- ]
- elif policy == 'run-condition':
- policy_element = XML.SubElement(root,
- 'policy',
- {'class': 'org.jenkins_ci.plugins.'
- 'build_keeper.RunConditionPolicy'})
-
- run_condition = data.get('run-condition', [])
+ if policy == "by-day":
+ policy_element = XML.SubElement(
+ root,
+ "policy",
+ {"class": "org.jenkins_ci.plugins." "build_keeper.ByDayPolicy"},
+ )
+ elif policy == "keep-since":
+ policy_element = XML.SubElement(
+ root,
+ "policy",
+ {"class": "org.jenkins_ci.plugins." "build_keeper.KeepSincePolicy"},
+ )
+ elif policy == "build-number":
+ policy_element = XML.SubElement(
+ root,
+ "policy",
+ {"class": "org.jenkins_ci.plugins." "build_keeper.BuildNumberPolicy"},
+ )
+ elif policy == "keep-first-failed":
+ policy_element = XML.SubElement(
+ root,
+ "policy",
+ {"class": "org.jenkins_ci.plugins." "build_keeper.KeepFirstFailedPolicy"},
+ )
+ mapping = [("number-of-fails", "numberOfFails", 0)]
+ elif policy == "run-condition":
+ policy_element = XML.SubElement(
+ root,
+ "policy",
+ {"class": "org.jenkins_ci.plugins." "build_keeper.RunConditionPolicy"},
+ )
+
+ run_condition = data.get("run-condition", [])
run_condition_base_class = {
- 'core': "org.jenkins_ci.plugins.run_condition.core.",
- 'shell': "org.jenkins_ci.plugins.run_condition.contributed.",
+ "core": "org.jenkins_ci.plugins.run_condition.core.",
+ "shell": "org.jenkins_ci.plugins.run_condition.contributed.",
}
- mapping = [
- ('keep-build', 'keepBuildIfEvalFails', False),
- ]
- bool_cond_mapping = [
- ('token', 'token', ''),
+ mapping = [("keep-build", "keepBuildIfEvalFails", False)]
+ bool_cond_mapping = [("token", "token", "")]
+ build_cause_types = [
+ "USER_CAUSE",
+ "CLI_CAUSE",
+ "REMOTE_CAUSE",
+ "SCM_CAUSE",
+ "TIMER_CAUSE",
+ "UPSTREAM_CAUSE",
+ "FS_CAUSE",
+ "URL_CAUSE",
+ "IVY_CAUSE",
+ "SCRIPT_CAUSE",
+ "BUILDRESULT_CAUSE",
]
- build_cause_types = ['USER_CAUSE', 'CLI_CAUSE', 'REMOTE_CAUSE',
- 'SCM_CAUSE', 'TIMER_CAUSE', 'UPSTREAM_CAUSE',
- 'FS_CAUSE', 'URL_CAUSE', 'IVY_CAUSE',
- 'SCRIPT_CAUSE', 'BUILDRESULT_CAUSE']
cause_cond_mapping = [
- ('build-cause', 'buildCause', 'USER_CAUSE', build_cause_types),
- ('exclusive-cause', 'exclusiveCause', False),
- ]
- execute_mapping = [
- ('command', 'command', ''),
+ ("build-cause", "buildCause", "USER_CAUSE", build_cause_types),
+ ("exclusive-cause", "exclusiveCause", False),
]
+ execute_mapping = [("command", "command", "")]
regexp_match_mapping = [
- ('expression', 'expression', ''),
- ('label', 'label', ''),
+ ("expression", "expression", ""),
+ ("label", "label", ""),
]
strings_match_mapping = [
- ('arg1', 'arg1', ''),
- ('arg2', 'arg2', ''),
- ('ignore-case', 'ignoreCase', False),
+ ("arg1", "arg1", ""),
+ ("arg2", "arg2", ""),
+ ("ignore-case", "ignoreCase", False),
]
for value in run_condition:
- if value.get('type') == 'always':
- XML.SubElement(policy_element,
- 'runCondition',
- {'class':
- ''.join((run_condition_base_class.get('core'),
- 'AlwaysRun'))})
- elif value.get('type') == 'never':
- XML.SubElement(policy_element,
- 'runCondition',
- {'class':
- ''.join((run_condition_base_class.get('core'),
- 'NeverRun'))})
- elif value.get('type') == 'boolean-condition':
+ if value.get("type") == "always":
+ XML.SubElement(
+ policy_element,
+ "runCondition",
+ {
+ "class": "".join(
+ (run_condition_base_class.get("core"), "AlwaysRun")
+ )
+ },
+ )
+ elif value.get("type") == "never":
+ XML.SubElement(
+ policy_element,
+ "runCondition",
+ {
+ "class": "".join(
+ (run_condition_base_class.get("core"), "NeverRun")
+ )
+ },
+ )
+ elif value.get("type") == "boolean-condition":
boolean_condition_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('core'),
- 'BooleanCondition'))})
+ "runCondition",
+ {
+ "class": "".join(
+ (run_condition_base_class.get("core"), "BooleanCondition")
+ )
+ },
+ )
helpers.convert_mapping_to_xml(
- boolean_condition_element, value,
- bool_cond_mapping, fail_required=False)
- elif value.get('type') == 'cause-condition':
+ boolean_condition_element,
+ value,
+ bool_cond_mapping,
+ fail_required=False,
+ )
+ elif value.get("type") == "cause-condition":
cause_condition_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('core'),
- 'CauseCondition'))})
+ "runCondition",
+ {
+ "class": "".join(
+ (run_condition_base_class.get("core"), "CauseCondition")
+ )
+ },
+ )
helpers.convert_mapping_to_xml(
- cause_condition_element, value,
- cause_cond_mapping, fail_required=False)
- elif value.get('type') == 'execute-shell':
+ cause_condition_element,
+ value,
+ cause_cond_mapping,
+ fail_required=False,
+ )
+ elif value.get("type") == "execute-shell":
execute_shell_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('shell'),
- 'ShellCondition'))})
+ "runCondition",
+ {
+ "class": "".join(
+ (run_condition_base_class.get("shell"), "ShellCondition")
+ )
+ },
+ )
helpers.convert_mapping_to_xml(
- execute_shell_element, value,
- execute_mapping, fail_required=False)
- elif value.get('type') == 'execute-batch':
+ execute_shell_element, value, execute_mapping, fail_required=False
+ )
+ elif value.get("type") == "execute-batch":
execute_shell_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('shell'),
- 'BatchFileCondition'))})
+ "runCondition",
+ {
+ "class": "".join(
+ (
+ run_condition_base_class.get("shell"),
+ "BatchFileCondition",
+ )
+ )
+ },
+ )
helpers.convert_mapping_to_xml(
- execute_shell_element, value,
- execute_mapping, fail_required=False)
- elif value.get('type') == 'execution-node':
+ execute_shell_element, value, execute_mapping, fail_required=False
+ )
+ elif value.get("type") == "execution-node":
execute_shell_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('core'),
- 'NodeCondition'))})
- allowed_nodes = XML.SubElement(
- execute_shell_element, 'allowedNodes')
- XML.SubElement(allowed_nodes, 'string').text = value.get(
- 'allowed-nodes', None)
- elif value.get('type') == 'regexp-match':
+ "runCondition",
+ {
+ "class": "".join(
+ (run_condition_base_class.get("core"), "NodeCondition")
+ )
+ },
+ )
+ allowed_nodes = XML.SubElement(execute_shell_element, "allowedNodes")
+ XML.SubElement(allowed_nodes, "string").text = value.get(
+ "allowed-nodes", None
+ )
+ elif value.get("type") == "regexp-match":
regexp_match_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('core'),
- 'ExpressionCondition'))})
+ "runCondition",
+ {
+ "class": "".join(
+ (
+ run_condition_base_class.get("core"),
+ "ExpressionCondition",
+ )
+ )
+ },
+ )
helpers.convert_mapping_to_xml(
- regexp_match_element, value,
- regexp_match_mapping, fail_required=False)
- elif value.get('type') == 'strings-match':
+ regexp_match_element,
+ value,
+ regexp_match_mapping,
+ fail_required=False,
+ )
+ elif value.get("type") == "strings-match":
strings_match_element = XML.SubElement(
policy_element,
- 'runCondition',
- {'class': ''.join((run_condition_base_class.get('core'),
- 'StringsMatchCondition'))})
+ "runCondition",
+ {
+ "class": "".join(
+ (
+ run_condition_base_class.get("core"),
+ "StringsMatchCondition",
+ )
+ )
+ },
+ )
helpers.convert_mapping_to_xml(
- strings_match_element, value,
- strings_match_mapping, fail_required=False)
+ strings_match_element,
+ value,
+ strings_match_mapping,
+ fail_required=False,
+ )
else:
- InvalidAttributeError('policy', policy, valid_policies)
+ InvalidAttributeError("policy", policy, valid_policies)
- helpers.convert_mapping_to_xml(
- policy_element, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(policy_element, data, mapping, fail_required=True)
def live_screenshot(registry, xml_parent, data):
@@ -726,12 +809,12 @@ def live_screenshot(registry, xml_parent, data):
/../../tests/wrappers/fixtures/live-screenshot-minimal.yaml
"""
live = XML.SubElement(
- xml_parent,
- 'org.jenkinsci.plugins.livescreenshot.LiveScreenshotBuildWrapper')
- live.set('plugin', 'livescreenshot')
+ xml_parent, "org.jenkinsci.plugins.livescreenshot.LiveScreenshotBuildWrapper"
+ )
+ live.set("plugin", "livescreenshot")
mapping = [
- ('full-size', 'fullscreenFilename', 'screenshot.png'),
- ('thumbnail', 'thumbnailFilename', 'screenshot-thumb.png'),
+ ("full-size", "fullscreenFilename", "screenshot.png"),
+ ("thumbnail", "thumbnailFilename", "screenshot-thumb.png"),
]
helpers.convert_mapping_to_xml(live, data, mapping, fail_required=True)
@@ -747,9 +830,10 @@ def mask_passwords(registry, xml_parent, data):
wrappers:
- mask-passwords
"""
- XML.SubElement(xml_parent,
- 'com.michelin.cio.hudson.plugins.maskpasswords.'
- 'MaskPasswordsBuildWrapper')
+ XML.SubElement(
+ xml_parent,
+ "com.michelin.cio.hudson.plugins.maskpasswords." "MaskPasswordsBuildWrapper",
+ )
def workspace_cleanup(registry, xml_parent, data):
@@ -783,34 +867,27 @@ def workspace_cleanup(registry, xml_parent, data):
:language: yaml
"""
- p = XML.SubElement(xml_parent,
- 'hudson.plugins.ws__cleanup.PreBuildCleanup')
+ p = XML.SubElement(xml_parent, "hudson.plugins.ws__cleanup.PreBuildCleanup")
p.set("plugin", "ws-cleanup")
if "include" in data or "exclude" in data:
- patterns = XML.SubElement(p, 'patterns')
+ patterns = XML.SubElement(p, "patterns")
for inc in data.get("include", []):
- ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
- mapping = [
- ('', 'pattern', inc),
- ('', 'type', "INCLUDE"),
- ]
+ ptrn = XML.SubElement(patterns, "hudson.plugins.ws__cleanup.Pattern")
+ mapping = [("", "pattern", inc), ("", "type", "INCLUDE")]
helpers.convert_mapping_to_xml(ptrn, data, mapping, fail_required=True)
for exc in data.get("exclude", []):
- ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
- mapping = [
- ('', 'pattern', exc),
- ('', 'type', "EXCLUDE"),
- ]
+ ptrn = XML.SubElement(patterns, "hudson.plugins.ws__cleanup.Pattern")
+ mapping = [("", "pattern", exc), ("", "type", "EXCLUDE")]
helpers.convert_mapping_to_xml(ptrn, data, mapping, fail_required=True)
mapping = [
- ("dirmatch", 'deleteDirs', False),
- ('check-parameter', 'cleanupParameter', ''),
- ('external-deletion-command', 'externalDelete', ''),
- ('disable-deferred-wipeout', 'disableDeferredWipeout', False),
+ ("dirmatch", "deleteDirs", False),
+ ("check-parameter", "cleanupParameter", ""),
+ ("external-deletion-command", "externalDelete", ""),
+ ("disable-deferred-wipeout", "disableDeferredWipeout", False),
]
helpers.convert_mapping_to_xml(p, data, mapping, fail_required=True)
@@ -833,14 +910,14 @@ def m2_repository_cleanup(registry, xml_parent, data):
../../tests/wrappers/fixtures/m2-repository-cleanup001.yaml
"""
m2repo = XML.SubElement(
- xml_parent,
- 'hudson.plugins.m2__repo__reaper.M2RepoReaperWrapper')
+ xml_parent, "hudson.plugins.m2__repo__reaper.M2RepoReaperWrapper"
+ )
m2repo.set("plugin", "m2-repo-reaper")
patterns = data.get("patterns", [])
- XML.SubElement(m2repo, 'artifactPatterns').text = ",".join(patterns)
- p = XML.SubElement(m2repo, 'patterns')
+ XML.SubElement(m2repo, "artifactPatterns").text = ",".join(patterns)
+ p = XML.SubElement(m2repo, "patterns")
for pattern in patterns:
- XML.SubElement(p, 'string').text = pattern
+ XML.SubElement(p, "string").text = pattern
def rvm_env(registry, xml_parent, data):
@@ -857,37 +934,29 @@ def rvm_env(registry, xml_parent, data):
- rvm-env:
implementation: 1.9.3
"""
- rpo = XML.SubElement(xml_parent,
- 'ruby-proxy-object')
+ rpo = XML.SubElement(xml_parent, "ruby-proxy-object")
ro_class = "Jenkins::Plugin::Proxies::BuildWrapper"
plugin_info = registry.get_plugin_info("RVM Plugin")
plugin_ver = pkg_resources.parse_version(
- plugin_info.get("version", str(sys.maxsize)))
+ plugin_info.get("version", str(sys.maxsize))
+ )
if plugin_ver >= pkg_resources.parse_version("0.5"):
ro_class = "Jenkins::Tasks::BuildWrapperProxy"
- ro = XML.SubElement(rpo,
- 'ruby-object',
- {'ruby-class': ro_class,
- 'pluginid': 'rvm'})
+ ro = XML.SubElement(rpo, "ruby-object", {"ruby-class": ro_class, "pluginid": "rvm"})
- o = XML.SubElement(ro,
- 'object',
- {'ruby-class': 'RvmWrapper',
- 'pluginid': 'rvm'})
+ o = XML.SubElement(ro, "object", {"ruby-class": "RvmWrapper", "pluginid": "rvm"})
- XML.SubElement(o,
- 'impl',
- {'pluginid': 'rvm',
- 'ruby-class': 'String'}).text = data['implementation']
+ XML.SubElement(o, "impl", {"pluginid": "rvm", "ruby-class": "String"}).text = data[
+ "implementation"
+ ]
- XML.SubElement(ro,
- 'pluginid',
- {'pluginid': 'rvm',
- 'ruby-class': 'String'}).text = "rvm"
+ XML.SubElement(
+ ro, "pluginid", {"pluginid": "rvm", "ruby-class": "String"}
+ ).text = "rvm"
def rbenv(registry, xml_parent, data):
@@ -917,36 +986,34 @@ def rbenv(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/rbenv003.yaml
"""
- rpo = XML.SubElement(xml_parent,
- 'ruby-proxy-object')
+ rpo = XML.SubElement(xml_parent, "ruby-proxy-object")
ro_class = "Jenkins::Tasks::BuildWrapperProxy"
- ro = XML.SubElement(rpo,
- 'ruby-object',
- {'ruby-class': ro_class,
- 'pluginid': 'rbenv'})
+ ro = XML.SubElement(
+ rpo, "ruby-object", {"ruby-class": ro_class, "pluginid": "rbenv"}
+ )
- XML.SubElement(ro,
- 'pluginid',
- {'pluginid': "rbenv",
- 'ruby-class': "String"}).text = "rbenv"
+ XML.SubElement(
+ ro, "pluginid", {"pluginid": "rbenv", "ruby-class": "String"}
+ ).text = "rbenv"
- o = XML.SubElement(ro,
- 'object',
- {'ruby-class': 'RbenvWrapper',
- 'pluginid': 'rbenv'})
+ o = XML.SubElement(
+ ro, "object", {"ruby-class": "RbenvWrapper", "pluginid": "rbenv"}
+ )
mapping = [
# option, xml name, default value (text), attributes (hard coded)
- ("preinstall-gem-list", 'gem__list', 'bundler,rake'),
- ("rbenv-root", 'rbenv__root', '$HOME/.rbenv'),
- ("rbenv-repo", 'rbenv__repository',
- 'https://github.com/rbenv/rbenv'),
- ("rbenv-branch", 'rbenv__revision', 'master'),
- ("ruby-build-repo", 'ruby__build__repository',
- 'https://github.com/rbenv/ruby-build'),
- ("ruby-build-branch", 'ruby__build__revision', 'master'),
- ("ruby-version", 'version', '1.9.3-p484'),
+ ("preinstall-gem-list", "gem__list", "bundler,rake"),
+ ("rbenv-root", "rbenv__root", "$HOME/.rbenv"),
+ ("rbenv-repo", "rbenv__repository", "https://github.com/rbenv/rbenv"),
+ ("rbenv-branch", "rbenv__revision", "master"),
+ (
+ "ruby-build-repo",
+ "ruby__build__repository",
+ "https://github.com/rbenv/ruby-build",
+ ),
+ ("ruby-build-branch", "ruby__build__revision", "master"),
+ ("ruby-version", "version", "1.9.3-p484"),
]
helpers.convert_mapping_to_xml(o, data, mapping, fail_required=False)
@@ -956,17 +1023,18 @@ def rbenv(registry, xml_parent, data):
elem_tag.set("ruby-class", "String")
elem_tag.set("pluginid", "rbenv")
- ignore_local_class = 'FalseClass'
+ ignore_local_class = "FalseClass"
- if 'ignore-local-version' in data:
- ignore_local_string = str(data['ignore-local-version']).lower()
- if ignore_local_string == 'true':
- ignore_local_class = 'TrueClass'
+ if "ignore-local-version" in data:
+ ignore_local_string = str(data["ignore-local-version"]).lower()
+ if ignore_local_string == "true":
+ ignore_local_class = "TrueClass"
- XML.SubElement(o,
- 'ignore__local__version',
- {'ruby-class': ignore_local_class,
- 'pluginid': 'rbenv'})
+ XML.SubElement(
+ o,
+ "ignore__local__version",
+ {"ruby-class": ignore_local_class, "pluginid": "rbenv"},
+ )
def build_name(registry, xml_parent, data):
@@ -985,12 +1053,10 @@ def build_name(registry, xml_parent, data):
- build-name:
name: Build-${FOO}
"""
- bsetter = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.buildnamesetter.'
- 'BuildNameSetter')
- mapping = [
- ('name', 'template', None),
- ]
+ bsetter = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.buildnamesetter." "BuildNameSetter"
+ )
+ mapping = [("name", "template", None)]
helpers.convert_mapping_to_xml(bsetter, data, mapping, fail_required=True)
@@ -1008,22 +1074,22 @@ def port_allocator(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/port-allocator002.yaml
"""
- pa = XML.SubElement(xml_parent,
- 'org.jvnet.hudson.plugins.port__allocator.'
- 'PortAllocator')
- ports = XML.SubElement(pa, 'ports')
- names = data.get('names')
+ pa = XML.SubElement(
+ xml_parent, "org.jvnet.hudson.plugins.port__allocator." "PortAllocator"
+ )
+ ports = XML.SubElement(pa, "ports")
+ names = data.get("names")
if not names:
logger = logging.getLogger(__name__)
logger.warning(
- 'port_allocator name is deprecated, use a names list '
- ' instead')
- names = [data['name']]
+ "port_allocator name is deprecated, use a names list " " instead"
+ )
+ names = [data["name"]]
for name in names:
- dpt = XML.SubElement(ports,
- 'org.jvnet.hudson.plugins.port__allocator.'
- 'DefaultPortType')
- XML.SubElement(dpt, 'name').text = name
+ dpt = XML.SubElement(
+ ports, "org.jvnet.hudson.plugins.port__allocator." "DefaultPortType"
+ )
+ XML.SubElement(dpt, "name").text = name
def locks(registry, xml_parent, data):
@@ -1041,14 +1107,13 @@ def locks(registry, xml_parent, data):
"""
locks = data
if locks:
- lw = XML.SubElement(xml_parent,
- 'hudson.plugins.locksandlatches.LockWrapper')
- locktop = XML.SubElement(lw, 'locks')
+ lw = XML.SubElement(xml_parent, "hudson.plugins.locksandlatches.LockWrapper")
+ locktop = XML.SubElement(lw, "locks")
for lock in locks:
- lockwrapper = XML.SubElement(locktop,
- 'hudson.plugins.locksandlatches.'
- 'LockWrapper_-LockWaitConfig')
- XML.SubElement(lockwrapper, 'name').text = lock
+ lockwrapper = XML.SubElement(
+ locktop, "hudson.plugins.locksandlatches." "LockWrapper_-LockWaitConfig"
+ )
+ XML.SubElement(lockwrapper, "name").text = lock
def copy_to_slave(registry, xml_parent, data):
@@ -1077,18 +1142,18 @@ def copy_to_slave(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/copy-to-slave002.yaml
:language: yaml
"""
- p = 'com.michelin.cio.hudson.plugins.copytoslave.CopyToSlaveBuildWrapper'
+ p = "com.michelin.cio.hudson.plugins.copytoslave.CopyToSlaveBuildWrapper"
cs = XML.SubElement(xml_parent, p)
- XML.SubElement(cs, 'includes').text = ','.join(data.get('includes', ['']))
- XML.SubElement(cs, 'excludes').text = ','.join(data.get('excludes', ['']))
+ XML.SubElement(cs, "includes").text = ",".join(data.get("includes", [""]))
+ XML.SubElement(cs, "excludes").text = ",".join(data.get("excludes", [""]))
- locations = ['home', 'somewhereElse', 'userContent', 'workspace']
+ locations = ["home", "somewhereElse", "userContent", "workspace"]
mapping = [
- ('flatten', 'flatten', False),
- ('include-ant-excludes', 'includeAntExcludes', False),
- ('relative-to', 'relativeTo', 'userContent', locations),
- ('', 'hudsonHomeRelative', False),
+ ("flatten", "flatten", False),
+ ("include-ant-excludes", "includeAntExcludes", False),
+ ("relative-to", "relativeTo", "userContent", locations),
+ ("", "hudsonHomeRelative", False),
]
helpers.convert_mapping_to_xml(cs, data, mapping, fail_required=True)
@@ -1115,24 +1180,22 @@ def inject(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/inject-full.yaml
"""
- eib = XML.SubElement(xml_parent, 'EnvInjectBuildWrapper')
- info = XML.SubElement(eib, 'info')
+ eib = XML.SubElement(xml_parent, "EnvInjectBuildWrapper")
+ info = XML.SubElement(eib, "info")
mapping = [
- ('properties-file', 'propertiesFilePath', None),
- ('properties-content', 'propertiesContent', None),
- ('script-file', 'scriptFilePath', None),
- ('script-content', 'scriptContent', None),
- ('load-from-master', 'loadFilesFromMaster', False),
+ ("properties-file", "propertiesFilePath", None),
+ ("properties-content", "propertiesContent", None),
+ ("script-file", "scriptFilePath", None),
+ ("script-content", "scriptContent", None),
+ ("load-from-master", "loadFilesFromMaster", False),
]
helpers.convert_mapping_to_xml(info, data, mapping, fail_required=False)
- secure_groovy_script = XML.SubElement(info, 'secureGroovyScript')
- mapping = [
- ('groovy-script', 'script', None),
- ('groovy-sandbox', 'sandbox', False),
- ]
- helpers.convert_mapping_to_xml(secure_groovy_script, data, mapping,
- fail_required=False)
+ secure_groovy_script = XML.SubElement(info, "secureGroovyScript")
+ mapping = [("groovy-script", "script", None), ("groovy-sandbox", "sandbox", False)]
+ helpers.convert_mapping_to_xml(
+ secure_groovy_script, data, mapping, fail_required=False
+ )
def inject_ownership_variables(registry, xml_parent, data):
@@ -1151,14 +1214,15 @@ def inject_ownership_variables(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/ownership001.yaml
"""
- ownership = XML.SubElement(xml_parent, 'com.synopsys.arc.jenkins.plugins.'
- 'ownership.wrappers.OwnershipBuildWrapper')
+ ownership = XML.SubElement(
+ xml_parent,
+ "com.synopsys.arc.jenkins.plugins." "ownership.wrappers.OwnershipBuildWrapper",
+ )
mapping = [
- ('node-variables', 'injectNodeOwnership', False),
- ('job-variables', 'injectJobOwnership', False),
+ ("node-variables", "injectNodeOwnership", False),
+ ("job-variables", "injectJobOwnership", False),
]
- helpers.convert_mapping_to_xml(
- ownership, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(ownership, data, mapping, fail_required=True)
def inject_passwords(registry, xml_parent, data):
@@ -1178,24 +1242,20 @@ def inject_passwords(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/passwords001.yaml
"""
- eib = XML.SubElement(xml_parent, 'EnvInjectPasswordWrapper')
+ eib = XML.SubElement(xml_parent, "EnvInjectPasswordWrapper")
mapping = [
- ('global', 'injectGlobalPasswords', False),
- ('mask-password-params', 'maskPasswordParameters', False),
+ ("global", "injectGlobalPasswords", False),
+ ("mask-password-params", "maskPasswordParameters", False),
]
helpers.convert_mapping_to_xml(eib, data, mapping, fail_required=True)
- entries = XML.SubElement(eib, 'passwordEntries')
- passwords = data.get('job-passwords', [])
+ entries = XML.SubElement(eib, "passwordEntries")
+ passwords = data.get("job-passwords", [])
if passwords:
for password in passwords:
- entry = XML.SubElement(entries, 'EnvInjectPasswordEntry')
- mapping = [
- ('name', 'name', None),
- ('password', 'value', None),
- ]
- helpers.convert_mapping_to_xml(entry, password,
- mapping, fail_required=True)
+ entry = XML.SubElement(entries, "EnvInjectPasswordEntry")
+ mapping = [("name", "name", None), ("password", "value", None)]
+ helpers.convert_mapping_to_xml(entry, password, mapping, fail_required=True)
def vault_secrets(registry, xml_parent, data):
@@ -1235,42 +1295,39 @@ def vault_secrets(registry, xml_parent, data):
:language: yaml
"""
- vault = XML.SubElement(xml_parent,
- 'com.datapipe.jenkins.vault.VaultBuildWrapper')
- vault.set('plugin', 'hashicorp-vault-plugin')
- configuration = XML.SubElement(vault, 'configuration')
+ vault = XML.SubElement(xml_parent, "com.datapipe.jenkins.vault.VaultBuildWrapper")
+ vault.set("plugin", "hashicorp-vault-plugin")
+ configuration = XML.SubElement(vault, "configuration")
conf_mapping = [
- ('vault-url', 'vaultUrl', ''),
- ('credentials-id', 'vaultCredentialId', ''),
+ ("vault-url", "vaultUrl", ""),
+ ("credentials-id", "vaultCredentialId", ""),
]
helpers.convert_mapping_to_xml(
- configuration, data, conf_mapping, fail_required=True)
+ configuration, data, conf_mapping, fail_required=True
+ )
- secret_obj_mapping = [
- ('secret-path', 'path', ''),
- ]
- secret_value_mapping = [
- ('env-var', 'envVar', ''),
- ('vault-key', 'vaultKey', ''),
- ]
- secretsobj = XML.SubElement(vault, 'vaultSecrets')
- secrets = data.get('secrets', [])
+ secret_obj_mapping = [("secret-path", "path", "")]
+ secret_value_mapping = [("env-var", "envVar", ""), ("vault-key", "vaultKey", "")]
+ secretsobj = XML.SubElement(vault, "vaultSecrets")
+ secrets = data.get("secrets", [])
for secret in secrets:
secretobj = XML.SubElement(
- secretsobj, 'com.datapipe.jenkins.vault.model.VaultSecret')
+ secretsobj, "com.datapipe.jenkins.vault.model.VaultSecret"
+ )
helpers.convert_mapping_to_xml(
- secretobj, secret, secret_obj_mapping, fail_required=False)
- secretvaluesobj = XML.SubElement(secretobj, 'secretValues')
- for secretvalue in secret['secret-values']:
+ secretobj, secret, secret_obj_mapping, fail_required=False
+ )
+ secretvaluesobj = XML.SubElement(secretobj, "secretValues")
+ for secretvalue in secret["secret-values"]:
secretvalueobj = XML.SubElement(
- secretvaluesobj,
- 'com.datapipe.jenkins.vault.model.VaultSecretValue')
+ secretvaluesobj, "com.datapipe.jenkins.vault.model.VaultSecretValue"
+ )
helpers.convert_mapping_to_xml(
- secretvalueobj, secretvalue,
- secret_value_mapping, fail_required=False)
- XML.SubElement(vault, 'valuesToMask')
- XML.SubElement(vault, 'vaultAccessor')
+ secretvalueobj, secretvalue, secret_value_mapping, fail_required=False
+ )
+ XML.SubElement(vault, "valuesToMask")
+ XML.SubElement(vault, "vaultAccessor")
def env_file(registry, xml_parent, data):
@@ -1287,11 +1344,8 @@ def env_file(registry, xml_parent, data):
- env-file:
properties-file: ${WORKSPACE}/foo
"""
- eib = XML.SubElement(xml_parent,
- 'hudson.plugins.envfile.EnvFileBuildWrapper')
- mapping = [
- ('properties-file', 'filePath', None),
- ]
+ eib = XML.SubElement(xml_parent, "hudson.plugins.envfile.EnvFileBuildWrapper")
+ mapping = [("properties-file", "filePath", None)]
helpers.convert_mapping_to_xml(eib, data, mapping, fail_required=False)
@@ -1316,17 +1370,17 @@ def env_script(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/env-script001.yaml
"""
- el = XML.SubElement(xml_parent, 'com.lookout.jenkins.EnvironmentScript')
+ el = XML.SubElement(xml_parent, "com.lookout.jenkins.EnvironmentScript")
valid_script_types = {
- 'unix-script': 'unixScript',
- 'power-shell': 'powerShell',
- 'batch-script': 'batchScript',
+ "unix-script": "unixScript",
+ "power-shell": "powerShell",
+ "batch-script": "batchScript",
}
mapping = [
- ('script-content', 'script', ''),
- ('script-type', 'scriptType', 'unix-script', valid_script_types),
- ('only-run-on-parent', 'runOnlyOnParent', False),
+ ("script-content", "script", ""),
+ ("script-type", "scriptType", "unix-script", valid_script_types),
+ ("only-run-on-parent", "runOnlyOnParent", False),
]
helpers.convert_mapping_to_xml(el, data, mapping, fail_required=True)
@@ -1354,26 +1408,28 @@ def jclouds(registry, xml_parent, data):
"""
mapping = [
- ('cloud-name', 'cloudName', ''),
- ('count', 'count', '1'),
- ('stop-on-terminate', 'suspendOrTerminate', False),
+ ("cloud-name", "cloudName", ""),
+ ("count", "count", "1"),
+ ("stop-on-terminate", "suspendOrTerminate", False),
]
- if 'instances' in data:
+ if "instances" in data:
buildWrapper = XML.SubElement(
- xml_parent, 'jenkins.plugins.jclouds.compute.JCloudsBuildWrapper')
- instances = XML.SubElement(buildWrapper, 'instancesToRun')
- for foo in data['instances']:
+ xml_parent, "jenkins.plugins.jclouds.compute.JCloudsBuildWrapper"
+ )
+ instances = XML.SubElement(buildWrapper, "instancesToRun")
+ for foo in data["instances"]:
for template, params in foo.items():
- instance = XML.SubElement(instances,
- 'jenkins.plugins.jclouds.compute.'
- 'InstancesToRun')
- XML.SubElement(instance, 'templateName').text = template
+ instance = XML.SubElement(
+ instances, "jenkins.plugins.jclouds.compute." "InstancesToRun"
+ )
+ XML.SubElement(instance, "templateName").text = template
helpers.convert_mapping_to_xml(
- instance, params, mapping, fail_required=False)
- if data.get('single-use'):
- XML.SubElement(xml_parent,
- 'jenkins.plugins.jclouds.compute.'
- 'JCloudsOneOffSlave')
+ instance, params, mapping, fail_required=False
+ )
+ if data.get("single-use"):
+ XML.SubElement(
+ xml_parent, "jenkins.plugins.jclouds.compute." "JCloudsOneOffSlave"
+ )
def openstack(registry, xml_parent, data):
@@ -1403,32 +1459,34 @@ def openstack(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/openstack001.yaml
"""
- tag_prefix = 'jenkins.plugins.openstack.compute.'
+ tag_prefix = "jenkins.plugins.openstack.compute."
- if 'instances' in data:
+ if "instances" in data:
clouds_build_wrapper = XML.SubElement(
- xml_parent, tag_prefix + 'JCloudsBuildWrapper')
- instances_wrapper = XML.SubElement(
- clouds_build_wrapper, 'instancesToRun')
+ xml_parent, tag_prefix + "JCloudsBuildWrapper"
+ )
+ instances_wrapper = XML.SubElement(clouds_build_wrapper, "instancesToRun")
- for instance in data['instances']:
+ for instance in data["instances"]:
instances_to_run = XML.SubElement(
- instances_wrapper, tag_prefix + 'InstancesToRun')
+ instances_wrapper, tag_prefix + "InstancesToRun"
+ )
- instance_mapping = [('cloud-name', 'cloudName', None),
- ('count', 'count', 1)]
+ instance_mapping = [
+ ("cloud-name", "cloudName", None),
+ ("count", "count", 1),
+ ]
- if instance.get('manual-template', False):
- instance_mapping.append(('template-name',
- 'manualTemplateName', None))
+ if instance.get("manual-template", False):
+ instance_mapping.append(("template-name", "manualTemplateName", None))
else:
- instance_mapping.append(('template-name',
- 'templateName', None))
- helpers.convert_mapping_to_xml(instances_to_run,
- instance, instance_mapping, fail_required=True)
+ instance_mapping.append(("template-name", "templateName", None))
+ helpers.convert_mapping_to_xml(
+ instances_to_run, instance, instance_mapping, fail_required=True
+ )
- if data.get('single-use', False):
- XML.SubElement(xml_parent, tag_prefix + 'JCloudsOneOffSlave')
+ if data.get("single-use", False):
+ XML.SubElement(xml_parent, tag_prefix + "JCloudsOneOffSlave")
def build_user_vars(registry, xml_parent, data):
@@ -1442,7 +1500,7 @@ def build_user_vars(registry, xml_parent, data):
wrappers:
- build-user-vars
"""
- XML.SubElement(xml_parent, 'org.jenkinsci.plugins.builduser.BuildUser')
+ XML.SubElement(xml_parent, "org.jenkinsci.plugins.builduser.BuildUser")
def release(registry, xml_parent, data):
@@ -1465,35 +1523,32 @@ def release(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/release001.yaml
"""
- relwrap = XML.SubElement(xml_parent,
- 'hudson.plugins.release.ReleaseWrapper')
+ relwrap = XML.SubElement(xml_parent, "hudson.plugins.release.ReleaseWrapper")
# For 'keep-forever', the sense of the XML flag is the opposite of
# the YAML flag.
mapping = [
- ('do-not-keep-log',
- 'doNotKeepLog',
- not data.get('keep-forever', True)),
- ('override-build-parameters', 'overrideBuildParameters', False),
- ('version-template', 'releaseVersionTemplate', ''),
+ ("do-not-keep-log", "doNotKeepLog", not data.get("keep-forever", True)),
+ ("override-build-parameters", "overrideBuildParameters", False),
+ ("version-template", "releaseVersionTemplate", ""),
]
helpers.convert_mapping_to_xml(relwrap, data, mapping, fail_required=True)
- parameters = data.get('parameters', [])
+ parameters = data.get("parameters", [])
if parameters:
- pdef = XML.SubElement(relwrap, 'parameterDefinitions')
+ pdef = XML.SubElement(relwrap, "parameterDefinitions")
for param in parameters:
- registry.dispatch('parameter', pdef, param)
+ registry.dispatch("parameter", pdef, param)
builder_steps = {
- 'pre-build': 'preBuildSteps',
- 'post-build': 'postBuildSteps',
- 'post-success': 'postSuccessfulBuildSteps',
- 'post-fail': 'postFailedBuildSteps',
+ "pre-build": "preBuildSteps",
+ "post-build": "postBuildSteps",
+ "post-success": "postSuccessfulBuildSteps",
+ "post-fail": "postFailedBuildSteps",
}
for step in builder_steps.keys():
for builder in data.get(step, []):
- registry.dispatch('builder',
- XML.SubElement(relwrap, builder_steps[step]),
- builder)
+ registry.dispatch(
+ "builder", XML.SubElement(relwrap, builder_steps[step]), builder
+ )
def sauce_ondemand(registry, xml_parent, data):
@@ -1557,65 +1612,62 @@ def sauce_ondemand(registry, xml_parent, data):
- Linuxfirefox11
launch-sauce-connect-on-slave: true
"""
- sauce = XML.SubElement(xml_parent, 'hudson.plugins.sauce__ondemand.'
- 'SauceOnDemandBuildWrapper')
+ sauce = XML.SubElement(
+ xml_parent, "hudson.plugins.sauce__ondemand." "SauceOnDemandBuildWrapper"
+ )
mapping = [
- ('enable-sauce-connect', 'enableSauceConnect', False),
- ('sauce-host', 'seleniumHost', ''),
- ('sauce-port', 'seleniumPort', ''),
- ('launch-sauce-connect-on-slave', 'launchSauceConnectOnSlave', False),
- ('https-protocol', 'httpsProtocol', ''),
- ('sauce-connect-options', 'options', ''),
+ ("enable-sauce-connect", "enableSauceConnect", False),
+ ("sauce-host", "seleniumHost", ""),
+ ("sauce-port", "seleniumPort", ""),
+ ("launch-sauce-connect-on-slave", "launchSauceConnectOnSlave", False),
+ ("https-protocol", "httpsProtocol", ""),
+ ("sauce-connect-options", "options", ""),
]
helpers.convert_mapping_to_xml(sauce, data, mapping, fail_required=True)
# Optional override global authentication
- username = data.get('override-username')
- key = data.get('override-api-access-key')
+ username = data.get("override-username")
+ key = data.get("override-api-access-key")
if username and key:
- cred = XML.SubElement(sauce, 'credentials')
+ cred = XML.SubElement(sauce, "credentials")
mapping = [
- ('override-username', 'username', None),
- ('override-api-access-key', 'apiKey', None),
+ ("override-username", "username", None),
+ ("override-api-access-key", "apiKey", None),
]
helpers.convert_mapping_to_xml(cred, data, mapping, fail_required=True)
- atype = data.get('type', 'selenium')
- info = XML.SubElement(sauce, 'seleniumInformation')
+ atype = data.get("type", "selenium")
+ info = XML.SubElement(sauce, "seleniumInformation")
- if atype == 'selenium':
+ if atype == "selenium":
selenium_mapping = [
- ('starting-url', 'seleniumBrowsers', ''),
- ('', 'isWebDriver', False),
+ ("starting-url", "seleniumBrowsers", ""),
+ ("", "isWebDriver", False),
]
+ helpers.convert_mapping_to_xml(info, data, selenium_mapping, fail_required=True)
+
+ browsers = XML.SubElement(info, "seleniumBrowsers")
+ for platform in data["platforms"]:
+ mapping = [("", "string", platform)]
+ helpers.convert_mapping_to_xml(browsers, data, mapping, fail_required=True)
+ XML.SubElement(
+ sauce,
+ "seleniumBrowsers",
+ {"reference": "../seleniumInformation/" "seleniumBrowsers"},
+ )
+ if atype == "webdriver":
+ browsers = XML.SubElement(info, "webDriverBrowsers")
+ for platform in data["platforms"]:
+ mapping = [("", "string", platform)]
+ helpers.convert_mapping_to_xml(browsers, data, mapping, fail_required=True)
+ webdriver_mapping = [("", "isWebDriver", True)]
helpers.convert_mapping_to_xml(
- info, data, selenium_mapping, fail_required=True)
-
- browsers = XML.SubElement(info, 'seleniumBrowsers')
- for platform in data['platforms']:
- mapping = [
- ('', 'string', platform),
- ]
- helpers.convert_mapping_to_xml(
- browsers, data, mapping, fail_required=True)
- XML.SubElement(sauce, 'seleniumBrowsers',
- {'reference': '../seleniumInformation/'
- 'seleniumBrowsers'})
- if atype == 'webdriver':
- browsers = XML.SubElement(info, 'webDriverBrowsers')
- for platform in data['platforms']:
- mapping = [
- ('', 'string', platform),
- ]
- helpers.convert_mapping_to_xml(
- browsers, data, mapping, fail_required=True)
- webdriver_mapping = [
- ('', 'isWebDriver', True),
- ]
- helpers.convert_mapping_to_xml(
- info, data, webdriver_mapping, fail_required=True)
- XML.SubElement(sauce, 'webDriverBrowsers',
- {'reference': '../seleniumInformation/'
- 'webDriverBrowsers'})
+ info, data, webdriver_mapping, fail_required=True
+ )
+ XML.SubElement(
+ sauce,
+ "webDriverBrowsers",
+ {"reference": "../seleniumInformation/" "webDriverBrowsers"},
+ )
def sonar(registry, xml_parent, data):
@@ -1635,16 +1687,12 @@ def sonar(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/sonar-full.yaml
:language: yaml
"""
- sonar = XML.SubElement(
- xml_parent, 'hudson.plugins.sonar.SonarBuildWrapper')
- sonar.set('plugin', 'sonar')
+ sonar = XML.SubElement(xml_parent, "hudson.plugins.sonar.SonarBuildWrapper")
+ sonar.set("plugin", "sonar")
- if data.get('install-name'):
- mapping = [
- ('install-name', 'installationName', ''),
- ]
- helpers.convert_mapping_to_xml(
- sonar, data, mapping, fail_required=True)
+ if data.get("install-name"):
+ mapping = [("install-name", "installationName", "")]
+ helpers.convert_mapping_to_xml(sonar, data, mapping, fail_required=True)
def pathignore(registry, xml_parent, data):
@@ -1662,25 +1710,29 @@ def pathignore(registry, xml_parent, data):
- pathignore:
ignored: "docs, tests"
"""
- ruby = XML.SubElement(xml_parent, 'ruby-proxy-object')
- robj = XML.SubElement(ruby, 'ruby-object', attrib={
- 'pluginid': 'pathignore',
- 'ruby-class': 'Jenkins::Plugin::Proxies::BuildWrapper'
- })
- pluginid = XML.SubElement(robj, 'pluginid', {
- 'pluginid': 'pathignore', 'ruby-class': 'String'
- })
- pluginid.text = 'pathignore'
- obj = XML.SubElement(robj, 'object', {
- 'ruby-class': 'PathignoreWrapper', 'pluginid': 'pathignore'
- })
- ignored = XML.SubElement(obj, 'ignored__paths', {
- 'pluginid': 'pathignore', 'ruby-class': 'String'
- })
- ignored.text = data.get('ignored', '')
- XML.SubElement(obj, 'invert__ignore', {
- 'ruby-class': 'FalseClass', 'pluginid': 'pathignore'
- })
+ ruby = XML.SubElement(xml_parent, "ruby-proxy-object")
+ robj = XML.SubElement(
+ ruby,
+ "ruby-object",
+ attrib={
+ "pluginid": "pathignore",
+ "ruby-class": "Jenkins::Plugin::Proxies::BuildWrapper",
+ },
+ )
+ pluginid = XML.SubElement(
+ robj, "pluginid", {"pluginid": "pathignore", "ruby-class": "String"}
+ )
+ pluginid.text = "pathignore"
+ obj = XML.SubElement(
+ robj, "object", {"ruby-class": "PathignoreWrapper", "pluginid": "pathignore"}
+ )
+ ignored = XML.SubElement(
+ obj, "ignored__paths", {"pluginid": "pathignore", "ruby-class": "String"}
+ )
+ ignored.text = data.get("ignored", "")
+ XML.SubElement(
+ obj, "invert__ignore", {"ruby-class": "FalseClass", "pluginid": "pathignore"}
+ )
def pre_scm_buildstep(registry, xml_parent, data):
@@ -1701,22 +1753,20 @@ def pre_scm_buildstep(registry, xml_parent, data):
:language: yaml
"""
# Get plugin information to maintain backwards compatibility
- info = registry.get_plugin_info('preSCMbuildstep')
- version = pkg_resources.parse_version(info.get('version', "0"))
+ info = registry.get_plugin_info("preSCMbuildstep")
+ version = pkg_resources.parse_version(info.get("version", "0"))
- bsp = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.preSCMbuildstep.'
- 'PreSCMBuildStepsWrapper')
- bs = XML.SubElement(bsp, 'buildSteps')
- stepList = data if type(data) is list else data.get('buildsteps')
+ bsp = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.preSCMbuildstep." "PreSCMBuildStepsWrapper"
+ )
+ bs = XML.SubElement(bsp, "buildSteps")
+ stepList = data if type(data) is list else data.get("buildsteps")
for step in stepList:
for edited_node in create_builders(registry, step):
bs.append(edited_node)
if version >= pkg_resources.parse_version("0.3"):
- mapping = [
- ('failOnError', 'failOnError', False),
- ]
+ mapping = [("failOnError", "failOnError", False)]
helpers.convert_mapping_to_xml(bsp, data, mapping, fail_required=True)
@@ -1744,30 +1794,29 @@ def logstash(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/logstash001.yaml
"""
- logstash = XML.SubElement(xml_parent,
- 'jenkins.plugins.logstash.'
- 'LogstashBuildWrapper')
- logstash.set('plugin', 'logstash@0.8.0')
+ logstash = XML.SubElement(
+ xml_parent, "jenkins.plugins.logstash." "LogstashBuildWrapper"
+ )
+ logstash.set("plugin", "logstash@0.8.0")
- mapping = [
- ('use-redis', 'useRedis', True),
- ]
+ mapping = [("use-redis", "useRedis", True)]
helpers.convert_mapping_to_xml(logstash, data, mapping, fail_required=True)
- if data.get('use-redis'):
- redis_config = data.get('redis', {})
- redis_sub_element = XML.SubElement(logstash, 'redis')
+ if data.get("use-redis"):
+ redis_config = data.get("redis", {})
+ redis_sub_element = XML.SubElement(logstash, "redis")
mapping = [
- ('host', 'host', 'localhost'),
- ('port', 'port', '6379'),
- ('database-number', 'numb', '0'),
- ('database-password', 'pass', ''),
- ('data-type', 'dataType', 'list'),
- ('key', 'key', 'logstash'),
+ ("host", "host", "localhost"),
+ ("port", "port", "6379"),
+ ("database-number", "numb", "0"),
+ ("database-password", "pass", ""),
+ ("data-type", "dataType", "list"),
+ ("key", "key", "logstash"),
]
- helpers.convert_mapping_to_xml(redis_sub_element,
- redis_config, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(
+ redis_sub_element, redis_config, mapping, fail_required=True
+ )
def mongo_db(registry, xml_parent, data):
@@ -1790,17 +1839,17 @@ def mongo_db(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/mongo-db-minimal.yaml
"""
- mongodb = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.mongodb.'
- 'MongoBuildWrapper')
- mongodb.set('plugin', 'mongodb')
+ mongodb = XML.SubElement(
+ xml_parent, "org.jenkinsci.plugins.mongodb." "MongoBuildWrapper"
+ )
+ mongodb.set("plugin", "mongodb")
mapping = [
- ('name', 'mongodbName', None),
- ('port', 'port', ''),
- ('data-directory', 'dbpath', ''),
- ('startup-params', 'parameters', ''),
- ('start-timeout', 'startTimeout', 0),
+ ("name", "mongodbName", None),
+ ("port", "port", ""),
+ ("data-directory", "dbpath", ""),
+ ("startup-params", "parameters", ""),
+ ("start-timeout", "startTimeout", 0),
]
helpers.convert_mapping_to_xml(mongodb, data, mapping, fail_required=True)
@@ -1832,12 +1881,13 @@ def delivery_pipeline(registry, xml_parent, data):
:language: yaml
"""
pvc = XML.SubElement(
- xml_parent, 'se.diabol.jenkins.pipeline.PipelineVersionContributor')
- pvc.set('plugin', 'delivery-pipeline-plugin')
+ xml_parent, "se.diabol.jenkins.pipeline.PipelineVersionContributor"
+ )
+ pvc.set("plugin", "delivery-pipeline-plugin")
mapping = [
- ('version-template', 'versionTemplate', ''),
- ('set-display-name', 'updateDisplayName', False),
+ ("version-template", "versionTemplate", ""),
+ ("set-display-name", "updateDisplayName", False),
]
helpers.convert_mapping_to_xml(pvc, data, mapping, fail_required=True)
@@ -1858,10 +1908,8 @@ def matrix_tie_parent(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/matrix-tie-parent.yaml
"""
- mtp = XML.SubElement(xml_parent, 'matrixtieparent.BuildWrapperMtp')
- mapping = [
- ('node', 'labelName', None),
- ]
+ mtp = XML.SubElement(xml_parent, "matrixtieparent.BuildWrapperMtp")
+ mapping = [("node", "labelName", None)]
helpers.convert_mapping_to_xml(mtp, data, mapping, fail_required=True)
@@ -1880,17 +1928,13 @@ def exclusion(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/exclusion002.yaml
"""
- exl = XML.SubElement(xml_parent,
- 'org.jvnet.hudson.plugins.exclusion.IdAllocator')
- exl.set('plugin', 'Exclusion')
- ids = XML.SubElement(exl, 'ids')
- resources = data.get('resources', [])
+ exl = XML.SubElement(xml_parent, "org.jvnet.hudson.plugins.exclusion.IdAllocator")
+ exl.set("plugin", "Exclusion")
+ ids = XML.SubElement(exl, "ids")
+ resources = data.get("resources", [])
for resource in resources:
- dit = XML.SubElement(ids,
- 'org.jvnet.hudson.plugins.exclusion.DefaultIdType')
- mapping = [
- ('', 'name', resource.upper()),
- ]
+ dit = XML.SubElement(ids, "org.jvnet.hudson.plugins.exclusion.DefaultIdType")
+ mapping = [("", "name", resource.upper())]
helpers.convert_mapping_to_xml(dit, data, mapping, fail_required=True)
@@ -1938,37 +1982,37 @@ def ssh_agent_credentials(registry, xml_parent, data):
logger = logging.getLogger(__name__)
entry_xml = XML.SubElement(
- xml_parent,
- 'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper')
- xml_key = 'user'
+ xml_parent, "com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper"
+ )
+ xml_key = "user"
user_list = list()
- if 'users' in data:
- user_list += data['users']
+ if "users" in data:
+ user_list += data["users"]
if len(user_list) > 1:
- entry_xml = XML.SubElement(entry_xml, 'credentialIds')
- xml_key = 'string'
- if 'user' in data:
+ entry_xml = XML.SubElement(entry_xml, "credentialIds")
+ xml_key = "string"
+ if "user" in data:
logger.warning(
"Both 'users' and 'user' parameters specified for "
"ssh-agent-credentials. 'users' is used, 'user' is "
- "ignored.")
- elif 'user' in data:
- logger.warning("The 'user' param has been deprecated, "
- "use the 'users' param instead.")
- user_list.append(data['user'])
+ "ignored."
+ )
+ elif "user" in data:
+ logger.warning(
+ "The 'user' param has been deprecated, " "use the 'users' param instead."
+ )
+ user_list.append(data["user"])
else:
- raise JenkinsJobsException("Missing 'user' or 'users' parameter "
- "for ssh-agent-credentials")
+ raise JenkinsJobsException(
+ "Missing 'user' or 'users' parameter " "for ssh-agent-credentials"
+ )
for user in user_list:
XML.SubElement(entry_xml, xml_key).text = user
- mapping = [
- ('ignore-missing-credentials', 'ignoreMissing', False),
- ]
- helpers.convert_mapping_to_xml(entry_xml, data, mapping,
- fail_required=False)
+ mapping = [("ignore-missing-credentials", "ignoreMissing", False)]
+ helpers.convert_mapping_to_xml(entry_xml, data, mapping, fail_required=False)
def credentials_binding(registry, xml_parent, data):
@@ -2034,88 +2078,87 @@ def credentials_binding(registry, xml_parent, data):
"""
entry_xml = xml_parent.find(
- 'org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper')
+ "org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper"
+ )
if entry_xml is None:
entry_xml = XML.SubElement(
xml_parent,
- 'org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper')
+ "org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper",
+ )
- bindings_xml = entry_xml.find('bindings')
+ bindings_xml = entry_xml.find("bindings")
if bindings_xml is None:
- bindings_xml = XML.SubElement(entry_xml, 'bindings')
+ bindings_xml = XML.SubElement(entry_xml, "bindings")
binding_types = {
- 'zip-file': 'org.jenkinsci.plugins.credentialsbinding.impl.'
- 'ZipFileBinding',
- 'file': 'org.jenkinsci.plugins.credentialsbinding.impl.FileBinding',
- 'username-password': 'org.jenkinsci.plugins.credentialsbinding.impl.'
- 'UsernamePasswordBinding',
- 'username-password-separated': 'org.jenkinsci.plugins.'
- 'credentialsbinding.impl.'
- 'UsernamePasswordMultiBinding',
- 'text': 'org.jenkinsci.plugins.credentialsbinding.impl.StringBinding',
- 'amazon-web-services':
- 'com.cloudbees.jenkins.plugins.awscredentials'
- '.AmazonWebServicesCredentialsBinding',
- 'ssh-user-private-key':
- 'org.jenkinsci.plugins.credentialsbinding'
- '.impl.SSHUserPrivateKeyBinding',
- 'docker-server-creds-binding':
- 'org.jenkinsci.plugins.docker.commons'
- '.credentials.DockerServerCredentialsBinding',
- 'cert-multi-binding':
- 'org.jenkinsci.plugins.credentialsbinding'
- '.impl.CertificateMultiBinding'
+ "zip-file": "org.jenkinsci.plugins.credentialsbinding.impl." "ZipFileBinding",
+ "file": "org.jenkinsci.plugins.credentialsbinding.impl.FileBinding",
+ "username-password": "org.jenkinsci.plugins.credentialsbinding.impl."
+ "UsernamePasswordBinding",
+ "username-password-separated": "org.jenkinsci.plugins."
+ "credentialsbinding.impl."
+ "UsernamePasswordMultiBinding",
+ "text": "org.jenkinsci.plugins.credentialsbinding.impl.StringBinding",
+ "amazon-web-services": "com.cloudbees.jenkins.plugins.awscredentials"
+ ".AmazonWebServicesCredentialsBinding",
+ "ssh-user-private-key": "org.jenkinsci.plugins.credentialsbinding"
+ ".impl.SSHUserPrivateKeyBinding",
+ "docker-server-creds-binding": "org.jenkinsci.plugins.docker.commons"
+ ".credentials.DockerServerCredentialsBinding",
+ "cert-multi-binding": "org.jenkinsci.plugins.credentialsbinding"
+ ".impl.CertificateMultiBinding",
}
for binding in data:
for binding_type, params in binding.items():
if binding_type not in binding_types.keys():
- raise JenkinsJobsException('binding-type must be one of %r' %
- binding_types.keys())
+ raise JenkinsJobsException(
+ "binding-type must be one of %r" % binding_types.keys()
+ )
- binding_xml = XML.SubElement(bindings_xml,
- binding_types[binding_type])
- if binding_type == 'username-password-separated':
+ binding_xml = XML.SubElement(bindings_xml, binding_types[binding_type])
+ if binding_type == "username-password-separated":
mapping = [
- ('username', 'usernameVariable', None),
- ('password', 'passwordVariable', None),
+ ("username", "usernameVariable", None),
+ ("password", "passwordVariable", None),
]
helpers.convert_mapping_to_xml(
- binding_xml, params, mapping, fail_required=True)
- elif binding_type == 'amazon-web-services':
+ binding_xml, params, mapping, fail_required=True
+ )
+ elif binding_type == "amazon-web-services":
mapping = [
- ('access-key', 'accessKeyVariable', None),
- ('secret-key', 'secretKeyVariable', None),
+ ("access-key", "accessKeyVariable", None),
+ ("secret-key", "secretKeyVariable", None),
]
helpers.convert_mapping_to_xml(
- binding_xml, params, mapping, fail_required=True)
- elif binding_type == 'ssh-user-private-key':
+ binding_xml, params, mapping, fail_required=True
+ )
+ elif binding_type == "ssh-user-private-key":
mapping = [
- ('key-file-variable', 'keyFileVariable', None),
- ('username-variable', 'usernameVariable', ''),
- ('passphrase-variable', 'passphraseVariable', ''),
+ ("key-file-variable", "keyFileVariable", None),
+ ("username-variable", "usernameVariable", ""),
+ ("passphrase-variable", "passphraseVariable", ""),
]
helpers.convert_mapping_to_xml(
- binding_xml, params, mapping, fail_required=True)
- elif binding_type == 'cert-multi-binding':
+ binding_xml, params, mapping, fail_required=True
+ )
+ elif binding_type == "cert-multi-binding":
mapping = [
- ('keystore-variable', 'keystoreVariable', None),
- ('password-variable', 'passwordVariable', None),
- ('alias-variable', 'aliasVariable', None),
+ ("keystore-variable", "keystoreVariable", None),
+ ("password-variable", "passwordVariable", None),
+ ("alias-variable", "aliasVariable", None),
]
helpers.convert_mapping_to_xml(
- binding_xml, params, mapping, fail_required=True)
+ binding_xml, params, mapping, fail_required=True
+ )
else:
- mapping = [
- ('variable', 'variable', None),
- ]
+ mapping = [("variable", "variable", None)]
helpers.convert_mapping_to_xml(
- binding_xml, params, mapping, fail_required=False)
- mapping = [
- ('credential-id', 'credentialsId', None),
- ]
- helpers.convert_mapping_to_xml(binding_xml,
- params, mapping, fail_required=False)
+ binding_xml, params, mapping, fail_required=False
+ )
+ mapping = [("credential-id", "credentialsId", None)]
+ helpers.convert_mapping_to_xml(
+ binding_xml, params, mapping, fail_required=False
+ )
def custom_tools(registry, xml_parent, data):
@@ -2134,31 +2177,22 @@ def custom_tools(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/custom-tools001.yaml
"""
- base = 'com.cloudbees.jenkins.plugins.customtools'
- wrapper = XML.SubElement(xml_parent,
- base + ".CustomToolInstallWrapper")
+ base = "com.cloudbees.jenkins.plugins.customtools"
+ wrapper = XML.SubElement(xml_parent, base + ".CustomToolInstallWrapper")
- wrapper_tools = XML.SubElement(wrapper, 'selectedTools')
- tools = data.get('tools', [])
- tool_node = base + '.CustomToolInstallWrapper_-SelectedTool'
+ wrapper_tools = XML.SubElement(wrapper, "selectedTools")
+ tools = data.get("tools", [])
+ tool_node = base + ".CustomToolInstallWrapper_-SelectedTool"
for tool in tools:
tool_wrapper = XML.SubElement(wrapper_tools, tool_node)
- mapping = [
- ('', 'name', tool),
- ]
- helpers.convert_mapping_to_xml(
- tool_wrapper, data, mapping, fail_required=True)
+ mapping = [("", "name", tool)]
+ helpers.convert_mapping_to_xml(tool_wrapper, data, mapping, fail_required=True)
- opts = XML.SubElement(wrapper,
- 'multiconfigOptions')
- mapping = [
- ('skip-master-install', 'skipMasterInstallation', False),
- ]
+ opts = XML.SubElement(wrapper, "multiconfigOptions")
+ mapping = [("skip-master-install", "skipMasterInstallation", False)]
helpers.convert_mapping_to_xml(opts, data, mapping, fail_required=True)
- mapping = [
- ('convert-homes-to-upper', 'convertHomesToUppercase', False),
- ]
+ mapping = [("convert-homes-to-upper", "convertHomesToUppercase", False)]
helpers.convert_mapping_to_xml(wrapper, data, mapping, fail_required=True)
@@ -2174,15 +2208,13 @@ def nodejs_installator(registry, xml_parent, data):
.. literalinclude::
/../../tests/wrappers/fixtures/nodejs-installator001.yaml
"""
- npm_node = XML.SubElement(xml_parent,
- 'jenkins.plugins.nodejs.'
- 'NodeJSBuildWrapper')
+ npm_node = XML.SubElement(
+ xml_parent, "jenkins.plugins.nodejs." "NodeJSBuildWrapper"
+ )
- version = registry.get_plugin_info('nodejs').get('version', '0')
+ version = registry.get_plugin_info("nodejs").get("version", "0")
npm_node.set("plugin", "nodejs@" + version)
- mapping = [
- ('name', 'nodeJSInstallationName', None),
- ]
+ mapping = [("name", "nodeJSInstallationName", None)]
helpers.convert_mapping_to_xml(npm_node, data, mapping, fail_required=True)
@@ -2205,13 +2237,12 @@ def xvnc(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/xvnc-minimal.yaml
:language: yaml
"""
- xwrapper = XML.SubElement(xml_parent,
- 'hudson.plugins.xvnc.Xvnc')
- xwrapper.set('plugin', 'xvnc')
+ xwrapper = XML.SubElement(xml_parent, "hudson.plugins.xvnc.Xvnc")
+ xwrapper.set("plugin", "xvnc")
mapping = [
- ('screenshot', 'takeScreenshot', False),
- ('xauthority', 'useXauthority', True),
+ ("screenshot", "takeScreenshot", False),
+ ("xauthority", "useXauthority", True),
]
helpers.convert_mapping_to_xml(xwrapper, data, mapping, fail_required=True)
@@ -2230,12 +2261,10 @@ def job_log_logger(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/job-log-logger001.yaml
"""
- top = XML.SubElement(xml_parent,
- 'org.jenkins.ci.plugins.jobloglogger.'
- 'JobLogLoggerBuildWrapper')
- mapping = [
- ('suppress-empty', 'suppressEmpty', True),
- ]
+ top = XML.SubElement(
+ xml_parent, "org.jenkins.ci.plugins.jobloglogger." "JobLogLoggerBuildWrapper"
+ )
+ mapping = [("suppress-empty", "suppressEmpty", True)]
helpers.convert_mapping_to_xml(top, data, mapping, fail_required=True)
@@ -2276,21 +2305,20 @@ def xvfb(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/xvfb-minimal.yaml
:language: yaml
"""
- xwrapper = XML.SubElement(xml_parent,
- 'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper')
+ xwrapper = XML.SubElement(xml_parent, "org.jenkinsci.plugins.xvfb.XvfbBuildWrapper")
mapping = [
- ('installation-name', 'installationName', 'default'),
- ('auto-display-name', 'autoDisplayName', False),
- ('display-name', 'displayName', ''),
- ('assigned-labels', 'assignedLabels', ''),
- ('parallel-build', 'parallelBuild', False),
- ('timeout', 'timeout', 0),
- ('screen', 'screen', '1024x768x24'),
- ('display-name-offset', 'displayNameOffset', 1),
- ('additional-options', 'additionalOptions', ''),
- ('debug', 'debug', False),
- ('shutdown-with-build', 'shutdownWithBuild', False),
+ ("installation-name", "installationName", "default"),
+ ("auto-display-name", "autoDisplayName", False),
+ ("display-name", "displayName", ""),
+ ("assigned-labels", "assignedLabels", ""),
+ ("parallel-build", "parallelBuild", False),
+ ("timeout", "timeout", 0),
+ ("screen", "screen", "1024x768x24"),
+ ("display-name-offset", "displayNameOffset", 1),
+ ("additional-options", "additionalOptions", ""),
+ ("debug", "debug", False),
+ ("shutdown-with-build", "shutdownWithBuild", False),
]
helpers.convert_mapping_to_xml(xwrapper, data, mapping, fail_required=True)
@@ -2332,50 +2360,51 @@ def android_emulator(registry, xml_parent, data):
.. literalinclude:: /../../tests/wrappers/fixtures/android003.yaml
"""
- root = XML.SubElement(xml_parent,
- 'hudson.plugins.android__emulator.AndroidEmulator')
+ root = XML.SubElement(
+ xml_parent, "hudson.plugins.android__emulator.AndroidEmulator"
+ )
- if data.get('avd') and data.get('os'):
- raise JenkinsJobsException("'avd' and 'os' options are "
- "exclusive, please pick one only")
+ if data.get("avd") and data.get("os"):
+ raise JenkinsJobsException(
+ "'avd' and 'os' options are " "exclusive, please pick one only"
+ )
- if not data.get('avd') and not data.get('os'):
- raise JenkinsJobsException("AndroidEmulator requires an AVD name or"
- "OS version to run: specify 'os' or 'avd'")
+ if not data.get("avd") and not data.get("os"):
+ raise JenkinsJobsException(
+ "AndroidEmulator requires an AVD name or"
+ "OS version to run: specify 'os' or 'avd'"
+ )
- if data.get('avd'):
- XML.SubElement(root, 'avdName').text = str(data['avd'])
+ if data.get("avd"):
+ XML.SubElement(root, "avdName").text = str(data["avd"])
else:
mapping = [
- ('os', 'osVersion', None),
- ('screen-density', 'screenDensity', 'mdpi'),
- ('screen-resolution', 'screenResolution', 'WVGA'),
- ('locale', 'deviceLocale', 'en_US'),
- ('target-abi', 'targetAbi', ''),
- ('sd-card', 'sdCardSize', ''),
+ ("os", "osVersion", None),
+ ("screen-density", "screenDensity", "mdpi"),
+ ("screen-resolution", "screenResolution", "WVGA"),
+ ("locale", "deviceLocale", "en_US"),
+ ("target-abi", "targetAbi", ""),
+ ("sd-card", "sdCardSize", ""),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
- hardware = XML.SubElement(root, 'hardwareProperties')
- for prop_name, prop_val in data.get('hardware-properties', {}).items():
- prop_node = XML.SubElement(hardware,
- 'hudson.plugins.android__emulator'
- '.AndroidEmulator_-HardwareProperty')
- mapping = [
- ('', 'key', prop_name),
- ('', 'value', prop_val),
- ]
- helpers.convert_mapping_to_xml(
- prop_node, data, mapping, fail_required=True)
+ hardware = XML.SubElement(root, "hardwareProperties")
+ for prop_name, prop_val in data.get("hardware-properties", {}).items():
+ prop_node = XML.SubElement(
+ hardware,
+ "hudson.plugins.android__emulator" ".AndroidEmulator_-HardwareProperty",
+ )
+ mapping = [("", "key", prop_name), ("", "value", prop_val)]
+ helpers.convert_mapping_to_xml(prop_node, data, mapping, fail_required=True)
mapping = [
- ('wipe', 'wipeData', False),
- ('show-window', 'showWindow', False),
- ('snapshot', 'useSnapshots', False),
- ('delete', 'deleteAfterBuild', False),
- ('startup-delay', 'startupDelay', 0),
- ('commandline-options', 'commandLineOptions', ''),
- ('exe', 'executable', ''),
+ ("wipe", "wipeData", False),
+ ("show-window", "showWindow", False),
+ ("snapshot", "useSnapshots", False),
+ ("delete", "deleteAfterBuild", False),
+ ("startup-delay", "startupDelay", 0),
+ ("commandline-options", "commandLineOptions", ""),
+ ("exe", "executable", ""),
]
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
@@ -2406,19 +2435,19 @@ def artifactory_maven(registry, xml_parent, data):
"""
artifactory = XML.SubElement(
- xml_parent,
- 'org.jfrog.hudson.maven3.ArtifactoryMaven3NativeConfigurator')
+ xml_parent, "org.jfrog.hudson.maven3.ArtifactoryMaven3NativeConfigurator"
+ )
# details
- details = XML.SubElement(artifactory, 'details')
+ details = XML.SubElement(artifactory, "details")
helpers.artifactory_common_details(details, data)
- if 'repo-key' in data:
- mapping = [('repo-key', 'downloadRepositoryKey', None)]
+ if "repo-key" in data:
+ mapping = [("repo-key", "downloadRepositoryKey", None)]
else:
mapping = [
- ('snapshot-repo-key', 'downloadSnapshotRepositoryKey', ''),
- ('release-repo-key', 'downloadReleaseRepositoryKey', ''),
+ ("snapshot-repo-key", "downloadSnapshotRepositoryKey", ""),
+ ("release-repo-key", "downloadReleaseRepositoryKey", ""),
]
helpers.convert_mapping_to_xml(details, data, mapping, fail_required=True)
@@ -2483,73 +2512,73 @@ def artifactory_generic(registry, xml_parent, data):
use_specs = False
artifactory = XML.SubElement(
- xml_parent,
- 'org.jfrog.hudson.generic.ArtifactoryGenericConfigurator')
+ xml_parent, "org.jfrog.hudson.generic.ArtifactoryGenericConfigurator"
+ )
# details
- details = XML.SubElement(artifactory, 'details')
+ details = XML.SubElement(artifactory, "details")
helpers.artifactory_common_details(details, data)
# Get plugin information to maintain backwards compatibility
- info = registry.get_plugin_info('artifactory')
+ info = registry.get_plugin_info("artifactory")
# Note: Assume latest version of plugin is preferred config format
- version = pkg_resources.parse_version(
- info.get('version', str(sys.maxsize)))
+ version = pkg_resources.parse_version(info.get("version", str(sys.maxsize)))
- if version >= pkg_resources.parse_version('2.3.0'):
- deploy_release_repo = XML.SubElement(
- details, 'deployReleaseRepository')
+ if version >= pkg_resources.parse_version("2.3.0"):
+ deploy_release_repo = XML.SubElement(details, "deployReleaseRepository")
mapping = [
- ('key-from-text', 'keyFromText', ''),
- ('key-from-select', 'keyFromSelect', ''),
- ('key-from-text', 'dynamicMode', ''),
+ ("key-from-text", "keyFromText", ""),
+ ("key-from-select", "keyFromSelect", ""),
+ ("key-from-text", "dynamicMode", ""),
]
helpers.convert_mapping_to_xml(
- deploy_release_repo, data, mapping, fail_required=False)
+ deploy_release_repo, data, mapping, fail_required=False
+ )
else:
mapping = [
- ('repo-key', 'repositoryKey', ''),
- ('snapshot-repo-key', 'snapshotsRepositoryKey', ''),
+ ("repo-key", "repositoryKey", ""),
+ ("snapshot-repo-key", "snapshotsRepositoryKey", ""),
]
- helpers.convert_mapping_to_xml(
- details, data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(details, data, mapping, fail_required=False)
- if 'upload-spec' in data or 'download-spec' in data:
- upload_spec = data.get('upload-spec', '')
- upl_spec_xml = XML.SubElement(artifactory, 'uploadSpec')
- XML.SubElement(upl_spec_xml, 'spec').text = upload_spec
+ if "upload-spec" in data or "download-spec" in data:
+ upload_spec = data.get("upload-spec", "")
+ upl_spec_xml = XML.SubElement(artifactory, "uploadSpec")
+ XML.SubElement(upl_spec_xml, "spec").text = upload_spec
- download_spec = data.get('download-spec', '')
- dnl_spec_xml = XML.SubElement(artifactory, 'downloadSpec')
- XML.SubElement(dnl_spec_xml, 'spec').text = download_spec
+ download_spec = data.get("download-spec", "")
+ dnl_spec_xml = XML.SubElement(artifactory, "downloadSpec")
+ XML.SubElement(dnl_spec_xml, "spec").text = download_spec
use_specs = True
- if 'upload-spec-file' in data or 'download-spec-file' in data:
- upload_spec_file = data.get('upload-spec-file', '')
- upl_spec_xml = XML.SubElement(artifactory, 'uploadSpec')
- XML.SubElement(upl_spec_xml, 'filePath').text = upload_spec_file
+ if "upload-spec-file" in data or "download-spec-file" in data:
+ upload_spec_file = data.get("upload-spec-file", "")
+ upl_spec_xml = XML.SubElement(artifactory, "uploadSpec")
+ XML.SubElement(upl_spec_xml, "filePath").text = upload_spec_file
- download_spec_file = data.get('download-spec-file', '')
- dnl_spec_xml = XML.SubElement(artifactory, 'downloadSpec')
- XML.SubElement(dnl_spec_xml, 'filePath').text = download_spec_file
+ download_spec_file = data.get("download-spec-file", "")
+ dnl_spec_xml = XML.SubElement(artifactory, "downloadSpec")
+ XML.SubElement(dnl_spec_xml, "filePath").text = download_spec_file
use_specs = True
- XML.SubElement(artifactory, 'useSpecs').text = str(use_specs).lower()
+ XML.SubElement(artifactory, "useSpecs").text = str(use_specs).lower()
- XML.SubElement(artifactory, 'deployPattern').text = ','.join(data.get(
- 'deploy-pattern', []))
- XML.SubElement(artifactory, 'resolvePattern').text = ','.join(
- data.get('resolve-pattern', []))
- XML.SubElement(artifactory, 'matrixParams').text = ','.join(
- data.get('matrix-params', []))
+ XML.SubElement(artifactory, "deployPattern").text = ",".join(
+ data.get("deploy-pattern", [])
+ )
+ XML.SubElement(artifactory, "resolvePattern").text = ",".join(
+ data.get("resolve-pattern", [])
+ )
+ XML.SubElement(artifactory, "matrixParams").text = ",".join(
+ data.get("matrix-params", [])
+ )
mapping = [
- ('deploy-build-info', 'deployBuildInfo', False),
- ('env-vars-include', 'includeEnvVars', False),
- ('discard-old-builds', 'discardOldBuilds', False),
- ('discard-build-artifacts', 'discardBuildArtifacts', True),
+ ("deploy-build-info", "deployBuildInfo", False),
+ ("env-vars-include", "includeEnvVars", False),
+ ("discard-old-builds", "discardOldBuilds", False),
+ ("discard-build-artifacts", "discardBuildArtifacts", True),
]
- helpers.convert_mapping_to_xml(
- artifactory, data, mapping, fail_required=False)
+ helpers.convert_mapping_to_xml(artifactory, data, mapping, fail_required=False)
# envVarsPatterns
helpers.artifactory_env_vars_patterns(artifactory, data)
@@ -2657,34 +2686,36 @@ def artifactory_maven_freestyle(registry, xml_parent, data):
"""
artifactory = XML.SubElement(
- xml_parent,
- 'org.jfrog.hudson.maven3.ArtifactoryMaven3Configurator')
+ xml_parent, "org.jfrog.hudson.maven3.ArtifactoryMaven3Configurator"
+ )
# details
- details = XML.SubElement(artifactory, 'details')
+ details = XML.SubElement(artifactory, "details")
helpers.artifactory_common_details(details, data)
- deploy_release = XML.SubElement(details, 'deployReleaseRepository')
- helpers.artifactory_repository(deploy_release, data, 'release')
+ deploy_release = XML.SubElement(details, "deployReleaseRepository")
+ helpers.artifactory_repository(deploy_release, data, "release")
- deploy_snapshot = XML.SubElement(details, 'deploySnapshotRepository')
- helpers.artifactory_repository(deploy_snapshot, data, 'snapshot')
+ deploy_snapshot = XML.SubElement(details, "deploySnapshotRepository")
+ helpers.artifactory_repository(deploy_snapshot, data, "snapshot")
- XML.SubElement(details, 'stagingPlugin').text = data.get(
- 'resolve-staging-plugin', '')
+ XML.SubElement(details, "stagingPlugin").text = data.get(
+ "resolve-staging-plugin", ""
+ )
# resolverDetails
- resolver = XML.SubElement(artifactory, 'resolverDetails')
+ resolver = XML.SubElement(artifactory, "resolverDetails")
helpers.artifactory_common_details(resolver, data)
- resolve_snapshot = XML.SubElement(resolver, 'resolveSnapshotRepository')
- helpers.artifactory_repository(resolve_snapshot, data, 'snapshot')
+ resolve_snapshot = XML.SubElement(resolver, "resolveSnapshotRepository")
+ helpers.artifactory_repository(resolve_snapshot, data, "snapshot")
- deploy_release = XML.SubElement(resolver, 'resolveReleaseRepository')
- helpers.artifactory_repository(deploy_release, data, 'release')
+ deploy_release = XML.SubElement(resolver, "resolveReleaseRepository")
+ helpers.artifactory_repository(deploy_release, data, "release")
- XML.SubElement(resolver, 'stagingPlugin').text = data.get(
- 'resolve-staging-plugin', '')
+ XML.SubElement(resolver, "stagingPlugin").text = data.get(
+ "resolve-staging-plugin", ""
+ )
# artifactDeploymentPatterns
helpers.artifactory_deployment_patterns(artifactory, data)
@@ -2692,11 +2723,12 @@ def artifactory_maven_freestyle(registry, xml_parent, data):
# envVarsPatterns
helpers.artifactory_env_vars_patterns(artifactory, data)
- XML.SubElement(artifactory, 'matrixParams').text = ','.join(
- data.get('matrix-params', []))
+ XML.SubElement(artifactory, "matrixParams").text = ",".join(
+ data.get("matrix-params", [])
+ )
# optional__props
- helpers.artifactory_optional_props(artifactory, data, 'wrappers')
+ helpers.artifactory_optional_props(artifactory, data, "wrappers")
def maven_release(registry, xml_parent, data):
@@ -2725,25 +2757,22 @@ def maven_release(registry, xml_parent, data):
:language: yaml
"""
- mvn_release = XML.SubElement(xml_parent,
- 'org.jvnet.hudson.plugins.m2release.'
- 'M2ReleaseBuildWrapper')
+ mvn_release = XML.SubElement(
+ xml_parent, "org.jvnet.hudson.plugins.m2release." "M2ReleaseBuildWrapper"
+ )
mapping = [
- ('release-goals', 'releaseGoals', ''),
- ('dry-run-goals', 'dryRunGoals', ''),
- ('num-successful-builds', 'numberOfReleaseBuildsToKeep', 1),
- ('select-custom-scm-comment-prefix', 'selectCustomScmCommentPrefix',
- False),
- ('select-append-jenkins-username', 'selectAppendHudsonUsername',
- False),
- ('select-scm-credentials', 'selectScmCredentials', False),
- ('release-env-var', 'releaseEnvVar', ''),
- ('scm-user-env-var', 'scmUserEnvVar', ''),
- ('scm-password-env-var', 'scmPasswordEnvVar', ''),
+ ("release-goals", "releaseGoals", ""),
+ ("dry-run-goals", "dryRunGoals", ""),
+ ("num-successful-builds", "numberOfReleaseBuildsToKeep", 1),
+ ("select-custom-scm-comment-prefix", "selectCustomScmCommentPrefix", False),
+ ("select-append-jenkins-username", "selectAppendHudsonUsername", False),
+ ("select-scm-credentials", "selectScmCredentials", False),
+ ("release-env-var", "releaseEnvVar", ""),
+ ("scm-user-env-var", "scmUserEnvVar", ""),
+ ("scm-password-env-var", "scmPasswordEnvVar", ""),
]
- helpers.convert_mapping_to_xml(
- mvn_release, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(mvn_release, data, mapping, fail_required=True)
def version_number(parser, xml_parent, data):
@@ -2782,25 +2811,24 @@ def version_number(parser, xml_parent, data):
"""
version_number = XML.SubElement(
- xml_parent, 'org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder'
+ xml_parent, "org.jvnet.hudson.tools.versionnumber.VersionNumberBuilder"
)
mapping = [
# option, xml name, default value
- ("variable-name", 'environmentVariableName', None),
- ("format-string", 'versionNumberString', None),
- ("prefix-variable", 'environmentPrefixVariable', ''),
- ("skip-failed-builds", 'skipFailedBuilds', False),
- ("display-name", 'useAsBuildDisplayName', False),
- ("start-date", 'projectStartDate', '1970-1-1 00:00:00.0 UTC'),
- ("builds-today", 'oBuildsToday', '-1'),
- ("builds-this-month", 'oBuildsThisMonth', '-1'),
- ("builds-this-year", 'oBuildsThisYear', '-1'),
- ("builds-all-time", 'oBuildsAllTime', '-1'),
+ ("variable-name", "environmentVariableName", None),
+ ("format-string", "versionNumberString", None),
+ ("prefix-variable", "environmentPrefixVariable", ""),
+ ("skip-failed-builds", "skipFailedBuilds", False),
+ ("display-name", "useAsBuildDisplayName", False),
+ ("start-date", "projectStartDate", "1970-1-1 00:00:00.0 UTC"),
+ ("builds-today", "oBuildsToday", "-1"),
+ ("builds-this-month", "oBuildsThisMonth", "-1"),
+ ("builds-this-year", "oBuildsThisYear", "-1"),
+ ("builds-all-time", "oBuildsAllTime", "-1"),
]
- helpers.convert_mapping_to_xml(
- version_number, data, mapping, fail_required=True)
+ helpers.convert_mapping_to_xml(version_number, data, mapping, fail_required=True)
def github_pull_request(parser, xml_parent, data):
@@ -2845,52 +2873,51 @@ def github_pull_request(parser, xml_parent, data):
"""
ghprb = XML.SubElement(
- xml_parent, 'org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus'
+ xml_parent, "org.jenkinsci.plugins.ghprb.upstream.GhprbUpstreamStatus"
)
mapping = [
# option, xml name, default value
- ("show-matrix-status", 'showMatrixStatus', False),
- ("status-context", 'commitStatusContext', ''),
- ("triggered-status", 'triggeredStatus', ''),
- ("started-status", 'startedStatus', ''),
- ("status-url", 'statusUrl', ''),
- ("status-add-test-results", 'addTestResults', False),
+ ("show-matrix-status", "showMatrixStatus", False),
+ ("status-context", "commitStatusContext", ""),
+ ("triggered-status", "triggeredStatus", ""),
+ ("started-status", "startedStatus", ""),
+ ("status-url", "statusUrl", ""),
+ ("status-add-test-results", "addTestResults", False),
]
helpers.convert_mapping_to_xml(ghprb, data, mapping, fail_required=True)
- statuses = data.get('statuses', [])
+ statuses = data.get("statuses", [])
if statuses:
- status_mapping = [
- ('message', 'message', None),
- ('result', 'result', ''),
- ]
- result_list = ['ERROR', 'SUCCESS', 'FAILURE']
+ status_mapping = [("message", "message", None), ("result", "result", "")]
+ result_list = ["ERROR", "SUCCESS", "FAILURE"]
- completed_tag = XML.SubElement(ghprb, 'completedStatus')
+ completed_tag = XML.SubElement(ghprb, "completedStatus")
for status in statuses:
- result = status.get('result', '')
+ result = status.get("result", "")
if result not in result_list:
raise JenkinsJobsException(
- "'result' must be one of: " + ', '.join(result_list))
+ "'result' must be one of: " + ", ".join(result_list)
+ )
result_tag = XML.SubElement(
completed_tag,
- 'org.jenkinsci.plugins.ghprb.extensions'
- '.comments.GhprbBuildResultMessage'
+ "org.jenkinsci.plugins.ghprb.extensions"
+ ".comments.GhprbBuildResultMessage",
)
helpers.convert_mapping_to_xml(
- result_tag, status, status_mapping, fail_required=True)
+ result_tag, status, status_mapping, fail_required=True
+ )
class Wrappers(jenkins_jobs.modules.base.Base):
sequence = 80
- component_type = 'wrapper'
- component_list_type = 'wrappers'
+ component_type = "wrapper"
+ component_list_type = "wrappers"
def gen_xml(self, xml_parent, data):
- wrappers = XML.SubElement(xml_parent, 'buildWrappers')
+ wrappers = XML.SubElement(xml_parent, "buildWrappers")
- for wrap in data.get('wrappers', []):
- self.registry.dispatch('wrapper', wrappers, wrap)
+ for wrap in data.get("wrappers", []):
+ self.registry.dispatch("wrapper", wrappers, wrap)
diff --git a/jenkins_jobs/modules/zuul.py b/jenkins_jobs/modules/zuul.py
index c4f4857a..8766895d 100644
--- a/jenkins_jobs/modules/zuul.py
+++ b/jenkins_jobs/modules/zuul.py
@@ -58,80 +58,129 @@ def zuul_post():
ZUUL_PARAMETERS = [
- {'string':
- {'description': 'Zuul provided key to link builds with Gerrit events',
- 'name': 'ZUUL_UUID'}},
- {'string':
- {'description': 'Zuul provided key to link builds with Gerrit'
- ' events (deprecated use ZUUL_UUID instead)',
- 'name': 'UUID'}},
- {'string':
- {'description': 'Zuul pipeline triggering this job',
- 'name': 'ZUUL_PIPELINE'}},
- {'string':
- {'description': 'URL of Zuul\'s git repos accessible to workers',
- 'name': 'ZUUL_URL'}},
- {'string':
- {'description': 'Branch name of triggering project',
- 'name': 'ZUUL_PROJECT'}},
- {'string':
- {'description': 'Branch name of triggering change',
- 'name': 'ZUUL_BRANCH'}},
- {'string':
- {'description': 'List of dependent changes to merge',
- 'name': 'ZUUL_CHANGES'}},
- {'string':
- {'description': 'Reference for the merged commit(s) to use',
- 'name': 'ZUUL_REF'}},
- {'string':
- {'description': 'The commit SHA1 at the head of ZUUL_REF',
- 'name': 'ZUUL_COMMIT'}},
- {'string':
- {'description': 'List of included changes',
- 'name': 'ZUUL_CHANGE_IDS'}},
- {'string':
- {'description': 'ID of triggering change',
- 'name': 'ZUUL_CHANGE'}},
- {'string':
- {'description': 'Patchset of triggering change',
- 'name': 'ZUUL_PATCHSET'}},
- {'string':
- {'description': 'Zuul considered this job voting or not',
- 'name': 'ZUUL_VOTING'}},
+ {
+ "string": {
+ "description": "Zuul provided key to link builds with Gerrit events",
+ "name": "ZUUL_UUID",
+ }
+ },
+ {
+ "string": {
+ "description": "Zuul provided key to link builds with Gerrit"
+ " events (deprecated use ZUUL_UUID instead)",
+ "name": "UUID",
+ }
+ },
+ {
+ "string": {
+ "description": "Zuul pipeline triggering this job",
+ "name": "ZUUL_PIPELINE",
+ }
+ },
+ {
+ "string": {
+ "description": "URL of Zuul's git repos accessible to workers",
+ "name": "ZUUL_URL",
+ }
+ },
+ {
+ "string": {
+ "description": "Branch name of triggering project",
+ "name": "ZUUL_PROJECT",
+ }
+ },
+ {
+ "string": {
+ "description": "Branch name of triggering change",
+ "name": "ZUUL_BRANCH",
+ }
+ },
+ {
+ "string": {
+ "description": "List of dependent changes to merge",
+ "name": "ZUUL_CHANGES",
+ }
+ },
+ {
+ "string": {
+ "description": "Reference for the merged commit(s) to use",
+ "name": "ZUUL_REF",
+ }
+ },
+ {
+ "string": {
+ "description": "The commit SHA1 at the head of ZUUL_REF",
+ "name": "ZUUL_COMMIT",
+ }
+ },
+ {"string": {"description": "List of included changes", "name": "ZUUL_CHANGE_IDS"}},
+ {"string": {"description": "ID of triggering change", "name": "ZUUL_CHANGE"}},
+ {
+ "string": {
+ "description": "Patchset of triggering change",
+ "name": "ZUUL_PATCHSET",
+ }
+ },
+ {
+ "string": {
+ "description": "Zuul considered this job voting or not",
+ "name": "ZUUL_VOTING",
+ }
+ },
]
ZUUL_POST_PARAMETERS = [
- {'string':
- {'description': 'Zuul provided key to link builds with Gerrit events',
- 'name': 'ZUUL_UUID'}},
- {'string':
- {'description': 'Zuul provided key to link builds with Gerrit'
- ' events (deprecated use ZUUL_UUID instead)',
- 'name': 'UUID'}},
- {'string':
- {'description': 'Zuul pipeline triggering this job',
- 'name': 'ZUUL_PIPELINE'}},
- {'string':
- {'description': 'URL of Zuul\'s git repos accessible to workers',
- 'name': 'ZUUL_URL'}},
- {'string':
- {'description': 'Branch name of triggering project',
- 'name': 'ZUUL_PROJECT'}},
- {'string':
- {'description': 'Name of updated reference triggering this job',
- 'name': 'ZUUL_REF'}},
- {'string':
- {'description': 'Name of updated reference triggering this job',
- 'name': 'ZUUL_REFNAME'}},
- {'string':
- {'description': 'Old SHA at this reference',
- 'name': 'ZUUL_OLDREV'}},
- {'string':
- {'description': 'New SHA at this reference',
- 'name': 'ZUUL_NEWREV'}},
- {'string':
- {'description': 'Shortened new SHA at this reference',
- 'name': 'ZUUL_SHORT_NEWREV'}},
+ {
+ "string": {
+ "description": "Zuul provided key to link builds with Gerrit events",
+ "name": "ZUUL_UUID",
+ }
+ },
+ {
+ "string": {
+ "description": "Zuul provided key to link builds with Gerrit"
+ " events (deprecated use ZUUL_UUID instead)",
+ "name": "UUID",
+ }
+ },
+ {
+ "string": {
+ "description": "Zuul pipeline triggering this job",
+ "name": "ZUUL_PIPELINE",
+ }
+ },
+ {
+ "string": {
+ "description": "URL of Zuul's git repos accessible to workers",
+ "name": "ZUUL_URL",
+ }
+ },
+ {
+ "string": {
+ "description": "Branch name of triggering project",
+ "name": "ZUUL_PROJECT",
+ }
+ },
+ {
+ "string": {
+ "description": "Name of updated reference triggering this job",
+ "name": "ZUUL_REF",
+ }
+ },
+ {
+ "string": {
+ "description": "Name of updated reference triggering this job",
+ "name": "ZUUL_REFNAME",
+ }
+ },
+ {"string": {"description": "Old SHA at this reference", "name": "ZUUL_OLDREV"}},
+ {"string": {"description": "New SHA at this reference", "name": "ZUUL_NEWREV"}},
+ {
+ "string": {
+ "description": "Shortened new SHA at this reference",
+ "name": "ZUUL_SHORT_NEWREV",
+ }
+ },
]
@@ -141,23 +190,24 @@ class Zuul(jenkins_jobs.modules.base.Base):
def handle_data(self, job_data):
changed = False
jobs = itertools.chain(
- job_data.get('job', {}).values(),
- job_data.get('job-template', {}).values())
+ job_data.get("job", {}).values(), job_data.get("job-template", {}).values()
+ )
for job in jobs:
- triggers = job.get('triggers')
+ triggers = job.get("triggers")
if not triggers:
continue
- if ('zuul' not in job.get('triggers', []) and
- 'zuul-post' not in job.get('triggers', [])):
+ if "zuul" not in job.get("triggers", []) and "zuul-post" not in job.get(
+ "triggers", []
+ ):
continue
- if 'parameters' not in job:
- job['parameters'] = []
- if 'zuul' in job.get('triggers', []):
- job['parameters'].extend(ZUUL_PARAMETERS)
- job['triggers'].remove('zuul')
- if 'zuul-post' in job.get('triggers', []):
- job['parameters'].extend(ZUUL_POST_PARAMETERS)
- job['triggers'].remove('zuul-post')
+ if "parameters" not in job:
+ job["parameters"] = []
+ if "zuul" in job.get("triggers", []):
+ job["parameters"].extend(ZUUL_PARAMETERS)
+ job["triggers"].remove("zuul")
+ if "zuul-post" in job.get("triggers", []):
+ job["parameters"].extend(ZUUL_POST_PARAMETERS)
+ job["triggers"].remove("zuul-post")
changed = True
return changed
diff --git a/jenkins_jobs/parallel.py b/jenkins_jobs/parallel.py
index 5c0da07c..a409491e 100644
--- a/jenkins_jobs/parallel.py
+++ b/jenkins_jobs/parallel.py
@@ -33,11 +33,12 @@ class TaskFunc(dict):
"""
Simple class to wrap around the information needed to run a function.
"""
+
def __init__(self, n_ord, func, args=None, kwargs=None):
- self['func'] = func
- self['args'] = args or []
- self['kwargs'] = kwargs or {}
- self['ord'] = n_ord
+ self["func"] = func
+ self["args"] = args or []
+ self["kwargs"] = kwargs or {}
+ self["ord"] = n_ord
class Worker(threading.Thread):
@@ -47,6 +48,7 @@ class Worker(threading.Thread):
If the string 'done' is passed instead of a TaskFunc instance, the thread
will end.
"""
+
def __init__(self, in_queue, out_queue):
threading.Thread.__init__(self)
self.in_queue = in_queue
@@ -55,15 +57,14 @@ class Worker(threading.Thread):
def run(self):
while True:
task = self.in_queue.get()
- if task == 'done':
+ if task == "done":
return
try:
- res = task['func'](*task['args'],
- **task['kwargs'])
+ res = task["func"](*task["args"], **task["kwargs"])
except Exception as exc:
res = exc
traceback.print_exc()
- self.out_queue.put((task['ord'], res))
+ self.out_queue.put((task["ord"], res))
def concurrent(func):
@@ -102,8 +103,8 @@ def concurrent(func):
array with the results of the executions in the same order the
parameters were passed.
"""
- n_workers = kwargs.pop('n_workers', 0)
- p_kwargs = kwargs.pop('concurrent', [])
+ n_workers = kwargs.pop("n_workers", 0)
+ p_kwargs = kwargs.pop("concurrent", [])
# if only one parameter is passed inside the concurrent dict, run the
# original function as is, no need for pools
if len(p_kwargs) == 1:
@@ -133,7 +134,7 @@ def concurrent(func):
in_queue.put(TaskFunc(n_ord, func, args, f_kwargs))
n_ord += 1
for _ in range(n_workers):
- in_queue.put('done')
+ in_queue.put("done")
# Wait for the results
logging.debug("Waiting for workers to finish processing")
@@ -148,4 +149,5 @@ def concurrent(func):
results = [r[1] for r in sorted(results)]
logging.debug("Concurrent task finished")
return results
+
return concurrentized
diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py
index 667ce426..e2ef6f15 100644
--- a/jenkins_jobs/parser.py
+++ b/jenkins_jobs/parser.py
@@ -29,9 +29,7 @@ from jenkins_jobs.formatter import deep_format
import jenkins_jobs.local_yaml as local_yaml
from jenkins_jobs import utils
-__all__ = [
- "YamlParser"
-]
+__all__ = ["YamlParser"]
logger = logging.getLogger(__name__)
@@ -45,8 +43,7 @@ def matches(what, glob_patterns):
:arg iterable glob_patterns: glob patterns to match (list, tuple, set,
etc.)
"""
- return any(fnmatch.fnmatch(what, glob_pattern)
- for glob_pattern in glob_patterns)
+ return any(fnmatch.fnmatch(what, glob_pattern) for glob_pattern in glob_patterns)
def combination_matches(combination, match_combinations):
@@ -79,28 +76,32 @@ class YamlParser(object):
self.views = []
self.jjb_config = jjb_config
- self.keep_desc = jjb_config.yamlparser['keep_descriptions']
- self.path = jjb_config.yamlparser['include_path']
+ self.keep_desc = jjb_config.yamlparser["keep_descriptions"]
+ self.path = jjb_config.yamlparser["include_path"]
def load_files(self, fn):
# handle deprecated behavior, and check that it's not a file like
# object as these may implement the '__iter__' attribute.
- if not hasattr(fn, '__iter__') or hasattr(fn, 'read'):
+ if not hasattr(fn, "__iter__") or hasattr(fn, "read"):
logger.warning(
- 'Passing single elements for the `fn` argument in '
- 'Builder.load_files is deprecated. Please update your code '
- 'to use a list as support for automatic conversion will be '
- 'removed in a future version.')
+ "Passing single elements for the `fn` argument in "
+ "Builder.load_files is deprecated. Please update your code "
+ "to use a list as support for automatic conversion will be "
+ "removed in a future version."
+ )
fn = [fn]
files_to_process = []
for path in fn:
- if not hasattr(path, 'read') and os.path.isdir(path):
- files_to_process.extend([os.path.join(path, f)
- for f in sorted(os.listdir(path))
- if (f.endswith('.yml') or
- f.endswith('.yaml'))])
+ if not hasattr(path, "read") and os.path.isdir(path):
+ files_to_process.extend(
+ [
+ os.path.join(path, f)
+ for f in sorted(os.listdir(path))
+ if (f.endswith(".yml") or f.endswith(".yaml"))
+ ]
+ )
else:
files_to_process.append(path)
@@ -108,41 +109,45 @@ class YamlParser(object):
# definitions of macros and templates when loading all from top-level
unique_files = []
for f in files_to_process:
- if hasattr(f, 'read'):
+ if hasattr(f, "read"):
unique_files.append(f)
continue
rpf = os.path.realpath(f)
if rpf not in unique_files:
unique_files.append(rpf)
else:
- logger.warning("File '%s' already added as '%s', ignoring "
- "reference to avoid duplicating yaml "
- "definitions." % (f, rpf))
+ logger.warning(
+ "File '%s' already added as '%s', ignoring "
+ "reference to avoid duplicating yaml "
+ "definitions." % (f, rpf)
+ )
for in_file in unique_files:
# use of ask-for-permissions instead of ask-for-forgiveness
# performs better when low use cases.
- if hasattr(in_file, 'name'):
+ if hasattr(in_file, "name"):
fname = in_file.name
else:
fname = in_file
logger.debug("Parsing YAML file {0}".format(fname))
- if hasattr(in_file, 'read'):
+ if hasattr(in_file, "read"):
self._parse_fp(in_file)
else:
self.parse(in_file)
def _parse_fp(self, fp):
# wrap provided file streams to ensure correct encoding used
- data = local_yaml.load(utils.wrap_stream(fp),
- self.jjb_config.yamlparser['retain_anchors'],
- search_path=self.path)
+ data = local_yaml.load(
+ utils.wrap_stream(fp),
+ self.jjb_config.yamlparser["retain_anchors"],
+ search_path=self.path,
+ )
if data:
if not isinstance(data, list):
raise JenkinsJobsException(
"The topmost collection in file '{fname}' must be a list,"
- " not a {cls}".format(fname=getattr(fp, 'name', fp),
- cls=type(data)))
+ " not a {cls}".format(fname=getattr(fp, "name", fp), cls=type(data))
+ )
for item in data:
cls, dfn = next(iter(item.items()))
group = self.data.get(cls, {})
@@ -153,41 +158,43 @@ class YamlParser(object):
n = v
break
# Syntax error
- raise JenkinsJobsException("Syntax error, for item "
- "named '{0}'. Missing indent?"
- .format(n))
+ raise JenkinsJobsException(
+ "Syntax error, for item "
+ "named '{0}'. Missing indent?".format(n)
+ )
# allow any entry to specify an id that can also be used
- _id = dfn.get('id', dfn['name'])
+ _id = dfn.get("id", dfn["name"])
if _id in group:
self._handle_dups(
"Duplicate entry found in '{0}: '{1}' already "
- "defined".format(fp.name, _id))
+ "defined".format(fp.name, _id)
+ )
group[_id] = dfn
self.data[cls] = group
def parse(self, fn):
- with io.open(fn, 'r', encoding='utf-8') as fp:
+ with io.open(fn, "r", encoding="utf-8") as fp:
self._parse_fp(fp)
def _handle_dups(self, message):
- if not self.jjb_config.yamlparser['allow_duplicates']:
+ if not self.jjb_config.yamlparser["allow_duplicates"]:
logger.error(message)
raise JenkinsJobsException(message)
else:
logger.warning(message)
def _getJob(self, name):
- job = self.data.get('job', {}).get(name, None)
+ job = self.data.get("job", {}).get(name, None)
if not job:
return job
return self._applyDefaults(job)
def _getJobGroup(self, name):
- return self.data.get('job-group', {}).get(name, None)
+ return self.data.get("job-group", {}).get(name, None)
def _getJobTemplate(self, name):
- job = self.data.get('job-template', {}).get(name, None)
+ job = self.data.get("job-template", {}).get(name, None)
if not job:
return job
return self._applyDefaults(job)
@@ -196,12 +203,12 @@ class YamlParser(object):
if override_dict is None:
override_dict = {}
- whichdefaults = data.get('defaults', 'global')
- defaults = copy.deepcopy(self.data.get('defaults',
- {}).get(whichdefaults, {}))
- if defaults == {} and whichdefaults != 'global':
- raise JenkinsJobsException("Unknown defaults set: '{0}'"
- .format(whichdefaults))
+ whichdefaults = data.get("defaults", "global")
+ defaults = copy.deepcopy(self.data.get("defaults", {}).get(whichdefaults, {}))
+ if defaults == {} and whichdefaults != "global":
+ raise JenkinsJobsException(
+ "Unknown defaults set: '{0}'".format(whichdefaults)
+ )
for key in override_dict.keys():
if key in defaults.keys():
@@ -216,53 +223,52 @@ class YamlParser(object):
if self.keep_desc:
description = job.get("description", None)
else:
- description = job.get("description", '')
+ description = job.get("description", "")
if description is not None:
- job["description"] = description + \
- self._get_managed_string().lstrip()
+ job["description"] = description + self._get_managed_string().lstrip()
def _getfullname(self, data):
- if 'folder' in data:
- return "%s/%s" % (data['folder'], data['name'])
+ if "folder" in data:
+ return "%s/%s" % (data["folder"], data["name"])
- return data['name']
+ return data["name"]
def expandYaml(self, registry, jobs_glob=None):
changed = True
while changed:
changed = False
for module in registry.modules:
- if hasattr(module, 'handle_data'):
+ if hasattr(module, "handle_data"):
if module.handle_data(self.data):
changed = True
- for job in self.data.get('job', {}).values():
+ for job in self.data.get("job", {}).values():
job = self._applyDefaults(job)
- job['name'] = self._getfullname(job)
+ job["name"] = self._getfullname(job)
- if jobs_glob and not matches(job['name'], jobs_glob):
- logger.debug("Ignoring job {0}".format(job['name']))
+ if jobs_glob and not matches(job["name"], jobs_glob):
+ logger.debug("Ignoring job {0}".format(job["name"]))
continue
- logger.debug("Expanding job '{0}'".format(job['name']))
+ logger.debug("Expanding job '{0}'".format(job["name"]))
self._formatDescription(job)
self.jobs.append(job)
- for view in self.data.get('view', {}).values():
- view['name'] = self._getfullname(view)
+ for view in self.data.get("view", {}).values():
+ view["name"] = self._getfullname(view)
- if jobs_glob and not matches(view['name'], jobs_glob):
- logger.debug("Ignoring view {0}".format(view['name']))
+ if jobs_glob and not matches(view["name"], jobs_glob):
+ logger.debug("Ignoring view {0}".format(view["name"]))
continue
- logger.debug("Expanding view '{0}'".format(view['name']))
+ logger.debug("Expanding view '{0}'".format(view["name"]))
self._formatDescription(view)
self.views.append(view)
- for project in self.data.get('project', {}).values():
- logger.debug("Expanding project '{0}'".format(project['name']))
+ for project in self.data.get("project", {}).values():
+ logger.debug("Expanding project '{0}'".format(project["name"]))
# use a set to check for duplicate job references in projects
seen = set()
- for jobspec in project.get('jobs', []):
+ for jobspec in project.get("jobs", []):
if isinstance(jobspec, dict):
# Singleton dict containing dict of job-specific params
jobname, jobparams = next(iter(jobspec.items()))
@@ -275,18 +281,20 @@ class YamlParser(object):
if job:
# Just naming an existing defined job
if jobname in seen:
- self._handle_dups("Duplicate job '{0}' specified "
- "for project '{1}'"
- .format(jobname, project['name']))
+ self._handle_dups(
+ "Duplicate job '{0}' specified "
+ "for project '{1}'".format(jobname, project["name"])
+ )
seen.add(jobname)
continue
# see if it's a job group
group = self._getJobGroup(jobname)
if group:
- for group_jobspec in group['jobs']:
+ for group_jobspec in group["jobs"]:
if isinstance(group_jobspec, dict):
- group_jobname, group_jobparams = \
- next(iter(group_jobspec.items()))
+ group_jobname, group_jobparams = next(
+ iter(group_jobspec.items())
+ )
if not isinstance(group_jobparams, dict):
group_jobparams = {}
else:
@@ -297,8 +305,10 @@ class YamlParser(object):
if group_jobname in seen:
self._handle_dups(
"Duplicate job '{0}' specified for "
- "project '{1}'".format(group_jobname,
- project['name']))
+ "project '{1}'".format(
+ group_jobname, project["name"]
+ )
+ )
seen.add(group_jobname)
continue
template = self._getJobTemplate(group_jobname)
@@ -308,10 +318,9 @@ class YamlParser(object):
d.update(group)
d.update(group_jobparams)
# Except name, since the group's name is not useful
- d['name'] = project['name']
+ d["name"] = project["name"]
if template:
- self._expandYamlForTemplateJob(d, template,
- jobs_glob)
+ self._expandYamlForTemplateJob(d, template, jobs_glob)
continue
# see if it's a template
template = self._getJobTemplate(jobname)
@@ -320,11 +329,12 @@ class YamlParser(object):
d.update(jobparams)
self._expandYamlForTemplateJob(d, template, jobs_glob)
else:
- raise JenkinsJobsException("Failed to find suitable "
- "template named '{0}'"
- .format(jobname))
+ raise JenkinsJobsException(
+ "Failed to find suitable "
+ "template named '{0}'".format(jobname)
+ )
- for viewspec in project.get('views', []):
+ for viewspec in project.get("views", []):
if isinstance(viewspec, dict):
# Singleton dict containing dict of view-specific params
viewname, viewparams = next(iter(viewspec.items()))
@@ -337,18 +347,20 @@ class YamlParser(object):
if view:
# Just naming an existing defined view
if viewname in seen:
- self._handle_dups("Duplicate view '{0}' specified "
- "for project '{1}'"
- .format(viewname, project['name']))
+ self._handle_dups(
+ "Duplicate view '{0}' specified "
+ "for project '{1}'".format(viewname, project["name"])
+ )
seen.add(viewname)
continue
# see if it's a view group
group = self._getViewGroup(viewname)
if group:
- for group_viewspec in group['views']:
+ for group_viewspec in group["views"]:
if isinstance(group_viewspec, dict):
- group_viewname, group_viewparams = \
- next(iter(group_viewspec.items()))
+ group_viewname, group_viewparams = next(
+ iter(group_viewspec.items())
+ )
if not isinstance(group_viewparams, dict):
group_viewparams = {}
else:
@@ -359,8 +371,10 @@ class YamlParser(object):
if group_viewname in seen:
self._handle_dups(
"Duplicate view '{0}' specified for "
- "project '{1}'".format(group_viewname,
- project['name']))
+ "project '{1}'".format(
+ group_viewname, project["name"]
+ )
+ )
seen.add(group_viewname)
continue
template = self._getViewTemplate(group_viewname)
@@ -370,10 +384,9 @@ class YamlParser(object):
d.update(group)
d.update(group_viewparams)
# Except name, since the group's name is not useful
- d['name'] = project['name']
+ d["name"] = project["name"]
if template:
- self._expandYamlForTemplateView(
- d, template, jobs_glob)
+ self._expandYamlForTemplateView(d, template, jobs_glob)
continue
# see if it's a template
template = self._getViewTemplate(viewname)
@@ -382,41 +395,46 @@ class YamlParser(object):
d.update(viewparams)
self._expandYamlForTemplateView(d, template, jobs_glob)
else:
- raise JenkinsJobsException("Failed to find suitable "
- "template named '{0}'"
- .format(viewname))
+ raise JenkinsJobsException(
+ "Failed to find suitable "
+ "template named '{0}'".format(viewname)
+ )
# check for duplicate generated jobs
seen = set()
# walk the list in reverse so that last definition wins
for job in self.jobs[::-1]:
- if job['name'] in seen:
- self._handle_dups("Duplicate definitions for job '{0}' "
- "specified".format(job['name']))
+ if job["name"] in seen:
+ self._handle_dups(
+ "Duplicate definitions for job '{0}' "
+ "specified".format(job["name"])
+ )
self.jobs.remove(job)
- seen.add(job['name'])
+ seen.add(job["name"])
# check for duplicate generated views
seen_views = set()
# walk the list in reverse so that last definition wins
for view in self.views[::-1]:
- if view['name'] in seen_views:
- self._handle_dups("Duplicate definitions for view '{0}' "
- "specified".format(view['name']))
+ if view["name"] in seen_views:
+ self._handle_dups(
+ "Duplicate definitions for view '{0}' "
+ "specified".format(view["name"])
+ )
self.views.remove(view)
- seen_views.add(view['name'])
+ seen_views.add(view["name"])
return self.jobs, self.views
def _expandYamlForTemplateJob(self, project, template, jobs_glob=None):
dimensions = []
- template_name = template['name']
+ template_name = template["name"]
# reject keys that are not useful during yaml expansion
- for k in ['jobs']:
+ for k in ["jobs"]:
project.pop(k)
- excludes = project.pop('exclude', [])
+ excludes = project.pop("exclude", [])
for (k, v) in project.items():
- tmpk = '{{{0}}}'.format(k)
+ tmpk = "{{{0}}}".format(k)
if tmpk not in template_name:
continue
if type(v) == list:
@@ -429,7 +447,7 @@ class YamlParser(object):
for values in itertools.product(*dimensions):
params = copy.deepcopy(project)
params = self._applyDefaults(params, template)
- params['template-name'] = re.sub(r'({|})', r'\1\1', template_name)
+ params["template-name"] = re.sub(r"({|})", r"\1\1", template_name)
try:
expanded_values = {}
@@ -441,29 +459,32 @@ class YamlParser(object):
else:
expanded_values[k] = v
except TypeError:
- project_name = project.pop('name')
+ project_name = project.pop("name")
logger.error(
"Exception thrown while expanding template '%s' for "
"project '%s', with expansion arguments of:\n%s\n"
"Original project input variables for template:\n%s\n"
"Most likely the inputs have items indented incorrectly "
"to describe how they should be applied.\n\nNote yaml "
- "'null' is mapped to python's 'None'", template_name,
+ "'null' is mapped to python's 'None'",
+ template_name,
project_name,
- "".join(local_yaml.dump({k: v}, default_flow_style=False)
- for (k, v) in values),
- local_yaml.dump(project, default_flow_style=False))
+ "".join(
+ local_yaml.dump({k: v}, default_flow_style=False)
+ for (k, v) in values
+ ),
+ local_yaml.dump(project, default_flow_style=False),
+ )
raise
params.update(expanded_values)
try:
params = deep_format(params, params)
except Exception:
- logging.error(
- "Failure formatting params '%s' with itself", params)
+ logging.error("Failure formatting params '%s' with itself", params)
raise
if combination_matches(params, excludes):
- logger.debug('Excluding combination %s', str(params))
+ logger.debug("Excluding combination %s", str(params))
continue
for key in template.keys():
@@ -472,16 +493,22 @@ class YamlParser(object):
try:
expanded = deep_format(
- template, params,
- self.jjb_config.yamlparser['allow_empty_variables'])
+ template,
+ params,
+ self.jjb_config.yamlparser["allow_empty_variables"],
+ )
except Exception:
logging.error(
"Failure formatting template '%s', containing '%s' with "
- "params '%s'", template_name, template, params)
+ "params '%s'",
+ template_name,
+ template,
+ params,
+ )
raise
- expanded['name'] = self._getfullname(expanded)
+ expanded["name"] = self._getfullname(expanded)
- job_name = expanded.get('name')
+ job_name = expanded.get("name")
if jobs_glob and not matches(job_name, jobs_glob):
continue
@@ -495,29 +522,29 @@ class YamlParser(object):
# Views related
def _getView(self, name):
- view = self.data.get('view', {}).get(name, None)
+ view = self.data.get("view", {}).get(name, None)
if not view:
return view
return self._applyDefaults(view)
def _getViewGroup(self, name):
- return self.data.get('view-group', {}).get(name, None)
+ return self.data.get("view-group", {}).get(name, None)
def _getViewTemplate(self, name):
- view = self.data.get('view-template', {}).get(name, None)
+ view = self.data.get("view-template", {}).get(name, None)
if not view:
return view
return self._applyDefaults(view)
def _expandYamlForTemplateView(self, project, template, views_glob=None):
dimensions = []
- template_name = template['name']
+ template_name = template["name"]
# reject keys that are not useful during yaml expansion
- for k in ['views']:
+ for k in ["views"]:
project.pop(k)
- excludes = project.pop('exclude', [])
+ excludes = project.pop("exclude", [])
for (k, v) in project.items():
- tmpk = '{{{0}}}'.format(k)
+ tmpk = "{{{0}}}".format(k)
if tmpk not in template_name:
continue
if type(v) == list:
@@ -543,19 +570,19 @@ class YamlParser(object):
params.update(expanded_values)
params = deep_format(params, params)
if combination_matches(params, excludes):
- logger.debug('Excluding combination %s', str(params))
+ logger.debug("Excluding combination %s", str(params))
continue
for key in template.keys():
if key not in params:
params[key] = template[key]
- params['template-name'] = template_name
+ params["template-name"] = template_name
expanded = deep_format(
- template, params,
- self.jjb_config.yamlparser['allow_empty_variables'])
+ template, params, self.jjb_config.yamlparser["allow_empty_variables"]
+ )
- view_name = expanded.get('name')
+ view_name = expanded.get("name")
if views_glob and not matches(view_name, views_glob):
continue
diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py
index 4b409963..2c997737 100644
--- a/jenkins_jobs/registry.py
+++ b/jenkins_jobs/registry.py
@@ -25,9 +25,7 @@ from jenkins_jobs.errors import JenkinsJobsException
from jenkins_jobs.formatter import deep_format
from jenkins_jobs.local_yaml import Jinja2Loader
-__all__ = [
- "ModuleRegistry"
-]
+__all__ = ["ModuleRegistry"]
logger = logging.getLogger(__name__)
@@ -47,12 +45,11 @@ class ModuleRegistry(object):
else:
self.plugins_dict = self._get_plugins_info_dict(plugins_list)
- for entrypoint in pkg_resources.iter_entry_points(
- group='jenkins_jobs.modules'):
+ for entrypoint in pkg_resources.iter_entry_points(group="jenkins_jobs.modules"):
Mod = entrypoint.load()
mod = Mod(self)
self.modules.append(mod)
- self.modules.sort(key=operator.attrgetter('sequence'))
+ self.modules.sort(key=operator.attrgetter("sequence"))
if mod.component_type is not None:
self.modules_by_component_type[mod.component_type] = entrypoint
@@ -64,12 +61,13 @@ class ModuleRegistry(object):
return a dictionary with the longName and shortName of the plugin
mapped to its plugin info dictionary.
"""
- version = plugin_info.get('version', '0')
- plugin_info['version'] = re.sub(r'(.*)-(?:SNAPSHOT|BETA).*',
- r'\g<1>.preview', version)
+ version = plugin_info.get("version", "0")
+ plugin_info["version"] = re.sub(
+ r"(.*)-(?:SNAPSHOT|BETA).*", r"\g<1>.preview", version
+ )
aliases = []
- for key in ['longName', 'shortName']:
+ for key in ["longName", "shortName"]:
value = plugin_info.get(key, None)
if value is not None:
aliases.append(value)
@@ -130,8 +128,7 @@ class ModuleRegistry(object):
def set_parser_data(self, parser_data):
self.__parser_data = parser_data
- def dispatch(self, component_type, xml_parent,
- component, template_data={}):
+ def dispatch(self, component_type, xml_parent, component, template_data={}):
"""This is a method that you can call from your implementation of
Base.gen_xml or component. It allows modules to define a type
of component, and benefit from extensibility via Python
@@ -152,8 +149,9 @@ class ModuleRegistry(object):
"""
if component_type not in self.modules_by_component_type:
- raise JenkinsJobsException("Unknown component type: "
- "'{0}'.".format(component_type))
+ raise JenkinsJobsException(
+ "Unknown component type: " "'{0}'.".format(component_type)
+ )
entry_point = self.modules_by_component_type[component_type]
component_list_type = entry_point.load().component_list_type
@@ -167,12 +165,16 @@ class ModuleRegistry(object):
# that don't contain any variables, we also deep format those.
try:
component_data = deep_format(
- component_data, template_data,
- self.jjb_config.yamlparser['allow_empty_variables'])
+ component_data,
+ template_data,
+ self.jjb_config.yamlparser["allow_empty_variables"],
+ )
except Exception:
logging.error(
"Failure formatting component ('%s') data '%s'",
- name, component_data)
+ name,
+ component_data,
+ )
raise
else:
# The component is a simple string name, eg "run-tests"
@@ -185,41 +187,54 @@ class ModuleRegistry(object):
module_eps = []
# auto build entry points by inferring from base component_types
mod = pkg_resources.EntryPoint(
- "__all__", entry_point.module_name, dist=entry_point.dist)
+ "__all__", entry_point.module_name, dist=entry_point.dist
+ )
Mod = mod.load()
- func_eps = [Mod.__dict__.get(a) for a in dir(Mod)
- if isinstance(Mod.__dict__.get(a),
- types.FunctionType)]
+ func_eps = [
+ Mod.__dict__.get(a)
+ for a in dir(Mod)
+ if isinstance(Mod.__dict__.get(a), types.FunctionType)
+ ]
for func_ep in func_eps:
try:
# extract entry point based on docstring
- name_line = func_ep.__doc__.split('\n')
- if not name_line[0].startswith('yaml:'):
- logger.debug("Ignoring '%s' as an entry point" %
- name_line)
+ name_line = func_ep.__doc__.split("\n")
+ if not name_line[0].startswith("yaml:"):
+ logger.debug("Ignoring '%s' as an entry point" % name_line)
continue
- ep_name = name_line[0].split(' ')[1]
+ ep_name = name_line[0].split(" ")[1]
except (AttributeError, IndexError):
# AttributeError by docstring not being defined as
# a string to have split called on it.
# IndexError raised by name_line not containing anything
# after the 'yaml:' string.
- logger.debug("Not including func '%s' as an entry point"
- % func_ep.__name__)
+ logger.debug(
+ "Not including func '%s' as an entry point" % func_ep.__name__
+ )
continue
module_eps.append(
pkg_resources.EntryPoint(
- ep_name, entry_point.module_name,
- dist=entry_point.dist, attrs=(func_ep.__name__,)))
+ ep_name,
+ entry_point.module_name,
+ dist=entry_point.dist,
+ attrs=(func_ep.__name__,),
+ )
+ )
logger.debug(
- "Adding auto EP '%s=%s:%s'" %
- (ep_name, entry_point.module_name, func_ep.__name__))
+ "Adding auto EP '%s=%s:%s'"
+ % (ep_name, entry_point.module_name, func_ep.__name__)
+ )
# load from explicitly defined entry points
- module_eps.extend(list(pkg_resources.iter_entry_points(
- group='jenkins_jobs.{0}'.format(component_list_type))))
+ module_eps.extend(
+ list(
+ pkg_resources.iter_entry_points(
+ group="jenkins_jobs.{0}".format(component_list_type)
+ )
+ )
+ )
eps = {}
for module_ep in module_eps:
@@ -227,14 +242,14 @@ class ModuleRegistry(object):
raise JenkinsJobsException(
"Duplicate entry point found for component type: "
"'{0}', '{0}',"
- "name: '{1}'".format(component_type, name))
+ "name: '{1}'".format(component_type, name)
+ )
eps[module_ep.name] = module_ep
# cache both sets of entry points
self._entry_points_cache[component_list_type] = eps
- logger.debug("Cached entry point group %s = %s",
- component_list_type, eps)
+ logger.debug("Cached entry point group %s = %s", component_list_type, eps)
# check for macro first
component = self.parser_data.get(component_type, {}).get(name)
@@ -244,7 +259,8 @@ class ModuleRegistry(object):
logger.warning(
"You have a macro ('%s') defined for '%s' "
"component type that is masking an inbuilt "
- "definition" % (name, component_type))
+ "definition" % (name, component_type)
+ )
for b in component[component_list_type]:
# Pass component_data in as template data to this function
@@ -255,6 +271,7 @@ class ModuleRegistry(object):
func = eps[name].load()
func(self, xml_parent, component_data)
else:
- raise JenkinsJobsException("Unknown entry point or macro '{0}' "
- "for component type: '{1}'.".
- format(name, component_type))
+ raise JenkinsJobsException(
+ "Unknown entry point or macro '{0}' "
+ "for component type: '{1}'.".format(name, component_type)
+ )
diff --git a/jenkins_jobs/sphinx/yaml.py b/jenkins_jobs/sphinx/yaml.py
index 2c7083f7..67ed8f9b 100644
--- a/jenkins_jobs/sphinx/yaml.py
+++ b/jenkins_jobs/sphinx/yaml.py
@@ -29,7 +29,7 @@ from sphinx.ext.autodoc import FunctionDocumenter
from sphinx.locale import _
-yaml_sig_re = re.compile(r'yaml:\s*(.*)')
+yaml_sig_re = re.compile(r"yaml:\s*(.*)")
class PyYAMLFunction(PyModulelevel):
@@ -48,15 +48,14 @@ class PyYAMLFunction(PyModulelevel):
retann = None
# determine module and class name (if applicable), as well as full name
- modname = self.options.get(
- 'module', self.env.temp_data.get('py:module'))
- classname = self.env.temp_data.get('py:class')
+ modname = self.options.get("module", self.env.temp_data.get("py:module"))
+ classname = self.env.temp_data.get("py:class")
fullname = name
- signode['module'] = modname
- signode['class'] = classname
- signode['fullname'] = fullname
+ signode["module"] = modname
+ signode["class"] = classname
+ signode["fullname"] = fullname
sig_prefix = self.get_signature_prefix(sig)
if sig_prefix:
@@ -65,7 +64,7 @@ class PyYAMLFunction(PyModulelevel):
if name_prefix:
signode += addnodes.desc_addname(name_prefix, name_prefix)
- anno = self.options.get('annotation')
+ anno = self.options.get("annotation")
signode += addnodes.desc_name(name, name)
if not arglist:
@@ -75,29 +74,30 @@ class PyYAMLFunction(PyModulelevel):
if retann:
signode += addnodes.desc_returns(retann, retann)
if anno:
- signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
+ signode += addnodes.desc_annotation(" " + anno, " " + anno)
return fullname, name_prefix
_pseudo_parse_arglist(signode, arglist)
if retann:
signode += addnodes.desc_returns(retann, retann)
if anno:
- signode += addnodes.desc_annotation(' ' + anno, ' ' + anno)
+ signode += addnodes.desc_annotation(" " + anno, " " + anno)
return fullname, name_prefix
def get_index_text(self, modname, name_cls):
- return _('%s (in module %s)') % (name_cls[0], modname)
+ return _("%s (in module %s)") % (name_cls[0], modname)
class YAMLFunctionDocumenter(FunctionDocumenter):
priority = FunctionDocumenter.priority + 10
- objtype = 'yamlfunction'
- directivetype = 'yamlfunction'
+ objtype = "yamlfunction"
+ directivetype = "yamlfunction"
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
- if not FunctionDocumenter.can_document_member(member, membername,
- isattr, parent):
+ if not FunctionDocumenter.can_document_member(
+ member, membername, isattr, parent
+ ):
return False
if member.__doc__ is not None and yaml_sig_re.match(member.__doc__):
return True
@@ -108,7 +108,7 @@ class YAMLFunctionDocumenter(FunctionDocumenter):
if len(docstrings) != 1:
return
doclines = docstrings[0]
- setattr(self, '__new_doclines', doclines)
+ setattr(self, "__new_doclines", doclines)
if not doclines:
return
# match first line of docstring against signature RE
@@ -121,11 +121,11 @@ class YAMLFunctionDocumenter(FunctionDocumenter):
i = 1
while i < len(doclines) and not doclines[i].strip():
i += 1
- setattr(self, '__new_doclines', doclines[i:])
+ setattr(self, "__new_doclines", doclines[i:])
return name
def get_doc(self, encoding=None, ignore=1):
- lines = getattr(self, '__new_doclines', None)
+ lines = getattr(self, "__new_doclines", None)
if lines is not None:
return [lines]
return Documenter.get_doc(self, encoding, ignore)
@@ -133,7 +133,7 @@ class YAMLFunctionDocumenter(FunctionDocumenter):
def format_signature(self):
result = self._find_signature()
self._name = result
- return ''
+ return ""
def format_name(self):
return self._name
@@ -141,4 +141,4 @@ class YAMLFunctionDocumenter(FunctionDocumenter):
def setup(app):
app.add_autodocumenter(YAMLFunctionDocumenter)
- app.add_directive_to_domain('py', 'yamlfunction', PyYAMLFunction)
+ app.add_directive_to_domain("py", "yamlfunction", PyYAMLFunction)
diff --git a/jenkins_jobs/utils.py b/jenkins_jobs/utils.py
index 4ce8ad2c..5bb7af84 100644
--- a/jenkins_jobs/utils.py
+++ b/jenkins_jobs/utils.py
@@ -22,14 +22,14 @@ import os.path
from six.moves import input
-def wrap_stream(stream, encoding='utf-8'):
+def wrap_stream(stream, encoding="utf-8"):
try:
stream_enc = stream.encoding
except AttributeError:
stream_enc = locale.getpreferredencoding()
- if hasattr(stream, 'buffer'):
+ if hasattr(stream, "buffer"):
stream = stream.buffer
if str(stream_enc).lower() == str(encoding).lower():
@@ -47,21 +47,27 @@ def recurse_path(root, excludes=None):
patterns = [e for e in excludes if os.path.sep not in e]
absolute = [e for e in excludes if os.path.isabs(e)]
- relative = [e for e in excludes if os.path.sep in e and
- not os.path.isabs(e)]
+ relative = [e for e in excludes if os.path.sep in e and not os.path.isabs(e)]
for root, dirs, files in os.walk(basepath, topdown=True):
# sort in-place to ensure dirnames are visited in alphabetical order
# a predictable order makes it easier to use the retain_anchors option
dirs.sort()
dirs[:] = [
- d for d in dirs
+ d
+ for d in dirs
if not any([fnmatch.fnmatch(d, pattern) for pattern in patterns])
- if not any([fnmatch.fnmatch(os.path.abspath(os.path.join(root, d)),
- path)
- for path in absolute])
- if not any([fnmatch.fnmatch(os.path.relpath(os.path.join(root, d)),
- path)
- for path in relative])
+ if not any(
+ [
+ fnmatch.fnmatch(os.path.abspath(os.path.join(root, d)), path)
+ for path in absolute
+ ]
+ )
+ if not any(
+ [
+ fnmatch.fnmatch(os.path.relpath(os.path.join(root, d)), path)
+ for path in relative
+ ]
+ )
]
pathlist.extend([os.path.join(root, path) for path in dirs])
@@ -69,5 +75,5 @@ def recurse_path(root, excludes=None):
def confirm(question):
- answer = input('%s (Y/N): ' % question).upper().strip()
- return answer == 'Y'
+ answer = input("%s (Y/N): " % question).upper().strip()
+ return answer == "Y"
diff --git a/jenkins_jobs/version.py b/jenkins_jobs/version.py
index 181b8426..537ce0e6 100644
--- a/jenkins_jobs/version.py
+++ b/jenkins_jobs/version.py
@@ -17,4 +17,4 @@
from pbr.version import VersionInfo
-version_info = VersionInfo('jenkins-job-builder')
+version_info = VersionInfo("jenkins-job-builder")
diff --git a/jenkins_jobs/xml_config.py b/jenkins_jobs/xml_config.py
index c6265d6f..fabc7212 100644
--- a/jenkins_jobs/xml_config.py
+++ b/jenkins_jobs/xml_config.py
@@ -22,10 +22,7 @@ import xml.etree.ElementTree as XML
from jenkins_jobs import errors
-__all__ = [
- "XmlJobGenerator",
- "XmlJob"
-]
+__all__ = ["XmlJobGenerator", "XmlJob"]
def remove_ignorable_whitespace(node):
@@ -59,8 +56,8 @@ class XmlJob(object):
return hashlib.md5(self.output()).hexdigest()
def output(self):
- out = minidom.parseString(XML.tostring(self.xml, encoding='UTF-8'))
- return out.toprettyxml(indent=' ', encoding='utf-8')
+ out = minidom.parseString(XML.tostring(self.xml, encoding="UTF-8"))
+ return out.toprettyxml(indent=" ", encoding="utf-8")
class XmlGenerator(object):
@@ -86,25 +83,29 @@ class XmlGenerator(object):
kind = data.get(self.kind_attribute, self.kind_default)
for ep in pkg_resources.iter_entry_points(
- group=self.entry_point_group, name=kind):
+ group=self.entry_point_group, name=kind
+ ):
Mod = ep.load()
mod = Mod(self.registry)
xml = mod.root_xml(data)
if "view-type" not in data:
self._gen_xml(xml, data)
- obj = XmlJob(xml, data['name'])
+ obj = XmlJob(xml, data["name"])
return obj
names = [
- ep.name for ep in pkg_resources.iter_entry_points(
- group=self.entry_point_group)]
+ ep.name
+ for ep in pkg_resources.iter_entry_points(group=self.entry_point_group)
+ ]
raise errors.JenkinsJobsException(
- 'Unrecognized {}: {} (supported types are: {})'.format(
- self.kind_attribute, kind, ', '.join(names)))
+ "Unrecognized {}: {} (supported types are: {})".format(
+ self.kind_attribute, kind, ", ".join(names)
+ )
+ )
def _gen_xml(self, xml, data):
for module in self.registry.modules:
- if hasattr(module, 'gen_xml'):
+ if hasattr(module, "gen_xml"):
module.gen_xml(xml, data)
@@ -112,15 +113,17 @@ class XmlJobGenerator(XmlGenerator):
""" This class is responsible for generating Jenkins Configuration XML from
a compatible intermediate representation of Jenkins Jobs.
"""
- entry_point_group = 'jenkins_jobs.projects'
- kind_attribute = 'project-type'
- kind_default = 'freestyle'
+
+ entry_point_group = "jenkins_jobs.projects"
+ kind_attribute = "project-type"
+ kind_default = "freestyle"
class XmlViewGenerator(XmlGenerator):
""" This class is responsible for generating Jenkins Configuration XML from
a compatible intermediate representation of Jenkins Views.
"""
- entry_point_group = 'jenkins_jobs.views'
- kind_attribute = 'view-type'
- kind_default = 'list'
+
+ entry_point_group = "jenkins_jobs.views"
+ kind_attribute = "view-type"
+ kind_default = "list"
diff --git a/setup.cfg b/setup.cfg
index d29572da..e183d323 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -100,10 +100,8 @@ jenkins_jobs.modules =
zuul=jenkins_jobs.modules.zuul:Zuul
[flake8]
-# These are ignored intentionally in openstack-infra projects; please
-# don't submit patches that solely correct them or enable them.
-# W504 is controversial an apparently conflicting with W503, being impossible
-# to solve both of them while still keeping the line length limited.
-ignore = E125,E128,H,W504
+# Based on https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/
+ignore = E125,E128,E203,E501,H,W504,W503
show-source = True
exclude = .virtualenv,.venv,.tox,dist,build,*.egg,.test
+max-line-length = 88
diff --git a/setup.py b/setup.py
index 782bb21f..0488321b 100644
--- a/setup.py
+++ b/setup.py
@@ -24,6 +24,4 @@ try:
except ImportError:
pass
-setuptools.setup(
- setup_requires=['pbr>=1.8'],
- pbr=True)
+setuptools.setup(setup_requires=["pbr>=1.8"], pbr=True)
diff --git a/tests/base.py b/tests/base.py
index b239f64e..660a3af7 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -59,9 +59,13 @@ except ImportError:
import mock # noqa
-def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml',
- plugins_info_ext='plugins_info.yaml',
- filter_func=None):
+def get_scenarios(
+ fixtures_path,
+ in_ext="yaml",
+ out_ext="xml",
+ plugins_info_ext="plugins_info.yaml",
+ filter_func=None,
+):
"""Returns a list of scenarios, each scenario being described
by two parameters (yaml and xml filenames by default).
- content of the fixture output file (aka expected)
@@ -75,8 +79,9 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml',
else:
files[fn] = [os.path.join(dirpath, fn)]
- input_files = [files[f][0] for f in files if
- re.match(r'.*\.{0}$'.format(in_ext), f)]
+ input_files = [
+ files[f][0] for f in files if re.match(r".*\.{0}$".format(in_ext), f)
+ ]
for input_filename in input_files:
if input_filename.endswith(plugins_info_ext):
@@ -85,21 +90,22 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml',
if callable(filter_func) and filter_func(input_filename):
continue
- output_candidate = re.sub(r'\.{0}$'.format(in_ext),
- '.{0}'.format(out_ext), input_filename)
+ output_candidate = re.sub(
+ r"\.{0}$".format(in_ext), ".{0}".format(out_ext), input_filename
+ )
# assume empty file if no output candidate found
if os.path.basename(output_candidate) in files:
out_filenames = files[os.path.basename(output_candidate)]
else:
out_filenames = None
- plugins_info_candidate = re.sub(r'\.{0}$'.format(in_ext),
- '.{0}'.format(plugins_info_ext),
- input_filename)
+ plugins_info_candidate = re.sub(
+ r"\.{0}$".format(in_ext), ".{0}".format(plugins_info_ext), input_filename
+ )
if os.path.basename(plugins_info_candidate) not in files:
plugins_info_candidate = None
- conf_candidate = re.sub(r'\.yaml$|\.json$', '.conf', input_filename)
+ conf_candidate = re.sub(r"\.yaml$|\.json$", ".conf", input_filename)
conf_filename = files.get(os.path.basename(conf_candidate), None)
if conf_filename:
@@ -108,12 +114,17 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml',
# for testing purposes we want to avoid using user config files
conf_filename = os.devnull
- scenarios.append((input_filename, {
- 'in_filename': input_filename,
- 'out_filenames': out_filenames,
- 'conf_filename': conf_filename,
- 'plugins_info_filename': plugins_info_candidate,
- }))
+ scenarios.append(
+ (
+ input_filename,
+ {
+ "in_filename": input_filename,
+ "out_filenames": out_filenames,
+ "conf_filename": conf_filename,
+ "plugins_info_filename": plugins_info_candidate,
+ },
+ )
+ )
return scenarios
@@ -121,7 +132,7 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml',
class BaseTestCase(testtools.TestCase):
# TestCase settings:
- maxDiff = None # always dump text difference
+ maxDiff = None # always dump text difference
longMessage = True # keep normal error message when providing our
def setUp(self):
@@ -137,12 +148,12 @@ class BaseTestCase(testtools.TestCase):
# Read XML content, assuming it is unicode encoded
xml_content = ""
for f in sorted(self.out_filenames):
- with io.open(f, 'r', encoding='utf-8') as xml_file:
+ with io.open(f, "r", encoding="utf-8") as xml_file:
xml_content += u"%s" % xml_file.read()
return xml_content
def _read_yaml_content(self, filename):
- with io.open(filename, 'r', encoding='utf-8') as yaml_file:
+ with io.open(filename, "r", encoding="utf-8") as yaml_file:
yaml_content = yaml.load(yaml_file)
return yaml_content
@@ -170,10 +181,10 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase):
plugins_info = None
if self.plugins_info_filename:
plugins_info = self._read_yaml_content(self.plugins_info_filename)
- self.addDetail("plugins-info-filename",
- text_content(self.plugins_info_filename))
- self.addDetail("plugins-info",
- text_content(str(plugins_info)))
+ self.addDetail(
+ "plugins-info-filename", text_content(self.plugins_info_filename)
+ )
+ self.addDetail("plugins-info", text_content(str(plugins_info)))
parser = YamlParser(jjb_config)
registry = ModuleRegistry(jjb_config, plugins_info)
@@ -182,76 +193,89 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase):
pub = self.klass(registry)
project = None
- if ('project-type' in yaml_content):
- if (yaml_content['project-type'] == "maven"):
+ if "project-type" in yaml_content:
+ if yaml_content["project-type"] == "maven":
project = project_maven.Maven(registry)
- elif (yaml_content['project-type'] == "matrix"):
+ elif yaml_content["project-type"] == "matrix":
project = project_matrix.Matrix(registry)
- elif (yaml_content['project-type'] == "flow"):
+ elif yaml_content["project-type"] == "flow":
project = project_flow.Flow(registry)
- elif (yaml_content['project-type'] == "multijob"):
+ elif yaml_content["project-type"] == "multijob":
project = project_multijob.MultiJob(registry)
- elif (yaml_content['project-type'] == "multibranch"):
+ elif yaml_content["project-type"] == "multibranch":
project = project_multibranch.WorkflowMultiBranch(registry)
- elif (yaml_content['project-type'] == "multibranch-defaults"):
- project = project_multibranch.WorkflowMultiBranchDefaults(registry) # noqa
- elif (yaml_content['project-type'] == "externaljob"):
+ elif yaml_content["project-type"] == "multibranch-defaults":
+ project = project_multibranch.WorkflowMultiBranchDefaults(
+ registry
+ ) # noqa
+ elif yaml_content["project-type"] == "externaljob":
project = project_externaljob.ExternalJob(registry)
- if 'view-type' in yaml_content:
- if yaml_content['view-type'] == "all":
+ if "view-type" in yaml_content:
+ if yaml_content["view-type"] == "all":
project = view_all.All(None)
- elif yaml_content['view-type'] == "list":
+ elif yaml_content["view-type"] == "list":
project = view_list.List(None)
- elif yaml_content['view-type'] == "pipeline":
+ elif yaml_content["view-type"] == "pipeline":
project = view_pipeline.Pipeline(None)
else:
- raise InvalidAttributeError(
- 'view-type', yaml_content['view-type'])
+ raise InvalidAttributeError("view-type", yaml_content["view-type"])
if project:
xml_project = project.root_xml(yaml_content)
else:
- xml_project = XML.Element('project')
+ xml_project = XML.Element("project")
# Generate the XML tree directly with modules/general
pub.gen_xml(xml_project, yaml_content)
# check output file is under correct path
- if 'name' in yaml_content:
+ if "name" in yaml_content:
prefix = os.path.dirname(self.in_filename)
# split using '/' since fullname uses URL path separator
- expected_folders = [os.path.normpath(
- os.path.join(prefix,
- '/'.join(parser._getfullname(yaml_content).
- split('/')[:-1])))]
+ expected_folders = [
+ os.path.normpath(
+ os.path.join(
+ prefix,
+ "/".join(parser._getfullname(yaml_content).split("/")[:-1]),
+ )
+ )
+ ]
actual_folders = [os.path.dirname(f) for f in self.out_filenames]
self.assertEquals(
- expected_folders, actual_folders,
- "Output file under wrong path, was '%s', should be '%s'" %
- (self.out_filenames[0],
- os.path.join(expected_folders[0],
- os.path.basename(self.out_filenames[0]))))
+ expected_folders,
+ actual_folders,
+ "Output file under wrong path, was '%s', should be '%s'"
+ % (
+ self.out_filenames[0],
+ os.path.join(
+ expected_folders[0], os.path.basename(self.out_filenames[0])
+ ),
+ ),
+ )
# Prettify generated XML
- pretty_xml = XmlJob(xml_project, 'fixturejob').output().decode('utf-8')
+ pretty_xml = XmlJob(xml_project, "fixturejob").output().decode("utf-8")
self.assertThat(
pretty_xml,
- testtools.matchers.DocTestMatches(expected_xml,
- doctest.ELLIPSIS |
- doctest.REPORT_NDIFF)
+ testtools.matchers.DocTestMatches(
+ expected_xml, doctest.ELLIPSIS | doctest.REPORT_NDIFF
+ ),
)
class SingleJobTestCase(BaseScenariosTestCase):
-
def test_yaml_snippet(self):
config = self._get_config()
- expected_xml = self._read_utf8_content().strip() \
- .replace('<BLANKLINE>', '').replace('\n\n', '\n')
+ expected_xml = (
+ self._read_utf8_content()
+ .strip()
+ .replace("<BLANKLINE>", "")
+ .replace("\n\n", "\n")
+ )
parser = YamlParser(config)
parser.parse(self.in_filename)
@@ -259,10 +283,10 @@ class SingleJobTestCase(BaseScenariosTestCase):
plugins_info = None
if self.plugins_info_filename:
plugins_info = self._read_yaml_content(self.plugins_info_filename)
- self.addDetail("plugins-info-filename",
- text_content(self.plugins_info_filename))
- self.addDetail("plugins-info",
- text_content(str(plugins_info)))
+ self.addDetail(
+ "plugins-info-filename", text_content(self.plugins_info_filename)
+ )
+ self.addDetail("plugins-info", text_content(str(plugins_info)))
registry = ModuleRegistry(config, plugins_info)
registry.set_parser_data(parser.data)
@@ -277,53 +301,62 @@ class SingleJobTestCase(BaseScenariosTestCase):
# check reference files are under correct path for folders
prefix = os.path.dirname(self.in_filename)
# split using '/' since fullname uses URL path separator
- expected_folders = list(set([
- os.path.normpath(
- os.path.join(prefix,
- '/'.join(job_data['name'].split('/')[:-1])))
- for job_data in job_data_list
- ]))
+ expected_folders = list(
+ set(
+ [
+ os.path.normpath(
+ os.path.join(prefix, "/".join(job_data["name"].split("/")[:-1]))
+ )
+ for job_data in job_data_list
+ ]
+ )
+ )
actual_folders = [os.path.dirname(f) for f in self.out_filenames]
six.assertCountEqual(
self,
- expected_folders, actual_folders,
- "Output file under wrong path, was '%s', should be '%s'" %
- (self.out_filenames[0],
- os.path.join(expected_folders[0],
- os.path.basename(self.out_filenames[0]))))
+ expected_folders,
+ actual_folders,
+ "Output file under wrong path, was '%s', should be '%s'"
+ % (
+ self.out_filenames[0],
+ os.path.join(
+ expected_folders[0], os.path.basename(self.out_filenames[0])
+ ),
+ ),
+ )
# Prettify generated XML
- pretty_xml = u"\n".join(job.output().decode('utf-8')
- for job in xml_jobs) \
- .strip().replace('\n\n', '\n')
+ pretty_xml = (
+ u"\n".join(job.output().decode("utf-8") for job in xml_jobs)
+ .strip()
+ .replace("\n\n", "\n")
+ )
self.assertThat(
pretty_xml,
- testtools.matchers.DocTestMatches(expected_xml,
- doctest.ELLIPSIS |
- doctest.REPORT_NDIFF))
+ testtools.matchers.DocTestMatches(
+ expected_xml, doctest.ELLIPSIS | doctest.REPORT_NDIFF
+ ),
+ )
class JsonTestCase(BaseScenariosTestCase):
-
def test_yaml_snippet(self):
expected_json = self._read_utf8_content()
yaml_content = self._read_yaml_content(self.in_filename)
- pretty_json = json.dumps(yaml_content, indent=4,
- separators=(',', ': '))
+ pretty_json = json.dumps(yaml_content, indent=4, separators=(",", ": "))
self.assertThat(
pretty_json,
- testtools.matchers.DocTestMatches(expected_json,
- doctest.ELLIPSIS |
- doctest.REPORT_NDIFF)
+ testtools.matchers.DocTestMatches(
+ expected_json, doctest.ELLIPSIS | doctest.REPORT_NDIFF
+ ),
)
class YamlTestCase(BaseScenariosTestCase):
-
def test_yaml_snippet(self):
expected_yaml = self._read_utf8_content()
yaml_content = self._read_yaml_content(self.in_filename)
@@ -337,7 +370,7 @@ class YamlTestCase(BaseScenariosTestCase):
self.assertThat(
pretty_yaml,
- testtools.matchers.DocTestMatches(expected_yaml,
- doctest.ELLIPSIS |
- doctest.REPORT_NDIFF)
+ testtools.matchers.DocTestMatches(
+ expected_yaml, doctest.ELLIPSIS | doctest.REPORT_NDIFF
+ ),
)
diff --git a/tests/builders/test_builders.py b/tests/builders/test_builders.py
index 350d10e8..9d9f77d4 100644
--- a/tests/builders/test_builders.py
+++ b/tests/builders/test_builders.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleBuilders(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = builders.Builders
diff --git a/tests/cachestorage/test_cachestorage.py b/tests/cachestorage/test_cachestorage.py
index 138f1406..34803895 100644
--- a/tests/cachestorage/test_cachestorage.py
+++ b/tests/cachestorage/test_cachestorage.py
@@ -21,28 +21,25 @@ from tests.base import mock
class TestCaseJobCache(base.BaseTestCase):
-
- @mock.patch('jenkins_jobs.builder.JobCache.get_cache_dir',
- lambda x: '/bad/file')
+ @mock.patch("jenkins_jobs.builder.JobCache.get_cache_dir", lambda x: "/bad/file")
def test_save_on_exit(self):
"""
Test that the cache is saved on normal object deletion
"""
- with mock.patch('jenkins_jobs.builder.JobCache.save') as save_mock:
- with mock.patch('os.path.isfile', return_value=False):
- with mock.patch('jenkins_jobs.builder.JobCache._lock'):
+ with mock.patch("jenkins_jobs.builder.JobCache.save") as save_mock:
+ with mock.patch("os.path.isfile", return_value=False):
+ with mock.patch("jenkins_jobs.builder.JobCache._lock"):
jenkins_jobs.builder.JobCache("dummy")
save_mock.assert_called_with()
- @mock.patch('jenkins_jobs.builder.JobCache.get_cache_dir',
- lambda x: '/bad/file')
+ @mock.patch("jenkins_jobs.builder.JobCache.get_cache_dir", lambda x: "/bad/file")
def test_cache_file(self):
"""
Test providing a cachefile.
"""
test_file = os.path.abspath(__file__)
- with mock.patch('os.path.join', return_value=test_file):
- with mock.patch('yaml.load'):
- with mock.patch('jenkins_jobs.builder.JobCache._lock'):
+ with mock.patch("os.path.join", return_value=test_file):
+ with mock.patch("yaml.load"):
+ with mock.patch("jenkins_jobs.builder.JobCache._lock"):
jenkins_jobs.builder.JobCache("dummy").data = None
diff --git a/tests/cmd/subcommands/test_delete.py b/tests/cmd/subcommands/test_delete.py
index 4e577fd6..252b82ec 100644
--- a/tests/cmd/subcommands/test_delete.py
+++ b/tests/cmd/subcommands/test_delete.py
@@ -24,51 +24,49 @@ from tests.base import mock
from tests.cmd.test_cmd import CmdTestsBase
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class DeleteTests(CmdTestsBase):
-
- @mock.patch('jenkins_jobs.cli.subcommand.update.'
- 'JenkinsManager.delete_jobs')
- @mock.patch('jenkins_jobs.cli.subcommand.update.'
- 'JenkinsManager.delete_views')
+ @mock.patch("jenkins_jobs.cli.subcommand.update." "JenkinsManager.delete_jobs")
+ @mock.patch("jenkins_jobs.cli.subcommand.update." "JenkinsManager.delete_views")
def test_delete_single_job(self, delete_job_mock, delete_view_mock):
"""
Test handling the deletion of a single Jenkins job.
"""
- args = ['--conf', self.default_config_file, 'delete', 'test_job']
+ args = ["--conf", self.default_config_file, "delete", "test_job"]
self.execute_jenkins_jobs_with_args(args)
- @mock.patch('jenkins_jobs.cli.subcommand.update.'
- 'JenkinsManager.delete_jobs')
- @mock.patch('jenkins_jobs.cli.subcommand.update.'
- 'JenkinsManager.delete_views')
+ @mock.patch("jenkins_jobs.cli.subcommand.update." "JenkinsManager.delete_jobs")
+ @mock.patch("jenkins_jobs.cli.subcommand.update." "JenkinsManager.delete_views")
def test_delete_multiple_jobs(self, delete_job_mock, delete_view_mock):
"""
Test handling the deletion of multiple Jenkins jobs.
"""
- args = ['--conf', self.default_config_file,
- 'delete', 'test_job1', 'test_job2']
+ args = ["--conf", self.default_config_file, "delete", "test_job1", "test_job2"]
self.execute_jenkins_jobs_with_args(args)
- @mock.patch('jenkins_jobs.builder.JenkinsManager.delete_job')
+ @mock.patch("jenkins_jobs.builder.JenkinsManager.delete_job")
def test_delete_using_glob_params(self, delete_job_mock):
"""
Test handling the deletion of multiple Jenkins jobs using the glob
parameters feature.
"""
- args = ['--conf', self.default_config_file,
- 'delete', '--path',
- os.path.join(self.fixtures_path,
- 'cmd-002.yaml'),
- '*bar*']
+ args = [
+ "--conf",
+ self.default_config_file,
+ "delete",
+ "--path",
+ os.path.join(self.fixtures_path, "cmd-002.yaml"),
+ "*bar*",
+ ]
self.execute_jenkins_jobs_with_args(args)
- calls = [mock.call('bar001'), mock.call('bar002')]
+ calls = [mock.call("bar001"), mock.call("bar002")]
delete_job_mock.assert_has_calls(calls, any_order=True)
- self.assertEqual(delete_job_mock.call_count, len(calls),
- "Jenkins.delete_job() was called '%s' times when "
- "expected '%s'" % (delete_job_mock.call_count,
- len(calls)))
+ self.assertEqual(
+ delete_job_mock.call_count,
+ len(calls),
+ "Jenkins.delete_job() was called '%s' times when "
+ "expected '%s'" % (delete_job_mock.call_count, len(calls)),
+ )
diff --git a/tests/cmd/subcommands/test_delete_all.py b/tests/cmd/subcommands/test_delete_all.py
index a8f6e0b4..f2ef46e8 100644
--- a/tests/cmd/subcommands/test_delete_all.py
+++ b/tests/cmd/subcommands/test_delete_all.py
@@ -21,31 +21,27 @@ from tests.base import mock
from tests.cmd.test_cmd import CmdTestsBase
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class DeleteAllTests(CmdTestsBase):
-
- @mock.patch('jenkins_jobs.cli.subcommand.update.'
- 'JenkinsManager.delete_all_jobs')
+ @mock.patch("jenkins_jobs.cli.subcommand.update." "JenkinsManager.delete_all_jobs")
def test_delete_all_accept(self, delete_job_mock):
"""
Test handling the deletion of a single Jenkins job.
"""
- args = ['--conf', self.default_config_file, 'delete-all']
- with mock.patch('jenkins_jobs.builder.JenkinsManager.get_views',
- return_value=[None]):
- with mock.patch('jenkins_jobs.utils.input', return_value="y"):
+ args = ["--conf", self.default_config_file, "delete-all"]
+ with mock.patch(
+ "jenkins_jobs.builder.JenkinsManager.get_views", return_value=[None]
+ ):
+ with mock.patch("jenkins_jobs.utils.input", return_value="y"):
self.execute_jenkins_jobs_with_args(args)
- @mock.patch('jenkins_jobs.cli.subcommand.update.'
- 'JenkinsManager.delete_all_jobs')
+ @mock.patch("jenkins_jobs.cli.subcommand.update." "JenkinsManager.delete_all_jobs")
def test_delete_all_abort(self, delete_job_mock):
"""
Test handling the deletion of a single Jenkins job.
"""
- args = ['--conf', self.default_config_file, 'delete-all']
- with mock.patch('jenkins_jobs.utils.input', return_value="n"):
- self.assertRaises(SystemExit,
- self.execute_jenkins_jobs_with_args, args)
+ args = ["--conf", self.default_config_file, "delete-all"]
+ with mock.patch("jenkins_jobs.utils.input", return_value="n"):
+ self.assertRaises(SystemExit, self.execute_jenkins_jobs_with_args, args)
diff --git a/tests/cmd/subcommands/test_list.py b/tests/cmd/subcommands/test_list.py
index 1e413ee1..4f3ebd7a 100644
--- a/tests/cmd/subcommands/test_list.py
+++ b/tests/cmd/subcommands/test_list.py
@@ -21,65 +21,70 @@ from tests.base import mock
from tests.cmd.test_cmd import CmdTestsBase
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class ListFromJenkinsTests(TestWithScenarios, CmdTestsBase):
scenarios = [
- ('single',
- dict(jobs=['job1'], globs=[], found=['job1'])),
- ('multiple',
- dict(jobs=['job1', 'job2'], globs=[], found=['job1', 'job2'])),
- ('multiple_with_glob',
- dict(jobs=['job1', 'job2', 'job3'], globs=["job[1-2]"],
- found=['job1', 'job2'])),
- ('multiple_with_multi_glob',
- dict(jobs=['job1', 'job2', 'job3', 'job4'],
- globs=["job1", "job[24]"],
- found=['job1', 'job2', 'job4'])),
+ ("single", dict(jobs=["job1"], globs=[], found=["job1"])),
+ ("multiple", dict(jobs=["job1", "job2"], globs=[], found=["job1", "job2"])),
+ (
+ "multiple_with_glob",
+ dict(
+ jobs=["job1", "job2", "job3"],
+ globs=["job[1-2]"],
+ found=["job1", "job2"],
+ ),
+ ),
+ (
+ "multiple_with_multi_glob",
+ dict(
+ jobs=["job1", "job2", "job3", "job4"],
+ globs=["job1", "job[24]"],
+ found=["job1", "job2", "job4"],
+ ),
+ ),
]
- @mock.patch('jenkins_jobs.builder.JenkinsManager.get_jobs')
+ @mock.patch("jenkins_jobs.builder.JenkinsManager.get_jobs")
def test_list(self, get_jobs_mock):
-
def _get_jobs():
- return [{'name': name} for name in self.jobs]
+ return [{"name": name} for name in self.jobs]
get_jobs_mock.side_effect = _get_jobs
console_out = io.BytesIO()
- args = ['--conf', self.default_config_file, 'list'] + self.globs
+ args = ["--conf", self.default_config_file, "list"] + self.globs
- with mock.patch('sys.stdout', console_out):
+ with mock.patch("sys.stdout", console_out):
self.execute_jenkins_jobs_with_args(args)
- self.assertEqual(console_out.getvalue().decode('utf-8').rstrip(),
- ('\n'.join(self.found)))
+ self.assertEqual(
+ console_out.getvalue().decode("utf-8").rstrip(), ("\n".join(self.found))
+ )
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class ListFromYamlTests(TestWithScenarios, CmdTestsBase):
scenarios = [
- ('all',
- dict(globs=[], found=['bam001', 'bar001', 'bar002', 'baz001'])),
- ('some',
- dict(globs=["*am*", "*002", "bar001"],
- found=['bam001', 'bar001', 'bar002'])),
+ ("all", dict(globs=[], found=["bam001", "bar001", "bar002", "baz001"])),
+ (
+ "some",
+ dict(
+ globs=["*am*", "*002", "bar001"], found=["bam001", "bar001", "bar002"]
+ ),
+ ),
]
def test_list(self):
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
console_out = io.BytesIO()
- with mock.patch('sys.stdout', console_out):
+ with mock.patch("sys.stdout", console_out):
self.execute_jenkins_jobs_with_args(
- ['--conf',
- self.default_config_file,
- 'list',
- '-p',
- path] + self.globs)
-
- self.assertEqual(console_out.getvalue().decode('utf-8').rstrip(),
- ('\n'.join(self.found)))
+ ["--conf", self.default_config_file, "list", "-p", path] + self.globs
+ )
+
+ self.assertEqual(
+ console_out.getvalue().decode("utf-8").rstrip(), ("\n".join(self.found))
+ )
diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py
index 0ac06d4a..1e0234a9 100644
--- a/tests/cmd/subcommands/test_test.py
+++ b/tests/cmd/subcommands/test_test.py
@@ -35,31 +35,35 @@ from tests.base import mock
from tests.cmd.test_cmd import CmdTestsBase
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class TestTests(CmdTestsBase):
-
def test_non_existing_job(self):
"""
Run test mode and pass a non-existing job name
(probably better to fail here)
"""
- args = ['--conf', self.default_config_file, 'test',
- os.path.join(self.fixtures_path,
- 'cmd-001.yaml'),
- 'invalid']
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ "invalid",
+ ]
self.execute_jenkins_jobs_with_args(args)
def test_valid_job(self):
"""
Run test mode and pass a valid job name
"""
- args = ['--conf', self.default_config_file, 'test',
- os.path.join(self.fixtures_path,
- 'cmd-001.yaml'),
- 'foo-job']
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ "foo-job",
+ ]
console_out = io.BytesIO()
- with mock.patch('sys.stdout', console_out):
+ with mock.patch("sys.stdout", console_out):
self.execute_jenkins_jobs_with_args(args)
def test_console_output(self):
@@ -68,13 +72,18 @@ class TestTests(CmdTestsBase):
"""
console_out = io.BytesIO()
- with mock.patch('sys.stdout', console_out):
- args = ['--conf', self.default_config_file, 'test',
- os.path.join(self.fixtures_path, 'cmd-001.yaml')]
+ with mock.patch("sys.stdout", console_out):
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ ]
self.execute_jenkins_jobs_with_args(args)
- xml_content = io.open(os.path.join(self.fixtures_path, 'cmd-001.xml'),
- 'r', encoding='utf-8').read()
- self.assertEqual(console_out.getvalue().decode('utf-8'), xml_content)
+ xml_content = io.open(
+ os.path.join(self.fixtures_path, "cmd-001.xml"), "r", encoding="utf-8"
+ ).read()
+ self.assertEqual(console_out.getvalue().decode("utf-8"), xml_content)
def test_output_dir(self):
"""
@@ -83,11 +92,11 @@ class TestTests(CmdTestsBase):
"""
tmpdir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmpdir)
- args = ['test', os.path.join(self.fixtures_path, 'cmd-001.yaml'),
- '-o', tmpdir]
+ args = ["test", os.path.join(self.fixtures_path, "cmd-001.yaml"), "-o", tmpdir]
self.execute_jenkins_jobs_with_args(args)
- self.expectThat(os.path.join(tmpdir, 'foo-job'),
- testtools.matchers.FileExists())
+ self.expectThat(
+ os.path.join(tmpdir, "foo-job"), testtools.matchers.FileExists()
+ )
def test_output_dir_config_xml(self):
"""
@@ -96,11 +105,18 @@ class TestTests(CmdTestsBase):
"""
tmpdir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, tmpdir)
- args = ['test', os.path.join(self.fixtures_path, 'cmd-001.yaml'),
- '-o', tmpdir, '--config-xml']
+ args = [
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ "-o",
+ tmpdir,
+ "--config-xml",
+ ]
self.execute_jenkins_jobs_with_args(args)
- self.expectThat(os.path.join(tmpdir, 'foo-job', 'config.xml'),
- testtools.matchers.FileExists())
+ self.expectThat(
+ os.path.join(tmpdir, "foo-job", "config.xml"),
+ testtools.matchers.FileExists(),
+ )
def test_stream_input_output_no_encoding_exceed_recursion(self):
"""
@@ -109,13 +125,12 @@ class TestTests(CmdTestsBase):
"""
console_out = io.BytesIO()
- input_file = os.path.join(self.fixtures_path,
- 'large-number-of-jobs-001.yaml')
- with io.open(input_file, 'r') as f:
- with mock.patch('sys.stdout', console_out):
+ input_file = os.path.join(self.fixtures_path, "large-number-of-jobs-001.yaml")
+ with io.open(input_file, "r") as f:
+ with mock.patch("sys.stdout", console_out):
console_out.encoding = None
- with mock.patch('sys.stdin', f):
- args = ['test']
+ with mock.patch("sys.stdin", f):
+ args = ["test"]
self.execute_jenkins_jobs_with_args(args)
def test_stream_input_output_utf8_encoding(self):
@@ -125,16 +140,17 @@ class TestTests(CmdTestsBase):
"""
console_out = io.BytesIO()
- input_file = os.path.join(self.fixtures_path, 'cmd-001.yaml')
- with io.open(input_file, 'r') as f:
- with mock.patch('sys.stdout', console_out):
- with mock.patch('sys.stdin', f):
- args = ['--conf', self.default_config_file, 'test']
+ input_file = os.path.join(self.fixtures_path, "cmd-001.yaml")
+ with io.open(input_file, "r") as f:
+ with mock.patch("sys.stdout", console_out):
+ with mock.patch("sys.stdin", f):
+ args = ["--conf", self.default_config_file, "test"]
self.execute_jenkins_jobs_with_args(args)
- xml_content = io.open(os.path.join(self.fixtures_path, 'cmd-001.xml'),
- 'r', encoding='utf-8').read()
- value = console_out.getvalue().decode('utf-8')
+ xml_content = io.open(
+ os.path.join(self.fixtures_path, "cmd-001.xml"), "r", encoding="utf-8"
+ ).read()
+ value = console_out.getvalue().decode("utf-8")
self.assertEqual(value, xml_content)
def test_stream_input_output_ascii_encoding(self):
@@ -143,18 +159,19 @@ class TestTests(CmdTestsBase):
ascii encoding with unicode input
"""
console_out = io.BytesIO()
- console_out.encoding = 'ascii'
+ console_out.encoding = "ascii"
- input_file = os.path.join(self.fixtures_path, 'cmd-001.yaml')
- with io.open(input_file, 'r') as f:
- with mock.patch('sys.stdout', console_out):
- with mock.patch('sys.stdin', f):
- args = ['--conf', self.default_config_file, 'test']
+ input_file = os.path.join(self.fixtures_path, "cmd-001.yaml")
+ with io.open(input_file, "r") as f:
+ with mock.patch("sys.stdout", console_out):
+ with mock.patch("sys.stdin", f):
+ args = ["--conf", self.default_config_file, "test"]
self.execute_jenkins_jobs_with_args(args)
- xml_content = io.open(os.path.join(self.fixtures_path, 'cmd-001.xml'),
- 'r', encoding='utf-8').read()
- value = console_out.getvalue().decode('ascii')
+ xml_content = io.open(
+ os.path.join(self.fixtures_path, "cmd-001.xml"), "r", encoding="utf-8"
+ ).read()
+ value = console_out.getvalue().decode("ascii")
self.assertEqual(value, xml_content)
def test_stream_output_ascii_encoding_invalid_char(self):
@@ -164,65 +181,65 @@ class TestTests(CmdTestsBase):
that cannot be converted.
"""
console_out = io.BytesIO()
- console_out.encoding = 'ascii'
+ console_out.encoding = "ascii"
- input_file = os.path.join(self.fixtures_path, 'unicode001.yaml')
- with io.open(input_file, 'r', encoding='utf-8') as f:
- with mock.patch('sys.stdout', console_out):
- with mock.patch('sys.stdin', f):
- args = ['--conf', self.default_config_file, 'test']
+ input_file = os.path.join(self.fixtures_path, "unicode001.yaml")
+ with io.open(input_file, "r", encoding="utf-8") as f:
+ with mock.patch("sys.stdout", console_out):
+ with mock.patch("sys.stdin", f):
+ args = ["--conf", self.default_config_file, "test"]
jenkins_jobs = entry.JenkinsJobs(args)
e = self.assertRaises(UnicodeError, jenkins_jobs.execute)
self.assertIn("'ascii' codec can't encode character", str(e))
- @mock.patch(
- 'jenkins_jobs.cli.subcommand.update.XmlJobGenerator.generateXML')
- @mock.patch('jenkins_jobs.cli.subcommand.update.ModuleRegistry')
+ @mock.patch("jenkins_jobs.cli.subcommand.update.XmlJobGenerator.generateXML")
+ @mock.patch("jenkins_jobs.cli.subcommand.update.ModuleRegistry")
def test_plugins_info_stub_option(self, registry_mock, generateXML_mock):
"""
Test handling of plugins_info stub option.
"""
- plugins_info_stub_yaml_file = os.path.join(self.fixtures_path,
- 'plugins-info.yaml')
- args = ['--conf',
- os.path.join(self.fixtures_path, 'cmd-001.conf'),
- 'test',
- '-p',
- plugins_info_stub_yaml_file,
- os.path.join(self.fixtures_path, 'cmd-001.yaml')]
+ plugins_info_stub_yaml_file = os.path.join(
+ self.fixtures_path, "plugins-info.yaml"
+ )
+ args = [
+ "--conf",
+ os.path.join(self.fixtures_path, "cmd-001.conf"),
+ "test",
+ "-p",
+ plugins_info_stub_yaml_file,
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ ]
self.execute_jenkins_jobs_with_args(args)
- with io.open(plugins_info_stub_yaml_file,
- 'r', encoding='utf-8') as yaml_file:
+ with io.open(plugins_info_stub_yaml_file, "r", encoding="utf-8") as yaml_file:
plugins_info_list = yaml.load(yaml_file)
- registry_mock.assert_called_with(mock.ANY,
- plugins_info_list)
+ registry_mock.assert_called_with(mock.ANY, plugins_info_list)
- @mock.patch(
- 'jenkins_jobs.cli.subcommand.update.XmlJobGenerator.generateXML')
- @mock.patch('jenkins_jobs.cli.subcommand.update.ModuleRegistry')
- def test_bogus_plugins_info_stub_option(self, registry_mock,
- generateXML_mock):
+ @mock.patch("jenkins_jobs.cli.subcommand.update.XmlJobGenerator.generateXML")
+ @mock.patch("jenkins_jobs.cli.subcommand.update.ModuleRegistry")
+ def test_bogus_plugins_info_stub_option(self, registry_mock, generateXML_mock):
"""
Verify that a JenkinsJobException is raised if the plugins_info stub
file does not yield a list as its top-level object.
"""
- plugins_info_stub_yaml_file = os.path.join(self.fixtures_path,
- 'bogus-plugins-info.yaml')
- args = ['--conf',
- os.path.join(self.fixtures_path, 'cmd-001.conf'),
- 'test',
- '-p',
- plugins_info_stub_yaml_file,
- os.path.join(self.fixtures_path, 'cmd-001.yaml')]
+ plugins_info_stub_yaml_file = os.path.join(
+ self.fixtures_path, "bogus-plugins-info.yaml"
+ )
+ args = [
+ "--conf",
+ os.path.join(self.fixtures_path, "cmd-001.conf"),
+ "test",
+ "-p",
+ plugins_info_stub_yaml_file,
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ ]
stderr = StringIO()
- with mock.patch('sys.stderr', stderr):
+ with mock.patch("sys.stderr", stderr):
self.assertRaises(SystemExit, entry.JenkinsJobs, args)
- self.assertIn("must contain a Yaml list",
- stderr.getvalue())
+ self.assertIn("must contain a Yaml list", stderr.getvalue())
class TestJenkinsGetPluginInfoError(CmdTestsBase):
@@ -231,9 +248,8 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
jenkins_jobs.builder.JenkinsManager.get_plugins_info
"""
- @mock.patch('jenkins.Jenkins.get_plugins')
- def test_console_output_jenkins_connection_failure_warning(
- self, get_plugins_mock):
+ @mock.patch("jenkins.Jenkins.get_plugins")
+ def test_console_output_jenkins_connection_failure_warning(self, get_plugins_mock):
"""
Run test mode and verify that failed Jenkins connection attempt
exception does not bubble out of cmd.main. Ideally, we would also test
@@ -242,44 +258,51 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
suite.
"""
- get_plugins_mock.side_effect = \
- jenkins.JenkinsException("Connection refused")
- with mock.patch('sys.stdout'):
+ get_plugins_mock.side_effect = jenkins.JenkinsException("Connection refused")
+ with mock.patch("sys.stdout"):
try:
- args = ['--conf', self.default_config_file, 'test',
- os.path.join(self.fixtures_path, 'cmd-001.yaml')]
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ ]
self.execute_jenkins_jobs_with_args(args)
except jenkins.JenkinsException:
self.fail("jenkins.JenkinsException propagated to main")
except Exception:
pass # only care about jenkins.JenkinsException for now
- @mock.patch('jenkins.Jenkins.get_plugins')
- def test_skip_plugin_retrieval_if_no_config_provided(
- self, get_plugins_mock):
+ @mock.patch("jenkins.Jenkins.get_plugins")
+ def test_skip_plugin_retrieval_if_no_config_provided(self, get_plugins_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', new_callable=io.BytesIO):
- args = ['--conf', self.default_config_file, 'test',
- os.path.join(self.fixtures_path, 'cmd-001.yaml')]
+ with mock.patch("sys.stdout", new_callable=io.BytesIO):
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ ]
entry.JenkinsJobs(args)
self.assertFalse(get_plugins_mock.called)
- @mock.patch('jenkins.Jenkins.get_plugins_info')
+ @mock.patch("jenkins.Jenkins.get_plugins_info")
def test_skip_plugin_retrieval_if_disabled(self, get_plugins_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', new_callable=io.BytesIO):
- args = ['--conf',
- os.path.join(self.fixtures_path,
- 'disable-query-plugins.conf'),
- 'test',
- os.path.join(self.fixtures_path, 'cmd-001.yaml')]
+ with mock.patch("sys.stdout", new_callable=io.BytesIO):
+ args = [
+ "--conf",
+ os.path.join(self.fixtures_path, "disable-query-plugins.conf"),
+ "test",
+ os.path.join(self.fixtures_path, "cmd-001.yaml"),
+ ]
entry.JenkinsJobs(args)
self.assertFalse(get_plugins_mock.called)
@@ -291,8 +314,8 @@ class MatchesDirMissingFilesMismatch(object):
def describe(self):
return "{0} and {1} contain different files".format(
- self.left_directory,
- self.right_directory)
+ self.left_directory, self.right_directory
+ )
def get_details(self):
return {}
@@ -308,11 +331,15 @@ class MatchesDirFileContentsMismatch(object):
right_contents = open(self.right_file).readlines()
return "{0} is not equal to {1}:\n{2}".format(
- difflib.unified_diff(left_contents, right_contents,
- fromfile=self.left_file,
- tofile=self.right_file),
+ difflib.unified_diff(
+ left_contents,
+ right_contents,
+ fromfile=self.left_file,
+ tofile=self.right_file,
+ ),
self.left_file,
- self.right_file)
+ self.right_file,
+ )
def get_details(self):
return {}
@@ -337,8 +364,7 @@ class MatchesDir(object):
other_files.sort()
if self.__files != other_files:
- return MatchesDirMissingFilesMismatch(self.__directory,
- other_directory)
+ return MatchesDirMissingFilesMismatch(self.__directory, other_directory)
for i, file in enumerate(self.__files):
my_file = os.path.join(self.__directory, file)
@@ -349,16 +375,15 @@ class MatchesDir(object):
return None
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class TestTestsMultiPath(CmdTestsBase):
-
def setUp(self):
super(TestTestsMultiPath, self).setUp()
- path_list = [os.path.join(self.fixtures_path,
- 'multi-path/yamldirs/', p)
- for p in ['dir1', 'dir2']]
+ path_list = [
+ os.path.join(self.fixtures_path, "multi-path/yamldirs/", p)
+ for p in ["dir1", "dir2"]
+ ]
self.multipath = os.pathsep.join(path_list)
self.output_dir = tempfile.mkdtemp()
@@ -374,45 +399,74 @@ class TestTestsMultiPath(CmdTestsBase):
"""
Run test mode and pass multiple paths.
"""
- args = ['--conf', self.default_config_file, 'test',
- '-o', self.output_dir, self.multipath]
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ "-o",
+ self.output_dir,
+ self.multipath,
+ ]
self.execute_jenkins_jobs_with_args(args)
- self.check_dirs_match(os.path.join(self.fixtures_path,
- 'multi-path/output_simple'))
+ self.check_dirs_match(
+ os.path.join(self.fixtures_path, "multi-path/output_simple")
+ )
def test_recursive_multi_path_command_line(self):
"""
Run test mode and pass multiple paths with recursive path option.
"""
- args = ['--conf', self.default_config_file, 'test',
- '-o', self.output_dir, '-r', self.multipath]
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ "-o",
+ self.output_dir,
+ "-r",
+ self.multipath,
+ ]
self.execute_jenkins_jobs_with_args(args)
- self.check_dirs_match(os.path.join(self.fixtures_path,
- 'multi-path/output_recursive'))
+ self.check_dirs_match(
+ os.path.join(self.fixtures_path, "multi-path/output_recursive")
+ )
def test_recursive_multi_path_config_file(self):
# test recursive set in configuration file
- args = ['--conf', os.path.join(self.fixtures_path,
- 'multi-path/builder-recursive.ini'),
- 'test', '-o', self.output_dir, self.multipath]
+ args = [
+ "--conf",
+ os.path.join(self.fixtures_path, "multi-path/builder-recursive.ini"),
+ "test",
+ "-o",
+ self.output_dir,
+ self.multipath,
+ ]
self.execute_jenkins_jobs_with_args(args)
- self.check_dirs_match(os.path.join(self.fixtures_path,
- 'multi-path/output_recursive'))
+ self.check_dirs_match(
+ os.path.join(self.fixtures_path, "multi-path/output_recursive")
+ )
def test_recursive_multi_path_with_excludes(self):
"""
Run test mode and pass multiple paths with recursive path option.
"""
- exclude_path = os.path.join(self.fixtures_path,
- 'multi-path/yamldirs/dir2/dir1')
- args = ['--conf', self.default_config_file, 'test',
- '-x', exclude_path,
- '-o', self.output_dir,
- '-r', self.multipath]
+ exclude_path = os.path.join(self.fixtures_path, "multi-path/yamldirs/dir2/dir1")
+ args = [
+ "--conf",
+ self.default_config_file,
+ "test",
+ "-x",
+ exclude_path,
+ "-o",
+ self.output_dir,
+ "-r",
+ self.multipath,
+ ]
self.execute_jenkins_jobs_with_args(args)
self.check_dirs_match(
- os.path.join(self.fixtures_path,
- 'multi-path/output_recursive_with_excludes'))
+ os.path.join(
+ self.fixtures_path, "multi-path/output_recursive_with_excludes"
+ )
+ )
diff --git a/tests/cmd/subcommands/test_update.py b/tests/cmd/subcommands/test_update.py
index 9606951f..f755f4b8 100644
--- a/tests/cmd/subcommands/test_update.py
+++ b/tests/cmd/subcommands/test_update.py
@@ -25,61 +25,60 @@ from tests.base import mock
from tests.cmd.test_cmd import CmdTestsBase
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class UpdateTests(CmdTestsBase):
-
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.job_exists')
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs')
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.reconfig_job')
- def test_update_jobs(self,
- jenkins_reconfig_job,
- jenkins_get_jobs,
- jenkins_job_exists, ):
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job")
+ def test_update_jobs(
+ self, jenkins_reconfig_job, jenkins_get_jobs, jenkins_job_exists
+ ):
"""
Test update_job is called
"""
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- args = ['--conf', self.default_config_file, 'update', path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ args = ["--conf", self.default_config_file, "update", path]
self.execute_jenkins_jobs_with_args(args)
jenkins_reconfig_job.assert_has_calls(
- [mock.call(job_name, mock.ANY)
- for job_name in ['bar001', 'bar002', 'baz001', 'bam001']],
- any_order=True
+ [
+ mock.call(job_name, mock.ANY)
+ for job_name in ["bar001", "bar002", "baz001", "bam001"]
+ ],
+ any_order=True,
)
- @mock.patch('jenkins_jobs.builder.JenkinsManager.is_job',
- return_value=True)
- @mock.patch('jenkins_jobs.builder.JenkinsManager.get_jobs')
- @mock.patch('jenkins_jobs.builder.JenkinsManager.get_job_md5')
- @mock.patch('jenkins_jobs.builder.JenkinsManager.update_job')
- def test_update_jobs_decode_job_output(self, update_job_mock,
- get_job_md5_mock, get_jobs_mock,
- is_job_mock):
+ @mock.patch("jenkins_jobs.builder.JenkinsManager.is_job", return_value=True)
+ @mock.patch("jenkins_jobs.builder.JenkinsManager.get_jobs")
+ @mock.patch("jenkins_jobs.builder.JenkinsManager.get_job_md5")
+ @mock.patch("jenkins_jobs.builder.JenkinsManager.update_job")
+ def test_update_jobs_decode_job_output(
+ self, update_job_mock, get_job_md5_mock, get_jobs_mock, is_job_mock
+ ):
"""
Test that job xml output has been decoded before attempting to update
"""
# don't care about the value returned here
update_job_mock.return_value = ([], 0)
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- args = ['--conf', self.default_config_file, 'update', path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ args = ["--conf", self.default_config_file, "update", path]
self.execute_jenkins_jobs_with_args(args)
- self.assertTrue(isinstance(update_job_mock.call_args[0][1],
- six.text_type))
-
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.job_exists')
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs')
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.reconfig_job')
- @mock.patch('jenkins_jobs.builder.jenkins.Jenkins.delete_job')
- def test_update_jobs_and_delete_old(self,
- jenkins_delete_job,
- jenkins_reconfig_job,
- jenkins_get_all_jobs,
- jenkins_job_exists):
+ self.assertTrue(isinstance(update_job_mock.call_args[0][1], six.text_type))
+
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.job_exists")
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.get_all_jobs")
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.reconfig_job")
+ @mock.patch("jenkins_jobs.builder.jenkins.Jenkins.delete_job")
+ def test_update_jobs_and_delete_old(
+ self,
+ jenkins_delete_job,
+ jenkins_reconfig_job,
+ jenkins_get_all_jobs,
+ jenkins_job_exists,
+ ):
"""
Test update behaviour with --delete-old option
@@ -92,25 +91,26 @@ class UpdateTests(CmdTestsBase):
* mock out a call to jenkins.Jenkins.job_exists() to always return
True.
"""
- yaml_jobs = ['bar001', 'bar002', 'baz001', 'bam001']
- extra_jobs = ['old_job001', 'old_job002', 'unmanaged']
+ yaml_jobs = ["bar001", "bar002", "baz001", "bam001"]
+ extra_jobs = ["old_job001", "old_job002", "unmanaged"]
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- args = ['--conf', self.default_config_file, 'update', '--delete-old',
- path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ args = ["--conf", self.default_config_file, "update", "--delete-old", path]
jenkins_get_all_jobs.return_value = [
- {'fullname': name} for name in yaml_jobs + extra_jobs]
+ {"fullname": name} for name in yaml_jobs + extra_jobs
+ ]
- with mock.patch('jenkins_jobs.builder.JenkinsManager.is_managed',
- side_effect=(lambda name: name != 'unmanaged')):
+ with mock.patch(
+ "jenkins_jobs.builder.JenkinsManager.is_managed",
+ side_effect=(lambda name: name != "unmanaged"),
+ ):
self.execute_jenkins_jobs_with_args(args)
jenkins_reconfig_job.assert_has_calls(
- [mock.call(job_name, mock.ANY) for job_name in yaml_jobs],
- any_order=True
+ [mock.call(job_name, mock.ANY) for job_name in yaml_jobs], any_order=True
)
- calls = [mock.call(name) for name in extra_jobs if name != 'unmanaged']
+ calls = [mock.call(name) for name in extra_jobs if name != "unmanaged"]
jenkins_delete_job.assert_has_calls(calls)
# to ensure only the calls we expected were made, have to check
# there were no others, as no API call for assert_has_only_calls
diff --git a/tests/cmd/test_cmd.py b/tests/cmd/test_cmd.py
index 5ec1dd7a..e847ec39 100644
--- a/tests/cmd/test_cmd.py
+++ b/tests/cmd/test_cmd.py
@@ -7,7 +7,7 @@ from tests.base import mock
class CmdTestsBase(base.BaseTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
def setUp(self):
super(CmdTestsBase, self).setUp()
@@ -17,13 +17,11 @@ class CmdTestsBase(base.BaseTestCase):
# are run in parallel. Stub out the JobCache to ensure that each
# test can safely create the cache directory without risk of
# interference.
- cache_patch = mock.patch('jenkins_jobs.builder.JobCache',
- autospec=True)
+ cache_patch = mock.patch("jenkins_jobs.builder.JobCache", autospec=True)
self.cache_mock = cache_patch.start()
self.addCleanup(cache_patch.stop)
- self.default_config_file = os.path.join(self.fixtures_path,
- 'empty_builder.ini')
+ self.default_config_file = os.path.join(self.fixtures_path, "empty_builder.ini")
def execute_jenkins_jobs_with_args(self, args):
jenkins_jobs = entry.JenkinsJobs(args)
@@ -31,10 +29,9 @@ class CmdTestsBase(base.BaseTestCase):
class TestCmd(CmdTestsBase):
-
def test_with_empty_args(self):
"""
User passes no args, should fail with SystemExit
"""
- with mock.patch('sys.stderr'):
+ with mock.patch("sys.stderr"):
self.assertRaises(SystemExit, entry.JenkinsJobs, [])
diff --git a/tests/cmd/test_config.py b/tests/cmd/test_config.py
index 6cbb6d4d..ecae8a9a 100644
--- a/tests/cmd/test_config.py
+++ b/tests/cmd/test_config.py
@@ -9,25 +9,25 @@ from jenkins_jobs.cli import entry
from jenkins_jobs import builder
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class TestConfigs(CmdTestsBase):
- global_conf = '/etc/jenkins_jobs/jenkins_jobs.ini'
- user_conf = os.path.join(os.path.expanduser('~'), '.config',
- 'jenkins_jobs', 'jenkins_jobs.ini')
- local_conf = os.path.join(os.path.dirname(__file__),
- 'jenkins_jobs.ini')
+ global_conf = "/etc/jenkins_jobs/jenkins_jobs.ini"
+ user_conf = os.path.join(
+ os.path.expanduser("~"), ".config", "jenkins_jobs", "jenkins_jobs.ini"
+ )
+ local_conf = os.path.join(os.path.dirname(__file__), "jenkins_jobs.ini")
def test_use_global_config(self):
"""
Verify that JJB uses the global config file by default
"""
- args = ['test', 'foo']
- conffp = io.open(self.default_config_file, 'r', encoding='utf-8')
+ args = ["test", "foo"]
+ conffp = io.open(self.default_config_file, "r", encoding="utf-8")
+
+ with patch("os.path.isfile", return_value=True) as m_isfile:
- with patch('os.path.isfile', return_value=True) as m_isfile:
def side_effect(path):
if path == self.global_conf:
return True
@@ -35,36 +35,35 @@ class TestConfigs(CmdTestsBase):
m_isfile.side_effect = side_effect
- with patch('io.open', return_value=conffp) as m_open:
+ with patch("io.open", return_value=conffp) as m_open:
entry.JenkinsJobs(args, config_file_required=True)
- m_open.assert_called_with(self.global_conf, 'r',
- encoding='utf-8')
+ m_open.assert_called_with(self.global_conf, "r", encoding="utf-8")
def test_use_config_in_user_home(self):
"""
Verify that JJB uses config file in user home folder
"""
- args = ['test', 'foo']
+ args = ["test", "foo"]
+
+ conffp = io.open(self.default_config_file, "r", encoding="utf-8")
+ with patch("os.path.isfile", return_value=True) as m_isfile:
- conffp = io.open(self.default_config_file, 'r', encoding='utf-8')
- with patch('os.path.isfile', return_value=True) as m_isfile:
def side_effect(path):
if path == self.user_conf:
return True
return False
m_isfile.side_effect = side_effect
- with patch('io.open', return_value=conffp) as m_open:
+ with patch("io.open", return_value=conffp) as m_open:
entry.JenkinsJobs(args, config_file_required=True)
- m_open.assert_called_with(self.user_conf, 'r',
- encoding='utf-8')
+ m_open.assert_called_with(self.user_conf, "r", encoding="utf-8")
def test_non_existing_config_dir(self):
"""
Run test mode and pass a non-existing configuration directory
"""
- args = ['--conf', self.default_config_file, 'test', 'foo']
+ args = ["--conf", self.default_config_file, "test", "foo"]
jenkins_jobs = entry.JenkinsJobs(args)
self.assertRaises(IOError, jenkins_jobs.execute)
@@ -72,8 +71,7 @@ class TestConfigs(CmdTestsBase):
"""
Run test mode and pass a non-existing configuration file
"""
- args = ['--conf', self.default_config_file, 'test',
- 'non-existing.yaml']
+ args = ["--conf", self.default_config_file, "test", "non-existing.yaml"]
jenkins_jobs = entry.JenkinsJobs(args)
self.assertRaises(IOError, jenkins_jobs.execute)
@@ -82,37 +80,42 @@ class TestConfigs(CmdTestsBase):
Run test mode and check config settings from conf file retained
when none of the global CLI options are set.
"""
- config_file = os.path.join(self.fixtures_path,
- 'settings_from_config.ini')
- args = ['--conf', config_file, 'test', 'dummy.yaml']
+ config_file = os.path.join(self.fixtures_path, "settings_from_config.ini")
+ args = ["--conf", config_file, "test", "dummy.yaml"]
jenkins_jobs = entry.JenkinsJobs(args)
jjb_config = jenkins_jobs.jjb_config
- self.assertEqual(jjb_config.jenkins['user'], "jenkins_user")
- self.assertEqual(jjb_config.jenkins['password'], "jenkins_password")
- self.assertEqual(jjb_config.builder['ignore_cache'], True)
- self.assertEqual(jjb_config.builder['flush_cache'], True)
- self.assertEqual(jjb_config.builder['update'], "all")
- self.assertEqual(
- jjb_config.yamlparser['allow_empty_variables'], True)
+ self.assertEqual(jjb_config.jenkins["user"], "jenkins_user")
+ self.assertEqual(jjb_config.jenkins["password"], "jenkins_password")
+ self.assertEqual(jjb_config.builder["ignore_cache"], True)
+ self.assertEqual(jjb_config.builder["flush_cache"], True)
+ self.assertEqual(jjb_config.builder["update"], "all")
+ self.assertEqual(jjb_config.yamlparser["allow_empty_variables"], True)
def test_config_options_overriden_by_cli(self):
"""
Run test mode and check config settings from conf file retained
when none of the global CLI options are set.
"""
- args = ['--user', 'myuser', '--password', 'mypassword',
- '--ignore-cache', '--flush-cache', '--allow-empty-variables',
- 'test', 'dummy.yaml']
+ args = [
+ "--user",
+ "myuser",
+ "--password",
+ "mypassword",
+ "--ignore-cache",
+ "--flush-cache",
+ "--allow-empty-variables",
+ "test",
+ "dummy.yaml",
+ ]
jenkins_jobs = entry.JenkinsJobs(args)
jjb_config = jenkins_jobs.jjb_config
- self.assertEqual(jjb_config.jenkins['user'], "myuser")
- self.assertEqual(jjb_config.jenkins['password'], "mypassword")
- self.assertEqual(jjb_config.builder['ignore_cache'], True)
- self.assertEqual(jjb_config.builder['flush_cache'], True)
- self.assertEqual(
- jjb_config.yamlparser['allow_empty_variables'], True)
-
- @mock.patch('jenkins_jobs.cli.subcommand.update.JenkinsManager')
+ self.assertEqual(jjb_config.jenkins["user"], "myuser")
+ self.assertEqual(jjb_config.jenkins["password"], "mypassword")
+ self.assertEqual(jjb_config.builder["ignore_cache"], True)
+ self.assertEqual(jjb_config.builder["flush_cache"], True)
+ self.assertEqual(jjb_config.yamlparser["allow_empty_variables"], True)
+
+ @mock.patch("jenkins_jobs.cli.subcommand.update.JenkinsManager")
def test_update_timeout_not_set(self, jenkins_mock):
"""Check that timeout is left unset
@@ -120,8 +123,8 @@ class TestConfigs(CmdTestsBase):
provided via the config option.
"""
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- args = ['--conf', self.default_config_file, 'update', path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ args = ["--conf", self.default_config_file, "update", path]
jenkins_mock.return_value.update_jobs.return_value = ([], 0)
jenkins_mock.return_value.update_views.return_value = ([], 0)
@@ -131,10 +134,9 @@ class TestConfigs(CmdTestsBase):
# contains the expected timeout value.
jjb_config = jenkins_mock.call_args[0][0]
- self.assertEqual(jjb_config.jenkins['timeout'],
- builder._DEFAULT_TIMEOUT)
+ self.assertEqual(jjb_config.jenkins["timeout"], builder._DEFAULT_TIMEOUT)
- @mock.patch('jenkins_jobs.cli.subcommand.update.JenkinsManager')
+ @mock.patch("jenkins_jobs.cli.subcommand.update.JenkinsManager")
def test_update_timeout_set(self, jenkins_mock):
"""Check that timeout is set correctly
@@ -142,10 +144,9 @@ class TestConfigs(CmdTestsBase):
provided via the config option.
"""
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- config_file = os.path.join(self.fixtures_path,
- 'non-default-timeout.ini')
- args = ['--conf', config_file, 'update', path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ config_file = os.path.join(self.fixtures_path, "non-default-timeout.ini")
+ args = ["--conf", config_file, "update", path]
jenkins_mock.return_value.update_jobs.return_value = ([], 0)
jenkins_mock.return_value.update_views.return_value = ([], 0)
@@ -155,4 +156,4 @@ class TestConfigs(CmdTestsBase):
# contains the expected timeout value.
jjb_config = jenkins_mock.call_args[0][0]
- self.assertEqual(jjb_config.jenkins['timeout'], 0.2)
+ self.assertEqual(jjb_config.jenkins["timeout"], 0.2)
diff --git a/tests/cmd/test_recurse_path.py b/tests/cmd/test_recurse_path.py
index 2fb3eb32..acb609f3 100644
--- a/tests/cmd/test_recurse_path.py
+++ b/tests/cmd/test_recurse_path.py
@@ -22,6 +22,7 @@ def fake_os_walk(paths):
new_path = "/".join([top, name])
for x in os_walk(new_path, topdown):
yield x
+
return os_walk
@@ -29,10 +30,9 @@ def fake_os_walk(paths):
# attempting to create the cache directory multiple times as the tests
# are run in parallel. Stub out the JobCache to ensure that each
# test can safely create the object without effect.
-@mock.patch('jenkins_jobs.builder.JobCache', mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JobCache", mock.MagicMock)
class CmdRecursePath(testtools.TestCase):
-
- @mock.patch('jenkins_jobs.utils.os.walk')
+ @mock.patch("jenkins_jobs.utils.os.walk")
def test_recursive_path_option_exclude_pattern(self, oswalk_mock):
"""
Test paths returned by the recursive processing when using pattern
@@ -48,21 +48,21 @@ class CmdRecursePath(testtools.TestCase):
"""
os_walk_paths = [
- ('/jjb_configs', (['dir1', 'dir2', 'dir3', 'test3'], ())),
- ('/jjb_configs/dir1', (['test1'], ('file'))),
- ('/jjb_configs/dir2', (['test2'], ())),
- ('/jjb_configs/dir3', (['bar'], ())),
- ('/jjb_configs/dir3/bar', ([], ())),
- ('/jjb_configs/test3/bar', None),
- ('/jjb_configs/test3/baz', None)
+ ("/jjb_configs", (["dir1", "dir2", "dir3", "test3"], ())),
+ ("/jjb_configs/dir1", (["test1"], ("file"))),
+ ("/jjb_configs/dir2", (["test2"], ())),
+ ("/jjb_configs/dir3", (["bar"], ())),
+ ("/jjb_configs/dir3/bar", ([], ())),
+ ("/jjb_configs/test3/bar", None),
+ ("/jjb_configs/test3/baz", None),
]
paths = [k for k, v in os_walk_paths if v is not None]
oswalk_mock.side_effect = fake_os_walk(os_walk_paths)
- self.assertEqual(paths, utils.recurse_path('/jjb_configs', ['test*']))
+ self.assertEqual(paths, utils.recurse_path("/jjb_configs", ["test*"]))
- @mock.patch('jenkins_jobs.utils.os.walk')
+ @mock.patch("jenkins_jobs.utils.os.walk")
def test_recursive_path_option_exclude_absolute(self, oswalk_mock):
"""
Test paths returned by the recursive processing when using absolute
@@ -78,25 +78,26 @@ class CmdRecursePath(testtools.TestCase):
"""
os_walk_paths = [
- ('/jjb_configs', (['dir1', 'dir2', 'dir3', 'test3'], ())),
- ('/jjb_configs/dir1', None),
- ('/jjb_configs/dir2', (['test2'], ())),
- ('/jjb_configs/dir3', (['bar'], ())),
- ('/jjb_configs/test3', (['bar', 'baz'], ())),
- ('/jjb_configs/dir2/test2', ([], ())),
- ('/jjb_configs/dir3/bar', ([], ())),
- ('/jjb_configs/test3/bar', ([], ())),
- ('/jjb_configs/test3/baz', ([], ()))
+ ("/jjb_configs", (["dir1", "dir2", "dir3", "test3"], ())),
+ ("/jjb_configs/dir1", None),
+ ("/jjb_configs/dir2", (["test2"], ())),
+ ("/jjb_configs/dir3", (["bar"], ())),
+ ("/jjb_configs/test3", (["bar", "baz"], ())),
+ ("/jjb_configs/dir2/test2", ([], ())),
+ ("/jjb_configs/dir3/bar", ([], ())),
+ ("/jjb_configs/test3/bar", ([], ())),
+ ("/jjb_configs/test3/baz", ([], ())),
]
paths = [k for k, v in os_walk_paths if v is not None]
oswalk_mock.side_effect = fake_os_walk(os_walk_paths)
- self.assertEqual(paths, utils.recurse_path('/jjb_configs',
- ['/jjb_configs/dir1']))
+ self.assertEqual(
+ paths, utils.recurse_path("/jjb_configs", ["/jjb_configs/dir1"])
+ )
- @mock.patch('jenkins_jobs.utils.os.walk')
+ @mock.patch("jenkins_jobs.utils.os.walk")
def test_recursive_path_option_exclude_relative(self, oswalk_mock):
"""
Test paths returned by the recursive processing when using relative
@@ -112,25 +113,27 @@ class CmdRecursePath(testtools.TestCase):
"""
os_walk_paths = [
- ('jjb_configs', (['dir1', 'dir2', 'dir3', 'test3'], ())),
- ('jjb_configs/dir1', (['test'], ('file'))),
- ('jjb_configs/dir2', (['test2'], ())),
- ('jjb_configs/dir3', (['bar'], ())),
- ('jjb_configs/test3', (['bar', 'baz'], ())),
- ('jjb_configs/dir1/test', ([], ())),
- ('jjb_configs/dir2/test2', ([], ())),
- ('jjb_configs/dir3/bar', ([], ())),
- ('jjb_configs/test3/bar', None),
- ('jjb_configs/test3/baz', ([], ()))
+ ("jjb_configs", (["dir1", "dir2", "dir3", "test3"], ())),
+ ("jjb_configs/dir1", (["test"], ("file"))),
+ ("jjb_configs/dir2", (["test2"], ())),
+ ("jjb_configs/dir3", (["bar"], ())),
+ ("jjb_configs/test3", (["bar", "baz"], ())),
+ ("jjb_configs/dir1/test", ([], ())),
+ ("jjb_configs/dir2/test2", ([], ())),
+ ("jjb_configs/dir3/bar", ([], ())),
+ ("jjb_configs/test3/bar", None),
+ ("jjb_configs/test3/baz", ([], ())),
]
rel_os_walk_paths = [
- (os.path.abspath(
- os.path.join(os.path.curdir, k)), v) for k, v in os_walk_paths]
+ (os.path.abspath(os.path.join(os.path.curdir, k)), v)
+ for k, v in os_walk_paths
+ ]
paths = [k for k, v in rel_os_walk_paths if v is not None]
oswalk_mock.side_effect = fake_os_walk(rel_os_walk_paths)
- self.assertEqual(paths, utils.recurse_path('jjb_configs',
- ['jjb_configs/test3/bar']))
+ self.assertEqual(
+ paths, utils.recurse_path("jjb_configs", ["jjb_configs/test3/bar"])
+ )
diff --git a/tests/duplicates/test_duplicates.py b/tests/duplicates/test_duplicates.py
index 0a90c9b4..d22aea2a 100644
--- a/tests/duplicates/test_duplicates.py
+++ b/tests/duplicates/test_duplicates.py
@@ -23,10 +23,10 @@ from tests.base import mock
class TestCaseModuleDuplicates(base.SingleJobTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
- @mock.patch('jenkins_jobs.builder.logger', autospec=True)
+ @mock.patch("jenkins_jobs.builder.logger", autospec=True)
def test_yaml_snippet(self, mock_logger):
if os.path.basename(self.in_filename).startswith("exception_"):
diff --git a/tests/errors/test_exceptions.py b/tests/errors/test_exceptions.py
index 2fba25a6..079a5406 100644
--- a/tests/errors/test_exceptions.py
+++ b/tests/errors/test_exceptions.py
@@ -16,19 +16,19 @@ def dispatch(exc, *args):
def gen_xml(exc, *args):
- data = {'module': 'data'} # noqa
+ data = {"module": "data"} # noqa
raise exc(*args)
class TestInvalidAttributeError(base.BaseTestCase):
-
def test_no_valid_values(self):
# When given no valid values, InvalidAttributeError simply displays a
# message indicating the invalid value, the component type, the
# component name, and the attribute name.
message = "'{0}' is an invalid value for attribute {1}.{2}".format(
- "fnord", "type.name", "fubar")
+ "fnord", "type.name", "fubar"
+ )
with ExpectedException(errors.InvalidAttributeError, message):
dispatch(errors.InvalidAttributeError, "fubar", "fnord")
@@ -37,46 +37,49 @@ class TestInvalidAttributeError(base.BaseTestCase):
# indicating the invalid value, the component type, the component name,
# and the attribute name; additionally, it lists the valid values for
# the current component type & name.
- valid_values = ['herp', 'derp']
+ valid_values = ["herp", "derp"]
message = "'{0}' is an invalid value for attribute {1}.{2}".format(
- "fnord", "type.name", "fubar")
+ "fnord", "type.name", "fubar"
+ )
message += "\nValid values include: {0}".format(
- ', '.join("'{0}'".format(value) for value in valid_values))
+ ", ".join("'{0}'".format(value) for value in valid_values)
+ )
with ExpectedException(errors.InvalidAttributeError, message):
- dispatch(errors.InvalidAttributeError, "fubar", "fnord",
- valid_values)
+ dispatch(errors.InvalidAttributeError, "fubar", "fnord", valid_values)
class TestMissingAttributeError(base.BaseTestCase):
-
def test_with_single_missing_attribute(self):
# When passed a single missing attribute, display a message indicating
# * the missing attribute
# * which component type and component name is missing it.
- missing_attribute = 'herp'
+ missing_attribute = "herp"
message = "Missing {0} from an instance of '{1}'".format(
- missing_attribute, 'type.name')
+ missing_attribute, "type.name"
+ )
with ExpectedException(errors.MissingAttributeError, message):
dispatch(errors.MissingAttributeError, missing_attribute)
- with ExpectedException(errors.MissingAttributeError,
- message.replace('type.name', 'module')):
+ with ExpectedException(
+ errors.MissingAttributeError, message.replace("type.name", "module")
+ ):
gen_xml(errors.MissingAttributeError, missing_attribute)
def test_with_multiple_missing_attributes(self):
# When passed multiple missing attributes, display a message indicating
# * the missing attributes
# * which component type and component name is missing it.
- missing_attribute = ['herp', 'derp']
+ missing_attribute = ["herp", "derp"]
message = "One of {0} must be present in '{1}'".format(
- ', '.join("'{0}'".format(value) for value in missing_attribute),
- 'type.name')
+ ", ".join("'{0}'".format(value) for value in missing_attribute), "type.name"
+ )
with ExpectedException(errors.MissingAttributeError, message):
dispatch(errors.MissingAttributeError, missing_attribute)
- with ExpectedException(errors.MissingAttributeError,
- message.replace('type.name', 'module')):
+ with ExpectedException(
+ errors.MissingAttributeError, message.replace("type.name", "module")
+ ):
gen_xml(errors.MissingAttributeError, missing_attribute)
diff --git a/tests/general/test_general.py b/tests/general/test_general.py
index 503310fa..d7a7d77e 100644
--- a/tests/general/test_general.py
+++ b/tests/general/test_general.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleGeneral(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = general.General
diff --git a/tests/hipchat/test_hipchat.py b/tests/hipchat/test_hipchat.py
index 6ff6d969..9e276754 100644
--- a/tests/hipchat/test_hipchat.py
+++ b/tests/hipchat/test_hipchat.py
@@ -19,6 +19,6 @@ from tests import base
class TestCaseModulePublishers(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = hipchat_notif.HipChat
diff --git a/tests/jenkins_manager/test_manager.py b/tests/jenkins_manager/test_manager.py
index ba579d15..530a8eaf 100644
--- a/tests/jenkins_manager/test_manager.py
+++ b/tests/jenkins_manager/test_manager.py
@@ -21,66 +21,65 @@ from tests.base import mock
_plugins_info = {}
-_plugins_info['plugin1'] = {'longName': '',
- 'shortName': '',
- 'version': ''}
+_plugins_info["plugin1"] = {"longName": "", "shortName": "", "version": ""}
-@mock.patch('jenkins_jobs.builder.JobCache', mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JobCache", mock.MagicMock)
class TestCaseTestJenkinsManager(base.BaseTestCase):
-
def setUp(self):
super(TestCaseTestJenkinsManager, self).setUp()
self.jjb_config = JJBConfig()
self.jjb_config.validate()
def test_plugins_list(self):
- self.jjb_config.builder['plugins_info'] = _plugins_info
+ self.jjb_config.builder["plugins_info"] = _plugins_info
self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
self.assertEqual(self.builder.plugins_list, _plugins_info)
- @mock.patch.object(jenkins_jobs.builder.jenkins.Jenkins,
- 'get_plugins',
- return_value=_plugins_info)
+ @mock.patch.object(
+ jenkins_jobs.builder.jenkins.Jenkins, "get_plugins", return_value=_plugins_info
+ )
def test_plugins_list_from_jenkins(self, jenkins_mock):
# Trigger fetching the plugins from jenkins when accessing the property
- self.jjb_config.builder['plugins_info'] = {}
+ self.jjb_config.builder["plugins_info"] = {}
self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
# See https://github.com/formiaczek/multi_key_dict/issues/17
# self.assertEqual(self.builder.plugins_list, k)
for key_tuple in self.builder.plugins_list.keys():
for key in key_tuple:
- self.assertEqual(self.builder.plugins_list[key],
- _plugins_info[key])
+ self.assertEqual(self.builder.plugins_list[key], _plugins_info[key])
def test_delete_managed(self):
- self.jjb_config.builder['plugins_info'] = {}
+ self.jjb_config.builder["plugins_info"] = {}
self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
- with mock.patch.multiple('jenkins_jobs.builder.JenkinsManager',
- get_jobs=mock.DEFAULT,
- is_job=mock.DEFAULT,
- is_managed=mock.DEFAULT,
- delete_job=mock.DEFAULT) as patches:
- patches['get_jobs'].return_value = [{'fullname': 'job1'},
- {'fullname': 'job2'}]
- patches['is_managed'].side_effect = [True, True]
- patches['is_job'].side_effect = [True, True]
+ with mock.patch.multiple(
+ "jenkins_jobs.builder.JenkinsManager",
+ get_jobs=mock.DEFAULT,
+ is_job=mock.DEFAULT,
+ is_managed=mock.DEFAULT,
+ delete_job=mock.DEFAULT,
+ ) as patches:
+ patches["get_jobs"].return_value = [
+ {"fullname": "job1"},
+ {"fullname": "job2"},
+ ]
+ patches["is_managed"].side_effect = [True, True]
+ patches["is_job"].side_effect = [True, True]
self.builder.delete_old_managed()
- self.assertEqual(patches['delete_job'].call_count, 2)
+ self.assertEqual(patches["delete_job"].call_count, 2)
def _get_plugins_info_error_test(self, error_string):
builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
exception = jenkins_jobs.builder.jenkins.JenkinsException(error_string)
- with mock.patch.object(builder.jenkins, 'get_plugins',
- side_effect=exception):
+ with mock.patch.object(builder.jenkins, "get_plugins", side_effect=exception):
plugins_info = builder.get_plugins_info()
- self.assertEqual([_plugins_info['plugin1']], plugins_info)
+ self.assertEqual([_plugins_info["plugin1"]], plugins_info)
def test_get_plugins_info_handles_connectionrefused_errors(self):
- self._get_plugins_info_error_test('Connection refused')
+ self._get_plugins_info_error_test("Connection refused")
def test_get_plugins_info_handles_forbidden_errors(self):
- self._get_plugins_info_error_test('Forbidden')
+ self._get_plugins_info_error_test("Forbidden")
diff --git a/tests/jsonparser/test_jsonparser.py b/tests/jsonparser/test_jsonparser.py
index 5e62534b..6257b4d3 100644
--- a/tests/jsonparser/test_jsonparser.py
+++ b/tests/jsonparser/test_jsonparser.py
@@ -21,5 +21,5 @@ from tests import base
class TestCaseModuleJsonParser(base.SingleJobTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
- scenarios = base.get_scenarios(fixtures_path, in_ext='json', out_ext='xml')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
+ scenarios = base.get_scenarios(fixtures_path, in_ext="json", out_ext="xml")
diff --git a/tests/localyaml/test_localyaml.py b/tests/localyaml/test_localyaml.py
index 788bb3b2..c41c9ed8 100644
--- a/tests/localyaml/test_localyaml.py
+++ b/tests/localyaml/test_localyaml.py
@@ -34,15 +34,16 @@ class TestCaseLocalYamlInclude(base.JsonTestCase):
Verify application specific tags independently of any changes to
modules XML parsing behaviour
"""
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
- scenarios = base.get_scenarios(fixtures_path, 'yaml', 'json',
- filter_func=_exclude_scenarios)
+
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
+ scenarios = base.get_scenarios(
+ fixtures_path, "yaml", "json", filter_func=_exclude_scenarios
+ )
def test_yaml_snippet(self):
if os.path.basename(self.in_filename).startswith("exception_"):
- with ExpectedException(ComposerError,
- "^found duplicate anchor .*"):
+ with ExpectedException(ComposerError, "^found duplicate anchor .*"):
super(TestCaseLocalYamlInclude, self).test_yaml_snippet()
else:
super(TestCaseLocalYamlInclude, self).test_yaml_snippet()
@@ -53,13 +54,14 @@ class TestCaseLocalYamlAnchorAlias(base.YamlTestCase):
Verify yaml input is expanded to the expected yaml output when using yaml
anchors and aliases.
"""
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
- scenarios = base.get_scenarios(fixtures_path, 'iyaml', 'oyaml')
+
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
+ scenarios = base.get_scenarios(fixtures_path, "iyaml", "oyaml")
class TestCaseLocalYamlIncludeAnchors(base.BaseTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
def test_multiple_same_anchor_in_multiple_toplevel_yaml(self):
"""
@@ -70,14 +72,16 @@ class TestCaseLocalYamlIncludeAnchors(base.BaseTestCase):
are treated by the yaml loader as independent.
"""
- files = ["custom_same_anchor-001-part1.yaml",
- "custom_same_anchor-001-part2.yaml"]
+ files = [
+ "custom_same_anchor-001-part1.yaml",
+ "custom_same_anchor-001-part2.yaml",
+ ]
jjb_config = JJBConfig()
- jjb_config.jenkins['url'] = 'http://example.com'
- jjb_config.jenkins['user'] = 'jenkins'
- jjb_config.jenkins['password'] = 'password'
- jjb_config.builder['plugins_info'] = []
+ jjb_config.jenkins["url"] = "http://example.com"
+ jjb_config.jenkins["user"] = "jenkins"
+ jjb_config.jenkins["password"] = "password"
+ jjb_config.builder["plugins_info"] = []
jjb_config.validate()
j = YamlParser(jjb_config)
j.load_files([os.path.join(self.fixtures_path, f) for f in files])
@@ -85,22 +89,20 @@ class TestCaseLocalYamlIncludeAnchors(base.BaseTestCase):
class TestCaseLocalYamlRetainAnchors(base.BaseTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
def test_retain_anchors_default(self):
"""
Verify that anchors are NOT retained across files by default.
"""
- files = ["custom_retain_anchors_include001.yaml",
- "custom_retain_anchors.yaml"]
+ files = ["custom_retain_anchors_include001.yaml", "custom_retain_anchors.yaml"]
jjb_config = JJBConfig()
# use the default value for retain_anchors
jjb_config.validate()
j = YamlParser(jjb_config)
- with ExpectedException(yaml.composer.ComposerError,
- "found undefined alias.*"):
+ with ExpectedException(yaml.composer.ComposerError, "found undefined alias.*"):
j.load_files([os.path.join(self.fixtures_path, f) for f in files])
def test_retain_anchors_enabled(self):
@@ -109,11 +111,10 @@ class TestCaseLocalYamlRetainAnchors(base.BaseTestCase):
enabled in the config.
"""
- files = ["custom_retain_anchors_include001.yaml",
- "custom_retain_anchors.yaml"]
+ files = ["custom_retain_anchors_include001.yaml", "custom_retain_anchors.yaml"]
jjb_config = JJBConfig()
- jjb_config.yamlparser['retain_anchors'] = True
+ jjb_config.yamlparser["retain_anchors"] = True
jjb_config.validate()
j = YamlParser(jjb_config)
j.load_files([os.path.join(self.fixtures_path, f) for f in files])
diff --git a/tests/macros/test_macros.py b/tests/macros/test_macros.py
index 392154ff..1535e333 100644
--- a/tests/macros/test_macros.py
+++ b/tests/macros/test_macros.py
@@ -21,5 +21,5 @@ from tests import base
class TestCaseModuleSCMMacro(base.SingleJobTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
diff --git a/tests/moduleregistry/test_moduleregistry.py b/tests/moduleregistry/test_moduleregistry.py
index 0b0c54a4..743f180f 100644
--- a/tests/moduleregistry/test_moduleregistry.py
+++ b/tests/moduleregistry/test_moduleregistry.py
@@ -9,25 +9,34 @@ from tests import base
class ModuleRegistryPluginInfoTestsWithScenarios(
- testscenarios.TestWithScenarios, base.BaseTestCase):
+ testscenarios.TestWithScenarios, base.BaseTestCase
+):
scenarios = [
- ('s1', dict(v1='1.0.0', op='__gt__', v2='0.8.0')),
- ('s2', dict(v1='1.0.1alpha', op='__gt__', v2='1.0.0')),
- ('s3', dict(v1='1.0', op='__eq__', v2='1.0.0')),
- ('s4', dict(v1='1.0', op='__eq__', v2='1.0')),
- ('s5', dict(v1='1.0', op='__lt__', v2='1.8.0')),
- ('s6', dict(v1='1.0.1alpha', op='__lt__', v2='1.0.1')),
- ('s7', dict(v1='1.0alpha', op='__lt__', v2='1.0.0')),
- ('s8', dict(v1='1.0-alpha', op='__lt__', v2='1.0.0')),
- ('s9', dict(v1='1.1-alpha', op='__gt__', v2='1.0')),
- ('s10', dict(v1='1.0-SNAPSHOT', op='__lt__', v2='1.0')),
- ('s11', dict(v1='1.0.preview', op='__lt__', v2='1.0')),
- ('s12', dict(v1='1.1-SNAPSHOT', op='__gt__', v2='1.0')),
- ('s13', dict(v1='1.0a-SNAPSHOT', op='__lt__', v2='1.0a')),
- ('s14', dict(v1='1.4.6-SNAPSHOT (private-0986edd9-example)',
- op='__lt__', v2='1.4.6')),
- ('s15', dict(v1='1.4.6-SNAPSHOT (private-0986edd9-example)',
- op='__gt__', v2='1.4.5')),
+ ("s1", dict(v1="1.0.0", op="__gt__", v2="0.8.0")),
+ ("s2", dict(v1="1.0.1alpha", op="__gt__", v2="1.0.0")),
+ ("s3", dict(v1="1.0", op="__eq__", v2="1.0.0")),
+ ("s4", dict(v1="1.0", op="__eq__", v2="1.0")),
+ ("s5", dict(v1="1.0", op="__lt__", v2="1.8.0")),
+ ("s6", dict(v1="1.0.1alpha", op="__lt__", v2="1.0.1")),
+ ("s7", dict(v1="1.0alpha", op="__lt__", v2="1.0.0")),
+ ("s8", dict(v1="1.0-alpha", op="__lt__", v2="1.0.0")),
+ ("s9", dict(v1="1.1-alpha", op="__gt__", v2="1.0")),
+ ("s10", dict(v1="1.0-SNAPSHOT", op="__lt__", v2="1.0")),
+ ("s11", dict(v1="1.0.preview", op="__lt__", v2="1.0")),
+ ("s12", dict(v1="1.1-SNAPSHOT", op="__gt__", v2="1.0")),
+ ("s13", dict(v1="1.0a-SNAPSHOT", op="__lt__", v2="1.0a")),
+ (
+ "s14",
+ dict(
+ v1="1.4.6-SNAPSHOT (private-0986edd9-example)", op="__lt__", v2="1.4.6"
+ ),
+ ),
+ (
+ "s15",
+ dict(
+ v1="1.4.6-SNAPSHOT (private-0986edd9-example)", op="__gt__", v2="1.4.5"
+ ),
+ ),
]
def setUp(self):
@@ -36,13 +45,16 @@ class ModuleRegistryPluginInfoTestsWithScenarios(
jjb_config = JJBConfig()
jjb_config.validate()
- plugin_info = [{'shortName': "HerpDerpPlugin",
- 'longName': "Blah Blah Blah Plugin"
- }]
- plugin_info.append({'shortName': "JankyPlugin1",
- 'longName': "Not A Real Plugin",
- 'version': self.v1
- })
+ plugin_info = [
+ {"shortName": "HerpDerpPlugin", "longName": "Blah Blah Blah Plugin"}
+ ]
+ plugin_info.append(
+ {
+ "shortName": "JankyPlugin1",
+ "longName": "Not A Real Plugin",
+ "version": self.v1,
+ }
+ )
self.addDetail("plugin_info", text_content(str(plugin_info)))
self.registry = ModuleRegistry(jjb_config, plugin_info)
@@ -61,7 +73,7 @@ class ModuleRegistryPluginInfoTestsWithScenarios(
plugin_info = self.registry.get_plugin_info(plugin_name)
self.assertIsInstance(plugin_info, dict)
- self.assertEqual(plugin_info['shortName'], plugin_name)
+ self.assertEqual(plugin_info["shortName"], plugin_name)
def test_get_plugin_info_dict_using_longName(self):
"""
@@ -74,7 +86,7 @@ class ModuleRegistryPluginInfoTestsWithScenarios(
plugin_info = self.registry.get_plugin_info(plugin_name)
self.assertIsInstance(plugin_info, dict)
- self.assertEqual(plugin_info['longName'], plugin_name)
+ self.assertEqual(plugin_info["longName"], plugin_name)
def test_get_plugin_info_dict_no_plugin(self):
"""
@@ -101,8 +113,8 @@ class ModuleRegistryPluginInfoTestsWithScenarios(
plugin_info = self.registry.get_plugin_info(plugin_name)
self.assertIsInstance(plugin_info, dict)
- self.assertEqual(plugin_info['shortName'], plugin_name)
- self.assertEqual(plugin_info['version'], '0')
+ self.assertEqual(plugin_info["shortName"], plugin_name)
+ self.assertEqual(plugin_info["version"], "0")
def test_plugin_version_comparison(self):
"""
@@ -117,7 +129,8 @@ class ModuleRegistryPluginInfoTestsWithScenarios(
op = getattr(pkg_resources.parse_version(v1), self.op)
test = op(pkg_resources.parse_version(self.v2))
- self.assertTrue(test,
- msg="Unexpectedly found {0} {2} {1} == False "
- "when comparing versions!"
- .format(v1, self.v2, self.op))
+ self.assertTrue(
+ test,
+ msg="Unexpectedly found {0} {2} {1} == False "
+ "when comparing versions!".format(v1, self.v2, self.op),
+ )
diff --git a/tests/modules/test_helpers.py b/tests/modules/test_helpers.py
index cdfc4d74..f0cebb41 100644
--- a/tests/modules/test_helpers.py
+++ b/tests/modules/test_helpers.py
@@ -24,86 +24,91 @@ from tests import base
class TestCaseTestHelpers(base.BaseTestCase):
-
def test_convert_mapping_to_xml(self):
"""
Tests the test_convert_mapping_to_xml_fail_required function
"""
# Test default values
- default_root = XML.Element('testdefault')
+ default_root = XML.Element("testdefault")
default_data = yaml.load("string: hello")
- default_mappings = [('default-string', 'defaultString', 'default')]
+ default_mappings = [("default-string", "defaultString", "default")]
convert_mapping_to_xml(
- default_root,
- default_data,
- default_mappings,
- fail_required=True)
- result = default_root.find('defaultString').text
- self.assertThat(result, Equals('default'))
+ default_root, default_data, default_mappings, fail_required=True
+ )
+ result = default_root.find("defaultString").text
+ self.assertThat(result, Equals("default"))
# Test user input
- user_input_root = XML.Element('testUserInput')
+ user_input_root = XML.Element("testUserInput")
user_input_data = yaml.load("user-input-string: hello")
- user_input_mappings = [('user-input-string', 'userInputString',
- 'user-input')]
+ user_input_mappings = [("user-input-string", "userInputString", "user-input")]
convert_mapping_to_xml(
- user_input_root,
- user_input_data,
- user_input_mappings,
- fail_required=True)
- result = user_input_root.find('userInputString').text
- self.assertThat(result, Equals('hello'))
+ user_input_root, user_input_data, user_input_mappings, fail_required=True
+ )
+ result = user_input_root.find("userInputString").text
+ self.assertThat(result, Equals("hello"))
# Test missing required input
- required_root = XML.Element('testrequired')
+ required_root = XML.Element("testrequired")
required_data = yaml.load("string: hello")
- required_mappings = [('required-string', 'requiredString', None)]
+ required_mappings = [("required-string", "requiredString", None)]
- self.assertRaises(MissingAttributeError,
- convert_mapping_to_xml,
- required_root,
- required_data,
- required_mappings,
- fail_required=True)
+ self.assertRaises(
+ MissingAttributeError,
+ convert_mapping_to_xml,
+ required_root,
+ required_data,
+ required_mappings,
+ fail_required=True,
+ )
# Test invalid user input for list
- user_input_root = XML.Element('testUserInput')
+ user_input_root = XML.Element("testUserInput")
user_input_data = yaml.load("user-input-string: bye")
- valid_inputs = ['hello']
- user_input_mappings = [('user-input-string', 'userInputString',
- 'user-input', valid_inputs)]
-
- self.assertRaises(InvalidAttributeError,
- convert_mapping_to_xml,
- user_input_root,
- user_input_data,
- user_input_mappings)
+ valid_inputs = ["hello"]
+ user_input_mappings = [
+ ("user-input-string", "userInputString", "user-input", valid_inputs)
+ ]
+
+ self.assertRaises(
+ InvalidAttributeError,
+ convert_mapping_to_xml,
+ user_input_root,
+ user_input_data,
+ user_input_mappings,
+ )
# Test invalid user input for dict
- user_input_root = XML.Element('testUserInput')
+ user_input_root = XML.Element("testUserInput")
user_input_data = yaml.load("user-input-string: later")
- valid_inputs = {'hello': 'world'}
- user_input_mappings = [('user-input-string', 'userInputString',
- 'user-input', valid_inputs)]
-
- self.assertRaises(InvalidAttributeError,
- convert_mapping_to_xml,
- user_input_root,
- user_input_data,
- user_input_mappings)
+ valid_inputs = {"hello": "world"}
+ user_input_mappings = [
+ ("user-input-string", "userInputString", "user-input", valid_inputs)
+ ]
+
+ self.assertRaises(
+ InvalidAttributeError,
+ convert_mapping_to_xml,
+ user_input_root,
+ user_input_data,
+ user_input_mappings,
+ )
# Test invalid key for dict
- user_input_root = XML.Element('testUserInput')
+ user_input_root = XML.Element("testUserInput")
user_input_data = yaml.load("user-input-string: world")
- valid_inputs = {'hello': 'world'}
- user_input_mappings = [('user-input-string', 'userInputString',
- 'user-input', valid_inputs)]
-
- self.assertRaises(InvalidAttributeError,
- convert_mapping_to_xml,
- user_input_root,
- user_input_data,
- user_input_mappings)
+ valid_inputs = {"hello": "world"}
+ user_input_mappings = [
+ ("user-input-string", "userInputString", "user-input", valid_inputs)
+ ]
+
+ self.assertRaises(
+ InvalidAttributeError,
+ convert_mapping_to_xml,
+ user_input_root,
+ user_input_data,
+ user_input_mappings,
+ )
diff --git a/tests/multibranch/test_multibranch.py b/tests/multibranch/test_multibranch.py
index 6a1cca0b..84ecb012 100644
--- a/tests/multibranch/test_multibranch.py
+++ b/tests/multibranch/test_multibranch.py
@@ -19,9 +19,9 @@ import os
from jenkins_jobs.modules import project_multibranch
-@mock.patch('uuid.uuid4', mock.Mock(return_value='1-1-1-1-1'))
+@mock.patch("uuid.uuid4", mock.Mock(return_value="1-1-1-1-1"))
class TestCaseMultibranchPipeline(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
- default_config_file = '/dev/null'
+ default_config_file = "/dev/null"
klass = project_multibranch.WorkflowMultiBranch
diff --git a/tests/notifications/test_notifications.py b/tests/notifications/test_notifications.py
index e68a269d..e1935efa 100644
--- a/tests/notifications/test_notifications.py
+++ b/tests/notifications/test_notifications.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleNotifications(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = notifications.Notifications
diff --git a/tests/parallel/test_parallel.py b/tests/parallel/test_parallel.py
index a3b68092..b7ccd20b 100644
--- a/tests/parallel/test_parallel.py
+++ b/tests/parallel/test_parallel.py
@@ -30,19 +30,18 @@ class TestCaseParallel(TestCase):
def parallel_test(num_base, num_extra):
return num_base + num_extra
- parallel_args = [{'num_extra': num} for num in range(10)]
+ parallel_args = [{"num_extra": num} for num in range(10)]
result = parallel_test(10, concurrent=parallel_args)
self.assertThat(result, matchers.Equals(expected))
def test_parallel_time_less_than_serial(self):
-
@concurrent
def wait(secs):
time.sleep(secs)
before = time.time()
# ten threads to make it as fast as possible
- wait(concurrent=[{'secs': 1} for _ in range(10)], n_workers=10)
+ wait(concurrent=[{"secs": 1} for _ in range(10)], n_workers=10)
after = time.time()
self.assertThat(after - before, matchers.LessThan(5))
@@ -53,18 +52,16 @@ class TestCaseParallel(TestCase):
def parallel_test(num_base, num_extra):
return num_base + num_extra
- parallel_args = [{'num_extra': num} for num in range(10)]
+ parallel_args = [{"num_extra": num} for num in range(10)]
result = parallel_test(10, concurrent=parallel_args, n_workers=1)
self.assertThat(result, matchers.Equals(expected))
- @mock.patch('jenkins_jobs.parallel.cpu_count', wraps=cpu_count)
+ @mock.patch("jenkins_jobs.parallel.cpu_count", wraps=cpu_count)
def test_use_auto_detect_cores(self, mockCpu_count):
-
@concurrent
def parallel_test():
return True
- result = parallel_test(concurrent=[{} for _ in range(10)],
- n_workers=0)
+ result = parallel_test(concurrent=[{} for _ in range(10)], n_workers=0)
self.assertThat(result, matchers.Equals([True for _ in range(10)]))
mockCpu_count.assert_called_once_with()
diff --git a/tests/parameters/test_parameters.py b/tests/parameters/test_parameters.py
index ab637ca2..fad81a00 100644
--- a/tests/parameters/test_parameters.py
+++ b/tests/parameters/test_parameters.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleParameters(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = parameters.Parameters
diff --git a/tests/properties/test_properties.py b/tests/properties/test_properties.py
index f527d8dc..5c722a2b 100644
--- a/tests/properties/test_properties.py
+++ b/tests/properties/test_properties.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleProperties(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = properties.Properties
diff --git a/tests/publishers/test_publishers.py b/tests/publishers/test_publishers.py
index e44a4dba..16d2295e 100644
--- a/tests/publishers/test_publishers.py
+++ b/tests/publishers/test_publishers.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModulePublishers(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = publishers.Publishers
diff --git a/tests/reporters/test_reporters.py b/tests/reporters/test_reporters.py
index 920c463f..5b419e80 100644
--- a/tests/reporters/test_reporters.py
+++ b/tests/reporters/test_reporters.py
@@ -21,6 +21,6 @@ from tests import base
class TestCaseModuleReporters(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = reporters.Reporters
diff --git a/tests/scm/test_scm.py b/tests/scm/test_scm.py
index a4fa998d..62ee8762 100644
--- a/tests/scm/test_scm.py
+++ b/tests/scm/test_scm.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleSCM(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = scm.SCM
diff --git a/tests/triggers/test_triggers.py b/tests/triggers/test_triggers.py
index 04b7c8cd..9f0ae5f4 100644
--- a/tests/triggers/test_triggers.py
+++ b/tests/triggers/test_triggers.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleTriggers(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = triggers.Triggers
diff --git a/tests/views/test_views.py b/tests/views/test_views.py
index 4ce73330..700b174d 100644
--- a/tests/views/test_views.py
+++ b/tests/views/test_views.py
@@ -20,18 +20,18 @@ from tests import base
class TestCaseModuleViewAll(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = view_all.All
class TestCaseModuleViewList(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = view_list.List
class TestCaseModuleViewPipeline(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = view_pipeline.Pipeline
diff --git a/tests/wrappers/test_wrappers.py b/tests/wrappers/test_wrappers.py
index 717a9955..f84d040f 100644
--- a/tests/wrappers/test_wrappers.py
+++ b/tests/wrappers/test_wrappers.py
@@ -22,6 +22,6 @@ from tests import base
class TestCaseModuleWrappers(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
klass = wrappers.Wrappers
diff --git a/tests/xml_config/test_xml_config.py b/tests/xml_config/test_xml_config.py
index 76858db2..6f8fd0b7 100644
--- a/tests/xml_config/test_xml_config.py
+++ b/tests/xml_config/test_xml_config.py
@@ -23,23 +23,23 @@ from tests import base
class TestXmlJobGeneratorExceptions(base.BaseTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'exceptions')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "exceptions")
def test_invalid_project(self):
self.conf_filename = None
config = self._get_config()
yp = parser.YamlParser(config)
- yp.parse(os.path.join(self.fixtures_path,
- "invalid_project.yaml"))
+ yp.parse(os.path.join(self.fixtures_path, "invalid_project.yaml"))
reg = registry.ModuleRegistry(config)
job_data, _ = yp.expandYaml(reg)
# Generate the XML tree
xml_generator = xml_config.XmlJobGenerator(reg)
- e = self.assertRaises(errors.JenkinsJobsException,
- xml_generator.generateXML, job_data)
+ e = self.assertRaises(
+ errors.JenkinsJobsException, xml_generator.generateXML, job_data
+ )
self.assertIn("Unrecognized project-type:", str(e))
def test_invalid_view(self):
@@ -54,8 +54,9 @@ class TestXmlJobGeneratorExceptions(base.BaseTestCase):
# Generate the XML tree
xml_generator = xml_config.XmlViewGenerator(reg)
- e = self.assertRaises(errors.JenkinsJobsException,
- xml_generator.generateXML, view_data)
+ e = self.assertRaises(
+ errors.JenkinsJobsException, xml_generator.generateXML, view_data
+ )
self.assertIn("Unrecognized view-type:", str(e))
def test_incorrect_template_params(self):
@@ -63,8 +64,7 @@ class TestXmlJobGeneratorExceptions(base.BaseTestCase):
config = self._get_config()
yp = parser.YamlParser(config)
- yp.parse(os.path.join(self.fixtures_path,
- "failure_formatting_component.yaml"))
+ yp.parse(os.path.join(self.fixtures_path, "failure_formatting_component.yaml"))
reg = registry.ModuleRegistry(config)
reg.set_parser_data(yp.data)
diff --git a/tests/yamlparser/test_yamlparser.py b/tests/yamlparser/test_yamlparser.py
index cfc0c690..32030835 100644
--- a/tests/yamlparser/test_yamlparser.py
+++ b/tests/yamlparser/test_yamlparser.py
@@ -24,20 +24,19 @@ from tests import base
class TestCaseModuleYamlInclude(base.SingleJobTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
scenarios = base.get_scenarios(fixtures_path)
class TestYamlParserExceptions(base.BaseTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'exceptions')
+ fixtures_path = os.path.join(os.path.dirname(__file__), "exceptions")
def test_incorrect_template_dimensions(self):
self.conf_filename = None
config = self._get_config()
yp = parser.YamlParser(config)
- yp.parse(os.path.join(self.fixtures_path,
- "incorrect_template_dimensions.yaml"))
+ yp.parse(os.path.join(self.fixtures_path, "incorrect_template_dimensions.yaml"))
reg = registry.ModuleRegistry(config)
@@ -47,23 +46,22 @@ class TestYamlParserExceptions(base.BaseTestCase):
class TestYamlParserFailureFormattingExceptions(base.BaseScenariosTestCase):
- fixtures_path = os.path.join(os.path.dirname(__file__), 'exceptions')
- scenarios = [
- ('s1', {'name': 'template'}),
- ('s2', {'name': 'params'})
- ]
+ fixtures_path = os.path.join(os.path.dirname(__file__), "exceptions")
+ scenarios = [("s1", {"name": "template"}), ("s2", {"name": "params"})]
def test_yaml_snippet(self):
self.conf_filename = None
config = self._get_config()
yp = parser.YamlParser(config)
- yp.parse(os.path.join(self.fixtures_path,
- "failure_formatting_{}.yaml".format(self.name)))
+ yp.parse(
+ os.path.join(
+ self.fixtures_path, "failure_formatting_{}.yaml".format(self.name)
+ )
+ )
reg = registry.ModuleRegistry(config)
self.assertRaises(Exception, yp.expandYaml, reg)
- self.assertIn("Failure formatting {}".format(self.name),
- self.logger.output)
+ self.assertIn("Failure formatting {}".format(self.name), self.logger.output)
self.assertIn("Problem formatting with args", self.logger.output)