From ae1fb60f16fe4910d1c1e480368aa756eff4befa Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Sat, 2 Jan 2016 18:52:48 -0800 Subject: [PATCH] Disentangle YamlParser and ModuleRegistry classes Create the ModuleRegistry anywhere other than inside the YamlParser class. This will make it slightly easier to factor a XmlGenerator out of YamlParser, but I also want to work toward eliminating the circular references between YamlParser and ModuleRegistry which have been making it difficult to understand overall program flow. This commit also replaces all YamlParser instances being passed to Jenkins job config generating functions with a ModuleRegistry. Mostly it seems like the parser was only needed to call the ModuleRegistry's 'dispatch' method which to be honest I don't fully understand. This is where the circular references mentioned in previously come in...it seems like the "dispatch" function needs access to the (mostly) raw data contained by the parser, so it took that as a parameter. The need for the YamlParser's job data can be satisfied by assigning it to a property on the ModuleRegistry object before Yaml expansion or XML generation begins; by doing this, we allow the ModuleRegistry to avoid referencing the parser. Change-Id: I4b571299b81e708540392ad963163fe092acf1d9 --- jenkins_jobs/cli/subcommand/delete.py | 8 +- jenkins_jobs/cli/subcommand/update.py | 11 +- jenkins_jobs/modules/base.py | 2 +- jenkins_jobs/modules/builders.py | 123 ++++++------ jenkins_jobs/modules/general.py | 6 +- jenkins_jobs/modules/helpers.py | 3 +- jenkins_jobs/modules/hipchat_notif.py | 5 +- jenkins_jobs/modules/metadata.py | 19 +- jenkins_jobs/modules/notifications.py | 6 +- jenkins_jobs/modules/parameters.py | 93 ++++----- jenkins_jobs/modules/properties.py | 50 ++--- jenkins_jobs/modules/publishers.py | 265 +++++++++++++------------- jenkins_jobs/modules/reporters.py | 8 +- jenkins_jobs/modules/scm.py | 24 +-- jenkins_jobs/modules/triggers.py | 40 ++-- jenkins_jobs/modules/wrappers.py | 113 ++++++----- jenkins_jobs/parser.py | 26 ++- jenkins_jobs/registry.py | 17 +- tests/base.py | 25 ++- tests/cmd/subcommands/test_test.py | 4 +- 20 files changed, 427 insertions(+), 421 deletions(-) diff --git a/jenkins_jobs/cli/subcommand/delete.py b/jenkins_jobs/cli/subcommand/delete.py index 6aa953ced..a236c058c 100644 --- a/jenkins_jobs/cli/subcommand/delete.py +++ b/jenkins_jobs/cli/subcommand/delete.py @@ -16,6 +16,7 @@ from jenkins_jobs.builder import Builder from jenkins_jobs.parser import YamlParser +from jenkins_jobs.registry import ModuleRegistry import jenkins_jobs.cli.subcommand.base as base @@ -39,16 +40,15 @@ class DeleteSubCommand(base.BaseSubCommand): def execute(self, options, jjb_config): builder = Builder(jjb_config) - parser = YamlParser(jjb_config, builder.plugins_list) - fn = options.path + registry = ModuleRegistry(jjb_config, builder.plugins_list) for jobs_glob in options.name: - parser = YamlParser(jjb_config, builder.plugins_list) + parser = YamlParser(jjb_config) if fn: parser.load_files(fn) - parser.expandYaml([jobs_glob]) + parser.expandYaml(registry, [jobs_glob]) jobs = [j['name'] for j in parser.jobs] else: jobs = [jobs_glob] diff --git a/jenkins_jobs/cli/subcommand/update.py b/jenkins_jobs/cli/subcommand/update.py index be7dd8eac..6ac1115a7 100644 --- a/jenkins_jobs/cli/subcommand/update.py +++ b/jenkins_jobs/cli/subcommand/update.py @@ -19,6 +19,7 @@ import time from jenkins_jobs.builder import Builder from jenkins_jobs.parser import YamlParser +from jenkins_jobs.registry import ModuleRegistry from jenkins_jobs.errors import JenkinsJobsException import jenkins_jobs.cli.subcommand.base as base @@ -71,10 +72,14 @@ class UpdateSubCommand(base.BaseSubCommand): orig = time.time() # Generate XML - parser = YamlParser(jjb_config, builder.plugins_list) + parser = YamlParser(jjb_config) + registry = ModuleRegistry(jjb_config, builder.plugins_list) + parser.load_files(options.path) - parser.expandYaml(options.names) - parser.generateXML() + registry.set_parser_data(parser.data) + + parser.expandYaml(registry, options.names) + parser.generateXML(registry) jobs = parser.jobs step = time.time() diff --git a/jenkins_jobs/modules/base.py b/jenkins_jobs/modules/base.py index 9a0702379..690777506 100644 --- a/jenkins_jobs/modules/base.py +++ b/jenkins_jobs/modules/base.py @@ -72,7 +72,7 @@ class Base(object): return False - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): """Update the XML element tree based on YAML data. Override this method to add elements to the XML output. Create new Element objects and add them to the xml_parent. The YAML data diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index d7a1fffb9..4564f9fc3 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -58,7 +58,7 @@ from jenkins_jobs.modules.publishers import ssh logger = logging.getLogger(__name__) -def shell(parser, xml_parent, data): +def shell(registry, xml_parent, data): """yaml: shell Execute a shell command. @@ -74,7 +74,7 @@ def shell(parser, xml_parent, data): XML.SubElement(shell, 'command').text = data -def python(parser, xml_parent, data): +def python(registry, xml_parent, data): """yaml: python Execute a python command. Requires the Jenkins :jenkins-wiki:`Python plugin `. @@ -91,7 +91,7 @@ def python(parser, xml_parent, data): XML.SubElement(python, 'command').text = data -def copyartifact(parser, xml_parent, data): +def copyartifact(registry, xml_parent, data): """yaml: copyartifact Copy artifact from another project. Requires the :jenkins-wiki:`Copy @@ -179,7 +179,7 @@ def copyartifact(parser, xml_parent, data): copyartifact_build_selector(t, data) -def change_assembly_version(parser, xml_parent, data): +def change_assembly_version(registry, xml_parent, data): """yaml: change-assembly-version Change the assembly version. Requires the Jenkins :jenkins-wiki:`Change Assembly Version @@ -203,7 +203,7 @@ def change_assembly_version(parser, xml_parent, data): data.get('assembly-file', 'AssemblyInfo.cs')) -def fingerprint(parser, xml_parent, data): +def fingerprint(registry, xml_parent, data): """yaml: fingerprint Adds the ability to generate fingerprints as build steps instead of waiting for a build to complete. Requires the Jenkins :jenkins-wiki:`Fingerprint @@ -232,7 +232,7 @@ def fingerprint(parser, xml_parent, data): convert_mapping_to_xml(fingerprint, data, mapping, fail_required=True) -def ant(parser, xml_parent, data): +def ant(registry, xml_parent, data): """yaml: ant Execute an ant target. Requires the Jenkins :jenkins-wiki:`Ant Plugin `. @@ -299,7 +299,7 @@ def ant(parser, xml_parent, data): XML.SubElement(ant, 'antName').text = data.get('ant-name', 'default') -def trigger_remote(parser, xml_parent, data): +def trigger_remote(registry, xml_parent, data): """yaml: trigger-remote Trigger build of job on remote Jenkins instance. @@ -391,7 +391,7 @@ def trigger_remote(parser, xml_parent, data): XML.SubElement(triggerr, 'overrideAuth').text = "false" -def trigger_builds(parser, xml_parent, data): +def trigger_builds(registry, xml_parent, data): """yaml: trigger-builds Trigger builds of other jobs. Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin @@ -730,7 +730,7 @@ def trigger_builds(parser, xml_parent, data): xml_parent.remove(tbuilder) -def builders_from(parser, xml_parent, data): +def builders_from(registry, xml_parent, data): """yaml: builders-from Use builders from another project. Requires the Jenkins :jenkins-wiki:`Template Project Plugin @@ -748,7 +748,7 @@ def builders_from(parser, xml_parent, data): XML.SubElement(pbs, 'projectName').text = data -def http_request(parser, xml_parent, data): +def http_request(registry, xml_parent, data): """yaml: http-request This plugin sends a http request to an url with some parameters. Requires the Jenkins :jenkins-wiki:`HTTP Request Plugin @@ -851,7 +851,7 @@ def http_request(parser, xml_parent, data): fail_required=True) -def inject(parser, xml_parent, data): +def inject(registry, xml_parent, data): """yaml: inject Inject an environment for the job. Requires the Jenkins :jenkins-wiki:`EnvInject Plugin @@ -879,7 +879,7 @@ def inject(parser, xml_parent, data): info, 'scriptContent', data.get('script-content')) -def kmap(parser, xml_parent, data): +def kmap(registry, xml_parent, data): """yaml: kmap Publish mobile applications to your Keivox KMAP Private Mobile App Store. Requires the Jenkins :jenkins-wiki:`Keivox KMAP Private Mobile App Store @@ -952,7 +952,7 @@ def kmap(parser, xml_parent, data): publish_optional, data, publish_mapping, fail_required=True) -def artifact_resolver(parser, xml_parent, data): +def artifact_resolver(registry, xml_parent, data): """yaml: artifact-resolver Allows one to resolve artifacts from a maven repository like nexus (without having maven installed) @@ -1008,7 +1008,7 @@ def artifact_resolver(parser, xml_parent, data): XML.SubElement(ar, 'releaseChecksumPolicy').text = 'warn' -def doxygen(parser, xml_parent, data): +def doxygen(registry, xml_parent, data): """yaml: doxygen Builds doxygen HTML documentation. Requires the Jenkins :jenkins-wiki:`Doxygen plugin `. @@ -1037,7 +1037,7 @@ def doxygen(parser, xml_parent, data): convert_mapping_to_xml(doxygen, data, mappings, fail_required=True) -def gradle(parser, xml_parent, data): +def gradle(registry, xml_parent, data): """yaml: gradle Execute gradle tasks. Requires the Jenkins :jenkins-wiki:`Gradle Plugin `. @@ -1100,7 +1100,7 @@ def _groovy_common_scriptSource(data): return scriptSource -def groovy(parser, xml_parent, data): +def groovy(registry, xml_parent, data): """yaml: groovy Execute a groovy script or command. Requires the Jenkins :jenkins-wiki:`Groovy Plugin `. @@ -1144,7 +1144,7 @@ def groovy(parser, xml_parent, data): XML.SubElement(groovy, 'classPath').text = str(data.get('class-path', "")) -def system_groovy(parser, xml_parent, data): +def system_groovy(registry, xml_parent, data): """yaml: system-groovy Execute a system groovy script or command. Requires the Jenkins :jenkins-wiki:`Groovy Plugin `. @@ -1175,7 +1175,7 @@ def system_groovy(parser, xml_parent, data): data.get('class-path', "")) -def batch(parser, xml_parent, data): +def batch(registry, xml_parent, data): """yaml: batch Execute a batch command. @@ -1190,7 +1190,7 @@ def batch(parser, xml_parent, data): XML.SubElement(batch, 'command').text = data -def powershell(parser, xml_parent, data): +def powershell(registry, xml_parent, data): """yaml: powershell Execute a powershell command. Requires the :jenkins-wiki:`Powershell Plugin `. @@ -1206,7 +1206,7 @@ def powershell(parser, xml_parent, data): XML.SubElement(ps, 'command').text = data -def msbuild(parser, xml_parent, data): +def msbuild(registry, xml_parent, data): """yaml: msbuild Build .NET project using msbuild. Requires the :jenkins-wiki:`Jenkins MSBuild Plugin `. @@ -1247,13 +1247,13 @@ def msbuild(parser, xml_parent, data): convert_mapping_to_xml(msbuilder, data, mapping, fail_required=True) -def create_builders(parser, step): +def create_builders(registry, step): dummy_parent = XML.Element("dummy") - parser.registry.dispatch('builder', parser, dummy_parent, step) + registry.dispatch('builder', dummy_parent, step) return list(dummy_parent) -def conditional_step(parser, xml_parent, data): +def conditional_step(registry, xml_parent, data): """yaml: conditional-step Conditionally execute some build steps. Requires the Jenkins :jenkins-wiki:`Conditional BuildStep Plugin @@ -1658,7 +1658,7 @@ def conditional_step(parser, xml_parent, data): build_condition(condition, conditions_container_tag) def build_step(parent, step): - for edited_node in create_builders(parser, 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' @@ -1698,7 +1698,7 @@ def conditional_step(parser, xml_parent, data): build_step(steps_parent, step) -def maven_builder(parser, xml_parent, data): +def maven_builder(registry, xml_parent, data): """yaml: maven-builder Execute Maven3 builder @@ -1728,7 +1728,7 @@ def maven_builder(parser, xml_parent, data): convert_mapping_to_xml(maven, data, mapping, fail_required=True) -def maven_target(parser, xml_parent, data): +def maven_target(registry, xml_parent, data): """yaml: maven-target Execute top-level Maven targets. @@ -1781,7 +1781,7 @@ def maven_target(parser, xml_parent, data): config_file_provider_settings(maven, data) -def multijob(parser, xml_parent, data): +def multijob(registry, xml_parent, data): """yaml: multijob Define a multijob phase. Requires the Jenkins :jenkins-wiki:`Multijob Plugin `. @@ -1961,7 +1961,7 @@ def multijob(parser, xml_parent, data): ).text = kill_status -def config_file_provider(parser, xml_parent, data): +def config_file_provider(registry, xml_parent, data): """yaml: config-file-provider Provide configuration files (i.e., settings.xml for maven etc.) which will be copied to the job's workspace. @@ -1992,7 +1992,7 @@ def config_file_provider(parser, xml_parent, data): config_file_provider_builder(cfp, data) -def grails(parser, xml_parent, data): +def grails(registry, xml_parent, data): """yaml: grails Execute a grails build step. Requires the :jenkins-wiki:`Jenkins Grails Plugin `. @@ -2058,7 +2058,7 @@ def grails(parser, xml_parent, data): data.get('refresh-dependencies', False)).lower() -def sbt(parser, xml_parent, data): +def sbt(registry, xml_parent, data): """yaml: sbt Execute a sbt build step. Requires the Jenkins :jenkins-wiki:`Sbt Plugin `. @@ -2092,7 +2092,7 @@ def sbt(parser, xml_parent, data): 'subdir-path', '') -def critical_block_start(parser, xml_parent, data): +def critical_block_start(registry, xml_parent, data): """yaml: critical-block-start Designate the start of a critical block. Must be used in conjuction with critical-block-end. @@ -2113,7 +2113,7 @@ def critical_block_start(parser, xml_parent, data): cbs.set('plugin', 'Exclusion') -def critical_block_end(parser, xml_parent, data): +def critical_block_end(registry, xml_parent, data): """yaml: critical-block-end Designate the end of a critical block. Must be used in conjuction with critical-block-start. @@ -2134,7 +2134,7 @@ def critical_block_end(parser, xml_parent, data): cbs.set('plugin', 'Exclusion') -def publish_over_ssh(parser, xml_parent, data): +def publish_over_ssh(registry, xml_parent, data): """yaml: publish-over-ssh Send files or execute commands over SSH. Requires the Jenkins :jenkins-wiki:`Publish over SSH Plugin @@ -2160,7 +2160,7 @@ def publish_over_ssh(parser, xml_parent, data): .. literalinclude:: /../../tests/builders/fixtures/publish-over-ssh.yaml :language: yaml """ - ssh(parser, xml_parent, data) + ssh(registry, xml_parent, data) class Builders(jenkins_jobs.modules.base.Base): @@ -2169,14 +2169,13 @@ class Builders(jenkins_jobs.modules.base.Base): component_type = 'builder' component_list_type = 'builders' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): 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', parser, builders, - builder) + self.registry.dispatch('builder', builders, builder) # Make sure freestyle projects always have a entry # or Jenkins v1.472 (at least) will NPE. @@ -2185,7 +2184,7 @@ class Builders(jenkins_jobs.modules.base.Base): XML.SubElement(xml_parent, 'builders') -def shining_panda(parser, xml_parent, data): +def shining_panda(registry, xml_parent, data): """yaml: shining-panda Execute a command inside various python environments. Requires the Jenkins :jenkins-wiki:`ShiningPanda plugin `. @@ -2302,7 +2301,7 @@ def shining_panda(parser, xml_parent, data): XML.SubElement(t, 'ignoreExitCode').text = str(ignore_exit_code).lower() -def tox(parser, xml_parent, data): +def tox(registry, xml_parent, data): """yaml: tox Use tox to build a multi-configuration project. Requires the Jenkins :jenkins-wiki:`ShiningPanda plugin `. @@ -2328,7 +2327,7 @@ def tox(parser, xml_parent, data): XML.SubElement(t, 'toxenvPattern').text = pattern -def managed_script(parser, xml_parent, data): +def managed_script(registry, xml_parent, data): """yaml: managed-script This step allows to reference and execute a centrally managed script within your build. Requires the Jenkins @@ -2372,7 +2371,7 @@ def managed_script(parser, xml_parent, data): XML.SubElement(args, 'string').text = arg -def cmake(parser, xml_parent, data): +def cmake(registry, xml_parent, data): """yaml: cmake Execute a CMake target. Requires the Jenkins :jenkins-wiki:`CMake Plugin `. @@ -2497,7 +2496,7 @@ def cmake(parser, xml_parent, data): XML.SubElement(cmake, 'cleanBuild').text = str( data.get('clean-build-dir', False)).lower() - plugin_info = parser.registry.get_plugin_info("CMake plugin") + plugin_info = registry.get_plugin_info("CMake plugin") version = pkg_resources.parse_version(plugin_info.get("version", "1.0")) # Version 2.x breaks compatibility. So parse the input data differently @@ -2580,7 +2579,7 @@ def cmake(parser, xml_parent, data): XML.SubElement(cmake, 'builderImpl') -def dsl(parser, xml_parent, data): +def dsl(registry, xml_parent, data): """yaml: dsl Process Job DSL @@ -2670,7 +2669,7 @@ def dsl(parser, xml_parent, data): 'additional-classpath') -def github_notifier(parser, xml_parent, data): +def github_notifier(registry, xml_parent, data): """yaml: github-notifier Set pending build status on Github commit. Requires the Jenkins :jenkins-wiki:`Github Plugin `. @@ -2684,7 +2683,7 @@ def github_notifier(parser, xml_parent, data): 'com.cloudbees.jenkins.GitHubSetCommitStatusBuilder') -def scan_build(parser, xml_parent, data): +def scan_build(registry, xml_parent, data): """yaml: scan-build This plugin allows you configure a build step that will execute the Clang scan-build static analysis tool against an XCode project. @@ -2747,7 +2746,7 @@ def scan_build(parser, xml_parent, data): convert_mapping_to_xml(p, data, mappings, fail_required=True) -def ssh_builder(parser, xml_parent, data): +def ssh_builder(registry, xml_parent, data): """yaml: ssh-builder Executes command on remote host Requires the Jenkins :jenkins-wiki:`SSH plugin `. @@ -2770,7 +2769,7 @@ def ssh_builder(parser, xml_parent, data): raise MissingAttributeError("'%s'" % e.args[0]) -def sonar(parser, xml_parent, data): +def sonar(registry, xml_parent, data): """yaml: sonar Invoke standalone Sonar analysis. Requires the Jenkins `Sonar Plugin. @@ -2809,7 +2808,7 @@ def sonar(parser, xml_parent, data): XML.SubElement(sonar, 'jdk').text = data['jdk'] -def xcode(parser, xml_parent, data): +def xcode(registry, xml_parent, data): """yaml: xcode This step allows to execute an xcode build step. Requires the Jenkins :jenkins-wiki:`Xcode Plugin `. @@ -2939,7 +2938,7 @@ def xcode(parser, xml_parent, data): data.get('keychain-unlock', False)).lower() -def sonatype_clm(parser, xml_parent, data): +def sonatype_clm(registry, xml_parent, data): """yaml: sonatype-clm Requires the Jenkins :jenkins-wiki:`Sonatype CLM Plugin `. @@ -3007,7 +3006,7 @@ def sonatype_clm(parser, xml_parent, data): convert_mapping_to_xml(clm, data, mappings, fail_required=True) -def beaker(parser, xml_parent, data): +def beaker(registry, xml_parent, data): """yaml: beaker Execute a beaker build step. Requires the Jenkins :jenkins-wiki:`Beaker Builder Plugin `. @@ -3046,7 +3045,7 @@ def beaker(parser, xml_parent, data): 'download-logs', False)).lower() -def cloudformation(parser, xml_parent, data): +def cloudformation(registry, xml_parent, data): """yaml: cloudformation Create cloudformation stacks before running a build and optionally delete them at the end. Requires the Jenkins :jenkins-wiki:`AWS @@ -3089,7 +3088,7 @@ def cloudformation(parser, xml_parent, data): region_dict) -def openshift_build_verify(parser, xml_parent, data): +def openshift_build_verify(registry, xml_parent, data): """yaml: openshift-build-verify Performs the equivalent of an 'oc get builds` command invocation for the provided buildConfig key provided; once the list of builds are obtained, @@ -3138,7 +3137,7 @@ def openshift_build_verify(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_builder(parser, xml_parent, data): +def openshift_builder(registry, xml_parent, data): """yaml: openshift-builder Perform builds in OpenShift for the job. Requires the Jenkins :jenkins-wiki:`OpenShift @@ -3194,7 +3193,7 @@ def openshift_builder(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_creator(parser, xml_parent, data): +def openshift_creator(registry, xml_parent, data): """yaml: openshift-creator Performs the equivalent of an oc create command invocation; this build step takes in the provided JSON or YAML text, and if it @@ -3242,7 +3241,7 @@ def openshift_creator(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_dep_verify(parser, xml_parent, data): +def openshift_dep_verify(registry, xml_parent, data): """yaml: openshift-dep-verify Determines whether the expected set of DeploymentConfig's, ReplicationController's, and active replicas are present based on prior @@ -3293,7 +3292,7 @@ def openshift_dep_verify(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_deployer(parser, xml_parent, data): +def openshift_deployer(registry, xml_parent, data): """yaml: openshift-deployer Start a deployment in OpenShift for the job. Requires the Jenkins :jenkins-wiki:`OpenShift @@ -3339,7 +3338,7 @@ def openshift_deployer(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_img_tagger(parser, xml_parent, data): +def openshift_img_tagger(registry, xml_parent, data): """yaml: openshift-img-tagger Performs the equivalent of an oc tag command invocation in order to manipulate tags for images in OpenShift ImageStream's @@ -3390,7 +3389,7 @@ def openshift_img_tagger(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_scaler(parser, xml_parent, data): +def openshift_scaler(registry, xml_parent, data): """yaml: openshift-scaler Scale deployments in OpenShift for the job. Requires the Jenkins :jenkins-wiki:`OpenShift @@ -3437,7 +3436,7 @@ def openshift_scaler(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_svc_verify(parser, xml_parent, data): +def openshift_svc_verify(registry, xml_parent, data): """yaml: openshift-svc-verify Verify a service is up in OpenShift for the job. Requires the Jenkins :jenkins-wiki:`OpenShift @@ -3482,7 +3481,7 @@ def openshift_svc_verify(parser, xml_parent, data): convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def runscope(parser, xml_parent, data): +def runscope(registry, xml_parent, data): """yaml: runscope Execute a Runscope test. Requires the Jenkins :jenkins-wiki:`Runscope Plugin `. @@ -3513,7 +3512,7 @@ def runscope(parser, xml_parent, data): convert_mapping_to_xml(runscope, data, mapping, fail_required=True) -def description_setter(parser, xml_parent, data): +def description_setter(registry, xml_parent, data): """yaml: description-setter This plugin sets the description for each build, based upon a RegEx test of the build log file. @@ -3579,7 +3578,7 @@ def docker_build_publish(parse, xml_parent, data): convert_mapping_to_xml(db, data, mapping, fail_required=True) -def build_name_setter(parser, xml_parent, data): +def build_name_setter(registry, xml_parent, data): """yaml: build-name-setter Define Build Name Setter options which allows your build name to be updated during the build process. diff --git a/jenkins_jobs/modules/general.py b/jenkins_jobs/modules/general.py index b1268c136..62b5626a7 100644 --- a/jenkins_jobs/modules/general.py +++ b/jenkins_jobs/modules/general.py @@ -117,7 +117,7 @@ class General(jenkins_jobs.modules.base.Base): sequence = 10 logrotate_warn_issued = False - def gen_xml(self, parser, xml, data): + def gen_xml(self, xml, data): jdk = data.get('jdk', None) if jdk: XML.SubElement(xml, 'jdk').text = jdk @@ -190,10 +190,10 @@ class General(jenkins_jobs.modules.base.Base): lr_anum.text = str(logrotate.get('artifactNumToKeep', -1)) if 'raw' in data: - raw(parser, xml, data['raw']) + raw(self.registry, xml, data['raw']) -def raw(parser, xml_parent, data): +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')) diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py index 41ca8c739..21fa65c51 100644 --- a/jenkins_jobs/modules/helpers.py +++ b/jenkins_jobs/modules/helpers.py @@ -247,9 +247,8 @@ def findbugs_settings(xml_parent, data): convert_mapping_to_xml(xml_parent, data, mapping, fail_required=True) -def get_value_from_yaml_or_config_file(key, section, data, parser): +def get_value_from_yaml_or_config_file(key, section, data, jjb_config): result = data.get(key, '') - jjb_config = parser.jjb_config if result == '': result = jjb_config.get_module_config(section, key) return result diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py index 4cc88ea15..385ae6c21 100644 --- a/jenkins_jobs/modules/hipchat_notif.py +++ b/jenkins_jobs/modules/hipchat_notif.py @@ -117,7 +117,7 @@ class HipChat(jenkins_jobs.modules.base.Base): self.jenkinsUrl = jjb_config.jenkins['url'] self.sendAs = jjb_config.get_module_config('hipchat', 'send-as') - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): hipchat = data.get('hipchat') if not hipchat or not hipchat.get('enabled', True): return @@ -144,8 +144,7 @@ class HipChat(jenkins_jobs.modules.base.Base): "'hipchat' module supports the old plugin versions <1.9, " "newer versions are supported via the 'publishers' module. " "Please upgrade you job definition") - return self.registry.dispatch('publisher', parser, publishers, - data) + return self.registry.dispatch('publisher', publishers, data) else: properties = xml_parent.find('properties') if properties is None: diff --git a/jenkins_jobs/modules/metadata.py b/jenkins_jobs/modules/metadata.py index bd98d5edb..fb4c97c50 100644 --- a/jenkins_jobs/modules/metadata.py +++ b/jenkins_jobs/modules/metadata.py @@ -36,7 +36,7 @@ import xml.etree.ElementTree as XML import jenkins_jobs.modules.base -def base_metadata(parser, xml_parent, data, mtype): +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' @@ -48,7 +48,7 @@ def base_metadata(parser, xml_parent, data, mtype): return pdef -def string_metadata(parser, xml_parent, data): +def string_metadata(registry, xml_parent, data): """yaml: string A string metadata. @@ -64,13 +64,13 @@ def string_metadata(parser, xml_parent, data): value: bar expose-to-env: true """ - pdef = base_metadata(parser, xml_parent, data, + pdef = base_metadata(registry, xml_parent, data, 'metadata-string') value = data.get('value', '') XML.SubElement(pdef, 'value').text = value -def number_metadata(parser, xml_parent, data): +def number_metadata(registry, xml_parent, data): """yaml: number A number metadata. @@ -86,13 +86,13 @@ def number_metadata(parser, xml_parent, data): value: 1 expose-to-env: true """ - pdef = base_metadata(parser, xml_parent, data, + pdef = base_metadata(registry, xml_parent, data, 'metadata-number') value = data.get('value', '') XML.SubElement(pdef, 'value').text = value -def date_metadata(parser, xml_parent, data): +def date_metadata(registry, xml_parent, data): """yaml: date A date metadata @@ -110,7 +110,7 @@ def date_metadata(parser, xml_parent, data): timezone: Australia/Melbourne expose-to-env: true """ - pdef = base_metadata(parser, xml_parent, data, + pdef = base_metadata(registry, xml_parent, data, 'metadata-date') # TODO: convert time from any reasonable format into epoch mval = XML.SubElement(pdef, 'value') @@ -125,7 +125,7 @@ class Metadata(jenkins_jobs.modules.base.Base): component_type = 'metadata' component_list_type = 'metadata' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): properties = xml_parent.find('properties') if properties is None: properties = XML.SubElement(xml_parent, 'properties') @@ -136,5 +136,4 @@ class Metadata(jenkins_jobs.modules.base.Base): 'job-metadata', plugin="metadata@1.0b") pdefs = XML.SubElement(pdefp, 'values') for mdata in metadata: - self.registry.dispatch('metadata', - parser, pdefs, mdata) + self.registry.dispatch('metadata', pdefs, mdata) diff --git a/jenkins_jobs/modules/notifications.py b/jenkins_jobs/modules/notifications.py index 34103bfe9..ddb1139d3 100644 --- a/jenkins_jobs/modules/notifications.py +++ b/jenkins_jobs/modules/notifications.py @@ -30,7 +30,7 @@ from jenkins_jobs.errors import JenkinsJobsException import jenkins_jobs.modules.base -def http_endpoint(parser, xml_parent, data): +def http_endpoint(registry, xml_parent, data): """yaml: http Defines an HTTP notification endpoint. Requires the Jenkins :jenkins-wiki:`Notification Plugin @@ -87,7 +87,7 @@ class Notifications(jenkins_jobs.modules.base.Base): component_type = 'notification' component_list_type = 'notifications' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): properties = xml_parent.find('properties') if properties is None: properties = XML.SubElement(xml_parent, 'properties') @@ -102,4 +102,4 @@ class Notifications(jenkins_jobs.modules.base.Base): for endpoint in notifications: self.registry.dispatch('notification', - parser, endpoints_element, endpoint) + endpoints_element, endpoint) diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index 2fa3fcd36..bfcb30ca5 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -41,7 +41,7 @@ import jenkins_jobs.modules.base from jenkins_jobs.modules.helpers import copyartifact_build_selector -def base_param(parser, xml_parent, data, do_default, ptype): +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', '') @@ -54,7 +54,7 @@ def base_param(parser, xml_parent, data, do_default, ptype): return pdef -def string_param(parser, xml_parent, data): +def string_param(registry, xml_parent, data): """yaml: string A string parameter. @@ -70,11 +70,11 @@ def string_param(parser, xml_parent, data): default: bar description: "A parameter named FOO, defaults to 'bar'." """ - base_param(parser, xml_parent, data, True, + base_param(registry, xml_parent, data, True, 'hudson.model.StringParameterDefinition') -def promoted_param(parser, xml_parent, data): +def promoted_param(registry, xml_parent, data): """yaml: promoted build A promoted build parameter. Requires the Jenkins :jenkins-wiki:`Promoted Builds Plugin @@ -92,7 +92,7 @@ def promoted_param(parser, xml_parent, data): :language: yaml """ - pdef = base_param(parser, xml_parent, data, False, + pdef = base_param(registry, xml_parent, data, False, 'hudson.plugins.promoted__builds.parameters.' 'PromotedBuildParameterDefinition') try: @@ -104,7 +104,7 @@ def promoted_param(parser, xml_parent, data): 'promotion-name', None) -def password_param(parser, xml_parent, data): +def password_param(registry, xml_parent, data): """yaml: password A password parameter. @@ -120,11 +120,11 @@ def password_param(parser, xml_parent, data): default: 1HSC0Ts6E161FysGf+e1xasgsHkgleLh09JUTYnipPvw= description: "A parameter named FOO." """ - base_param(parser, xml_parent, data, True, + base_param(registry, xml_parent, data, True, 'hudson.model.PasswordParameterDefinition') -def bool_param(parser, xml_parent, data): +def bool_param(registry, xml_parent, data): """yaml: bool A boolean parameter. @@ -141,11 +141,11 @@ def bool_param(parser, xml_parent, data): description: "A parameter named FOO, defaults to 'false'." """ data['default'] = str(data.get('default', False)).lower() - base_param(parser, xml_parent, data, True, + base_param(registry, xml_parent, data, True, 'hudson.model.BooleanParameterDefinition') -def file_param(parser, xml_parent, data): +def file_param(registry, xml_parent, data): """yaml: file A file parameter. @@ -159,11 +159,11 @@ def file_param(parser, xml_parent, data): name: test.txt description: "Upload test.txt." """ - base_param(parser, xml_parent, data, False, + base_param(registry, xml_parent, data, False, 'hudson.model.FileParameterDefinition') -def text_param(parser, xml_parent, data): +def text_param(registry, xml_parent, data): """yaml: text A text parameter. @@ -179,11 +179,11 @@ def text_param(parser, xml_parent, data): default: bar description: "A parameter named FOO, defaults to 'bar'." """ - base_param(parser, xml_parent, data, True, + base_param(registry, xml_parent, data, True, 'hudson.model.TextParameterDefinition') -def label_param(parser, xml_parent, data): +def label_param(registry, xml_parent, data): """yaml: label A node label parameter. @@ -199,12 +199,12 @@ def label_param(parser, xml_parent, data): default: precise description: "The node on which to run the job" """ - base_param(parser, xml_parent, data, True, + base_param(registry, xml_parent, data, True, 'org.jvnet.jenkins.plugins.nodelabelparameter.' 'LabelParameterDefinition') -def node_param(parser, xml_parent, data): +def node_param(registry, xml_parent, data): """yaml: node Defines a list of nodes where this job could potentially be executed on. Restrict where this project can be run, If your using a node or label @@ -232,7 +232,7 @@ def node_param(parser, xml_parent, data): :language: yaml """ - pdef = base_param(parser, xml_parent, data, False, + pdef = base_param(registry, xml_parent, data, False, 'org.jvnet.jenkins.plugins.nodelabelparameter.' 'NodeParameterDefinition') default = XML.SubElement(pdef, 'defaultSlaves') @@ -258,7 +258,7 @@ def node_param(parser, xml_parent, data): data.get('allowed-multiselect', False)).lower() -def choice_param(parser, xml_parent, data): +def choice_param(registry, xml_parent, data): """yaml: choice A single selection parameter. @@ -276,7 +276,7 @@ def choice_param(parser, xml_parent, data): - glance description: "On which project to run?" """ - pdef = base_param(parser, xml_parent, data, False, + pdef = base_param(registry, xml_parent, data, False, 'hudson.model.ChoiceParameterDefinition') choices = XML.SubElement(pdef, 'choices', {'class': 'java.util.Arrays$ArrayList'}) @@ -285,7 +285,7 @@ def choice_param(parser, xml_parent, data): XML.SubElement(a, 'string').text = choice -def run_param(parser, xml_parent, data): +def run_param(registry, xml_parent, data): """yaml: run A run parameter. @@ -299,12 +299,12 @@ def run_param(parser, xml_parent, data): :language: yaml """ - pdef = base_param(parser, xml_parent, data, False, + pdef = base_param(registry, xml_parent, data, False, 'hudson.model.RunParameterDefinition') XML.SubElement(pdef, 'projectName').text = data['project-name'] -def extended_choice_param(parser, xml_parent, data): +def extended_choice_param(registry, xml_parent, data): """yaml: extended-choice Creates an extended choice parameter where values can be read from a file Requires the Jenkins :jenkins-wiki:`Extended Choice Parameter Plugin @@ -346,7 +346,7 @@ def extended_choice_param(parser, xml_parent, data): :language: yaml """ - pdef = base_param(parser, xml_parent, data, False, + pdef = base_param(registry, xml_parent, data, False, 'com.cwctravel.hudson.plugins.' 'extended__choice__parameter.' 'ExtendedChoiceParameterDefinition') @@ -391,7 +391,7 @@ def extended_choice_param(parser, xml_parent, data): 'description-property-key', '') -def validating_string_param(parser, xml_parent, data): +def validating_string_param(registry, xml_parent, data): """yaml: validating-string A validating string parameter Requires the Jenkins :jenkins-wiki:`Validating String Plugin @@ -413,14 +413,14 @@ def validating_string_param(parser, xml_parent, data): regex: [A-Za-z]* msg: Your entered value failed validation """ - pdef = base_param(parser, xml_parent, data, True, + pdef = base_param(registry, xml_parent, data, True, 'hudson.plugins.validating__string__parameter.' 'ValidatingStringParameterDefinition') XML.SubElement(pdef, 'regex').text = data['regex'] XML.SubElement(pdef, 'failedValidationMessage').text = data['msg'] -def svn_tags_param(parser, xml_parent, data): +def svn_tags_param(registry, xml_parent, data): """yaml: svn-tags A svn tag parameter Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin @@ -442,7 +442,7 @@ def svn_tags_param(parser, xml_parent, data): url: http://svn.example.com/repo filter: [A-za-z0-9]* """ - pdef = base_param(parser, xml_parent, data, True, + pdef = base_param(registry, xml_parent, data, True, 'hudson.scm.listtagsparameter.' 'ListSubversionTagsParameterDefinition') XML.SubElement(pdef, 'tagsDir').text = data['url'] @@ -453,7 +453,7 @@ def svn_tags_param(parser, xml_parent, data): XML.SubElement(pdef, 'uuid').text = "1-1-1-1-1" -def dynamic_choice_param(parser, xml_parent, data): +def dynamic_choice_param(registry, xml_parent, data): """yaml: dynamic-choice Dynamic Choice Parameter Requires the Jenkins :jenkins-wiki:`Jenkins Dynamic Parameter Plug-in @@ -478,10 +478,11 @@ def dynamic_choice_param(parser, xml_parent, data): remote: false read-only: false """ - dynamic_param_common(parser, xml_parent, data, 'ChoiceParameterDefinition') + dynamic_param_common(registry, xml_parent, data, + 'ChoiceParameterDefinition') -def dynamic_string_param(parser, xml_parent, data): +def dynamic_string_param(registry, xml_parent, data): """yaml: dynamic-string Dynamic Parameter Requires the Jenkins :jenkins-wiki:`Jenkins Dynamic Parameter Plug-in @@ -506,10 +507,11 @@ def dynamic_string_param(parser, xml_parent, data): remote: false read-only: false """ - dynamic_param_common(parser, xml_parent, data, 'StringParameterDefinition') + dynamic_param_common(registry, xml_parent, data, + 'StringParameterDefinition') -def dynamic_choice_scriptler_param(parser, xml_parent, data): +def dynamic_choice_scriptler_param(registry, xml_parent, data): """yaml: dynamic-choice-scriptler Dynamic Choice Parameter (Scriptler) Requires the Jenkins :jenkins-wiki:`Jenkins Dynamic Parameter Plug-in @@ -542,11 +544,11 @@ def dynamic_choice_scriptler_param(parser, xml_parent, data): remote: false read-only: false """ - dynamic_scriptler_param_common(parser, xml_parent, data, + dynamic_scriptler_param_common(registry, xml_parent, data, 'ScriptlerChoiceParameterDefinition') -def dynamic_string_scriptler_param(parser, xml_parent, data): +def dynamic_string_scriptler_param(registry, xml_parent, data): """yaml: dynamic-string-scriptler Dynamic Parameter (Scriptler) Requires the Jenkins :jenkins-wiki:`Jenkins Dynamic Parameter Plug-in @@ -579,12 +581,12 @@ def dynamic_string_scriptler_param(parser, xml_parent, data): remote: false read-only: false """ - dynamic_scriptler_param_common(parser, xml_parent, data, + dynamic_scriptler_param_common(registry, xml_parent, data, 'ScriptlerStringParameterDefinition') -def dynamic_param_common(parser, xml_parent, data, ptype): - pdef = base_param(parser, xml_parent, data, False, +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( @@ -604,8 +606,8 @@ def dynamic_param_common(parser, xml_parent, data, ptype): data.get('read-only', False)).lower() -def dynamic_scriptler_param_common(parser, xml_parent, data, ptype): - pdef = base_param(parser, xml_parent, data, False, +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) XML.SubElement(pdef, '__remote').text = str( @@ -627,7 +629,7 @@ def dynamic_scriptler_param_common(parser, xml_parent, data, ptype): 'read-only', False)).lower() -def matrix_combinations_param(parser, xml_parent, data): +def matrix_combinations_param(registry, xml_parent, data): """yaml: matrix-combinations Matrix combinations parameter Requires the Jenkins :jenkins-wiki:`Matrix Combinations Plugin @@ -661,7 +663,7 @@ def matrix_combinations_param(parser, xml_parent, data): return pdef -def copyartifact_build_selector_param(parser, xml_parent, data): +def copyartifact_build_selector_param(registry, xml_parent, data): """yaml: copyartifact-build-selector Control via a build parameter, which build the copyartifact plugin should @@ -696,7 +698,7 @@ def copyartifact_build_selector_param(parser, xml_parent, data): copyartifact_build_selector(t, data, 'defaultSelector') -def maven_metadata_param(parser, xml_parent, data): +def maven_metadata_param(registry, xml_parent, data): """yaml: maven-metadata This parameter allows the resolution of maven artifact versions by contacting the repository and reading the maven-metadata.xml. @@ -734,7 +736,7 @@ def maven_metadata_param(parser, xml_parent, data): :language: yaml """ - pdef = base_param(parser, xml_parent, data, False, + pdef = base_param(registry, xml_parent, data, False, 'eu.markov.jenkins.plugin.mvnmeta.' 'MavenMetadataParameterDefinition') XML.SubElement(pdef, 'repoBaseUrl').text = data.get('repository-base-url', @@ -766,7 +768,7 @@ class Parameters(jenkins_jobs.modules.base.Base): component_type = 'parameter' component_list_type = 'parameters' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): properties = xml_parent.find('properties') if properties is None: properties = XML.SubElement(xml_parent, 'properties') @@ -787,5 +789,4 @@ class Parameters(jenkins_jobs.modules.base.Base): if pdefs is None: pdefs = XML.SubElement(pdefp, 'parameterDefinitions') for param in parameters: - self.registry.dispatch('parameter', - parser, pdefs, param) + self.registry.dispatch('parameter', pdefs, param) diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 5f7df3ce4..47fce9efe 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -42,7 +42,7 @@ import jenkins_jobs.modules.base from jenkins_jobs.modules.helpers import convert_mapping_to_xml -def builds_chain_fingerprinter(parser, xml_parent, data): +def builds_chain_fingerprinter(registry, xml_parent, data): """yaml: builds-chain-fingerprinter Builds chain fingerprinter. Requires the Jenkins :jenkins-wiki:`Builds chain fingerprinter Plugin @@ -68,7 +68,7 @@ def builds_chain_fingerprinter(parser, xml_parent, data): data.get('per-job-chain', False)).lower() -def ownership(parser, xml_parent, data): +def ownership(registry, xml_parent, data): """yaml: ownership Plugin provides explicit ownership for jobs and slave nodes. Requires the Jenkins :jenkins-wiki:`Ownership Plugin `. @@ -96,7 +96,7 @@ def ownership(parser, xml_parent, data): XML.SubElement(coownersIds, 'string').text = coowner -def promoted_build(parser, xml_parent, data): +def promoted_build(registry, xml_parent, data): """yaml: promoted-build Marks a build for promotion. A promotion process with an identical name must be created via the web interface in the job in order for the job @@ -121,7 +121,7 @@ def promoted_build(parser, xml_parent, data): XML.SubElement(active_processes, 'string').text = str(n) -def github(parser, xml_parent, data): +def github(registry, xml_parent, data): """yaml: github Sets the GitHub URL for the project. @@ -141,7 +141,7 @@ def github(parser, xml_parent, data): raise MissingAttributeError(e) -def gitlab(parser, xml_parent, data): +def gitlab(registry, xml_parent, data): """yaml: gitlab Sets the GitLab connection for the project. Configured via Jenkins Global Configuration. @@ -163,7 +163,7 @@ def gitlab(parser, xml_parent, data): raise MissingAttributeError(e) -def least_load(parser, xml_parent, data): +def least_load(registry, xml_parent, data): """yaml: least-load Enables the Least Load Plugin. Requires the Jenkins :jenkins-wiki:`Least Load Plugin `. @@ -183,7 +183,7 @@ def least_load(parser, xml_parent, data): data.get('disabled', True)).lower() -def throttle(parser, xml_parent, data): +def throttle(registry, xml_parent, data): """yaml: throttle Throttles the number of builds for this job. Requires the Jenkins :jenkins-wiki:`Throttle Concurrent Builds Plugin @@ -235,7 +235,7 @@ def throttle(parser, xml_parent, data): data.get('matrix-configs', False)).lower() -def sidebar(parser, xml_parent, data): +def sidebar(registry, xml_parent, data): """yaml: sidebar Allows you to add links in the sidebar. Requires the Jenkins :jenkins-wiki:`Sidebar-Link Plugin @@ -263,7 +263,7 @@ def sidebar(parser, xml_parent, data): XML.SubElement(action, 'icon').text = str(data.get('icon', '')) -def inject(parser, xml_parent, data): +def inject(registry, xml_parent, data): """yaml: inject Allows you to inject environment variables into the build. Requires the Jenkins :jenkins-wiki:`Env Inject Plugin `. @@ -313,7 +313,7 @@ def inject(parser, xml_parent, data): data.get('override-build-parameters', False)).lower() -def authenticated_build(parser, xml_parent, data): +def authenticated_build(registry, xml_parent, data): """yaml: authenticated-build Specifies an authorization matrix where only authenticated users may trigger a build. @@ -335,7 +335,7 @@ def authenticated_build(parser, xml_parent, data): 'hudson.model.Item.Build:authenticated') -def authorization(parser, xml_parent, data): +def authorization(registry, xml_parent, data): """yaml: authorization Specifies an authorization matrix @@ -408,7 +408,7 @@ def authorization(parser, xml_parent, data): raise InvalidAttributeError(username, perm, mapping.keys()) -def priority_sorter(parser, xml_parent, data): +def priority_sorter(registry, xml_parent, data): """yaml: priority-sorter Allows simple ordering of builds, using a configurable job priority. @@ -433,7 +433,7 @@ def priority_sorter(parser, xml_parent, data): raise MissingAttributeError(e) -def build_blocker(parser, xml_parent, data): +def build_blocker(registry, xml_parent, data): """yaml: build-blocker This plugin keeps the actual job in the queue if at least one name of currently running jobs @@ -487,7 +487,7 @@ def build_blocker(parser, xml_parent, data): XML.SubElement(blocker, 'scanQueueFor').text = queue_scanning -def copyartifact(parser, xml_parent, data): +def copyartifact(registry, xml_parent, data): """yaml: copyartifact Specify a list of projects that have access to copy the artifacts of this project. @@ -518,7 +518,7 @@ def copyartifact(parser, xml_parent, data): XML.SubElement(projectlist, 'string').text = project -def batch_tasks(parser, xml_parent, data): +def batch_tasks(registry, xml_parent, data): """yaml: batch-tasks Batch tasks can be tasks for events like releases, integration, archiving, etc. In this way, anyone in the project team can execute them in a way that @@ -553,7 +553,7 @@ def batch_tasks(parser, xml_parent, data): XML.SubElement(batch_task, 'script').text = task['script'] -def heavy_job(parser, xml_parent, data): +def heavy_job(registry, xml_parent, data): """yaml: heavy-job This plugin allows you to define "weight" on each job, and making each job consume that many executors @@ -576,7 +576,7 @@ def heavy_job(parser, xml_parent, data): data.get('weight', 1)) -def slave_utilization(parser, xml_parent, data): +def slave_utilization(registry, xml_parent, data): """yaml: slave-utilization This plugin allows you to specify the percentage of a slave's capacity a job wants to use. @@ -607,7 +607,7 @@ def slave_utilization(parser, xml_parent, data): data.get('single-instance-per-slave', False)).lower() -def delivery_pipeline(parser, xml_parent, data): +def delivery_pipeline(registry, xml_parent, data): """yaml: delivery-pipeline Requires the Jenkins :jenkins-wiki:`Delivery Pipeline Plugin `. @@ -641,7 +641,7 @@ def delivery_pipeline(parser, xml_parent, data): convert_mapping_to_xml(pipeline, data, mapping, fail_required=True) -def zeromq_event(parser, xml_parent, data): +def zeromq_event(registry, xml_parent, data): """yaml: zeromq-event This is a Jenkins plugin that will publish Jenkins Job run events (start, complete, finish) to a ZMQ PUB socket. @@ -663,7 +663,7 @@ def zeromq_event(parser, xml_parent, data): XML.SubElement(zmq_event, 'enabled').text = 'true' -def slack(parser, xml_parent, data): +def slack(registry, xml_parent, data): """yaml: slack Requires the Jenkins :jenkins-wiki:`Slack Plugin ` @@ -708,7 +708,7 @@ def slack(parser, xml_parent, data): logger = logging.getLogger(__name__) - plugin_info = parser.registry.get_plugin_info('Slack Notification Plugin') + 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"): @@ -746,7 +746,7 @@ def slack(parser, xml_parent, data): _add_xml(slack, xml_name, data.get(yaml_name, default_value)) -def rebuild(parser, xml_parent, data): +def rebuild(registry, xml_parent, data): """yaml: rebuild Requires the Jenkins :jenkins-wiki:`Rebuild Plugin `. @@ -771,7 +771,7 @@ def rebuild(parser, xml_parent, data): data.get('rebuild-disabled', False)).lower() -def build_discarder(parser, xml_parent, data): +def build_discarder(registry, xml_parent, data): """yaml: build-discarder :arg int days-to-keep: Number of days to keep builds for (default -1) @@ -811,10 +811,10 @@ class Properties(jenkins_jobs.modules.base.Base): component_type = 'property' component_list_type = 'properties' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): properties = xml_parent.find('properties') if properties is None: properties = XML.SubElement(xml_parent, 'properties') for prop in data.get('properties', []): - self.registry.dispatch('property', parser, properties, prop) + self.registry.dispatch('property', properties, prop) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c80d57103..ad1f7e32b 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -41,7 +41,7 @@ from jenkins_jobs.modules import hudson_model import jenkins_jobs.modules.helpers as helpers -def archive(parser, xml_parent, data): +def archive(registry, xml_parent, data): """yaml: archive Archive build artifacts @@ -98,7 +98,7 @@ def archive(parser, xml_parent, data): default_excludes.text = str(data.get('default-excludes', True)).lower() -def blame_upstream(parser, xml_parent, data): +def blame_upstream(registry, xml_parent, data): """yaml: blame-upstream Notify upstream commiters when build fails Requires the Jenkins :jenkins-wiki:`Blame upstream commiters Plugin @@ -115,7 +115,7 @@ def blame_upstream(parser, xml_parent, data): 'BlameUpstreamCommitersPublisher') -def jclouds(parser, xml_parent, data): +def jclouds(registry, xml_parent, data): """yaml: jclouds JClouds Cloud Storage Settings provides a way to store artifacts on JClouds supported storage providers. Requires the Jenkins @@ -161,7 +161,7 @@ def jclouds(parser, xml_parent, data): data.get('hierarchy', False)).lower() -def javadoc(parser, xml_parent, data): +def javadoc(registry, xml_parent, data): """yaml: javadoc Publish Javadoc Requires the Jenkins :jenkins-wiki:`Javadoc Plugin `. @@ -187,7 +187,7 @@ def javadoc(parser, xml_parent, data): 'keep-all-successful', False)).lower() -def jdepend(parser, xml_parent, data): +def jdepend(registry, xml_parent, data): """yaml: jdepend Publish jdepend report Requires the :jenkins-wiki:`JDepend Plugin `. @@ -208,7 +208,7 @@ def jdepend(parser, xml_parent, data): XML.SubElement(jdepend, 'configuredJDependFile').text = str(filepath) -def hue_light(parser, xml_parent, data): +def hue_light(registry, xml_parent, data): """yaml: hue-light This plugin shows the state of your builds using the awesome Philips hue lights. @@ -253,7 +253,7 @@ def hue_light(parser, xml_parent, data): hue_light, data, build_mapping, fail_required=True) -def campfire(parser, xml_parent, data): +def campfire(registry, xml_parent, data): """yaml: campfire Send build notifications to Campfire rooms. Requires the Jenkins :jenkins-wiki:`Campfire Plugin `. @@ -297,7 +297,7 @@ def campfire(parser, xml_parent, data): XML.SubElement(room, 'campfire reference="../../campfire"') -def codecover(parser, xml_parent, data): +def codecover(registry, xml_parent, data): """yaml: codecover This plugin allows you to capture code coverage report from CodeCover. Jenkins will generate the trend report of coverage. @@ -346,7 +346,7 @@ def codecover(parser, xml_parent, data): health_report, data, mapping, fail_required=True) -def emotional_jenkins(parser, xml_parent, data): +def emotional_jenkins(registry, xml_parent, data): """yaml: emotional-jenkins Emotional Jenkins. This funny plugin changes the expression of Mr. Jenkins in the background when your builds fail. @@ -364,7 +364,7 @@ def emotional_jenkins(parser, xml_parent, data): 'EmotionalJenkinsPublisher') -def trigger_parameterized_builds(parser, xml_parent, data): +def trigger_parameterized_builds(registry, xml_parent, data): """yaml: trigger-parameterized-builds Trigger parameterized builds of other jobs. Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin @@ -457,8 +457,8 @@ def trigger_parameterized_builds(parser, xml_parent, data): ] try: - if parser.jjb_config.config_parser.getboolean('__future__', - 'param_order_from_yaml'): + if registry.jjb_config.config_parser.getboolean( + '__future__', 'param_order_from_yaml'): orig_order = None except six.moves.configparser.NoSectionError: pass @@ -586,7 +586,7 @@ def trigger_parameterized_builds(parser, xml_parent, data): project_def.get('trigger-with-no-params', False)).lower() -def trigger(parser, xml_parent, data): +def trigger(registry, xml_parent, data): """yaml: trigger Trigger non-parametrised builds of other jobs. @@ -617,7 +617,7 @@ def trigger(parser, xml_parent, data): tcolor.text = hudson_model.THRESHOLDS[threshold]['color'] -def clone_workspace(parser, xml_parent, data): +def clone_workspace(registry, xml_parent, data): """yaml: clone-workspace Archive the workspace from builds of one project and reuse them as the SCM source for another project. @@ -689,7 +689,7 @@ def clone_workspace(parser, xml_parent, data): override_default_excludes_elem.text = override_default_excludes_str -def cloverphp(parser, xml_parent, data): +def cloverphp(registry, xml_parent, data): """yaml: cloverphp Capture code coverage reports from PHPUnit Requires the Jenkins :jenkins-wiki:`Clover PHP Plugin `. @@ -795,7 +795,7 @@ def cloverphp(parser, xml_parent, data): XML.SubElement(cur_target, t_type + 'Coverage').text = str(val) -def coverage(parser, xml_parent, data): +def coverage(registry, xml_parent, data): """yaml: coverage WARNING: The coverage function is deprecated. Instead, use the cobertura function to generate a cobertura coverage report. @@ -865,7 +865,7 @@ def coverage(parser, xml_parent, data): XML.SubElement(cobertura, 'sourceEncoding').text = 'ASCII' -def cobertura(parser, xml_parent, data): +def cobertura(registry, xml_parent, data): """yaml: cobertura Generate a cobertura coverage report. Requires the Jenkins :jenkins-wiki:`Cobertura Coverage Plugin @@ -953,7 +953,7 @@ def cobertura(parser, xml_parent, data): 'source-encoding', 'ASCII') -def jacoco(parser, xml_parent, data): +def jacoco(registry, xml_parent, data): """yaml: jacoco Generate a JaCoCo coverage report. Requires the Jenkins :jenkins-wiki:`JaCoCo Plugin `. @@ -1023,7 +1023,7 @@ def jacoco(parser, xml_parent, data): 'Coverage').text = str(item_values.get('unhealthy', 0)) -def ftp(parser, xml_parent, data): +def ftp(registry, xml_parent, data): """yaml: ftp Upload files via FTP. Requires the Jenkins :jenkins-wiki:`Publish over FTP Plugin @@ -1065,7 +1065,7 @@ def ftp(parser, xml_parent, data): XML.SubElement(transfer_node, 'asciiMode').text = 'false' -def junit(parser, xml_parent, data): +def junit(registry, xml_parent, data): """yaml: junit Publish JUnit test results. @@ -1131,7 +1131,7 @@ def junit(parser, xml_parent, data): '.JUnitFlakyTestDataPublisher') -def cucumber_reports(parser, xml_parent, data): +def cucumber_reports(registry, xml_parent, data): """yaml: cucumber-reports This plugin creates pretty cucumber-jvm html reports on jenkins. @@ -1195,7 +1195,7 @@ def cucumber_reports(parser, xml_parent, data): cucumber_reports, data, mappings, fail_required=True) -def cucumber_testresult(parser, xml_parent, data): +def cucumber_testresult(registry, xml_parent, data): """yaml: cucumber-testresult Publish cucumber test results. Requires the Jenkins :jenkins-wiki:`cucumber testresult @@ -1220,7 +1220,7 @@ def cucumber_testresult(parser, xml_parent, data): XML.SubElement(cucumber_result, 'testResults').text = str(filepath) -def xunit(parser, xml_parent, data): +def xunit(registry, xml_parent, data): """yaml: xunit Publish tests results. Requires the Jenkins :jenkins-wiki:`xUnit Plugin `. @@ -1375,7 +1375,7 @@ def _violations_add_entry(xml_parent, name, data): XML.SubElement(tconfig, 'pattern') -def violations(parser, xml_parent, data): +def violations(registry, xml_parent, data): """yaml: violations Publish code style violations. Requires the Jenkins :jenkins-wiki:`Violations Plugin `. @@ -1436,7 +1436,7 @@ def violations(parser, xml_parent, data): XML.SubElement(config, 'encoding').text = 'default' -def findbugs(parser, xml_parent, data): +def findbugs(registry, xml_parent, data): """yaml: findbugs FindBugs reporting for builds @@ -1505,7 +1505,7 @@ def findbugs(parser, xml_parent, data): helpers.build_trends_publisher('[FINDBUGS] ', findbugs, data) -def checkstyle(parser, xml_parent, data): +def checkstyle(registry, xml_parent, data): """yaml: checkstyle Publish trend reports with Checkstyle. Requires the Jenkins :jenkins-wiki:`Checkstyle Plugin `. @@ -1603,7 +1603,7 @@ def checkstyle(parser, xml_parent, data): helpers.build_trends_publisher('[CHECKSTYLE] ', xml_element, data) -def scp(parser, xml_parent, data): +def scp(registry, xml_parent, data): """yaml: scp Upload files via SCP Requires the Jenkins :jenkins-wiki:`SCP Plugin `. @@ -1669,7 +1669,7 @@ def scp(parser, xml_parent, data): XML.SubElement(entry_e, 'copyAfterFailure').text = 'false' -def ssh(parser, xml_parent, data): +def ssh(registry, xml_parent, data): """yaml: ssh Upload files via SCP. Requires the Jenkins :jenkins-wiki:`Publish over SSH Plugin @@ -1714,7 +1714,7 @@ def ssh(parser, xml_parent, data): publisher_tag, transfer_tag, reference_tag) -def pipeline(parser, xml_parent, data): +def pipeline(registry, xml_parent, data): """yaml: pipeline Specify a downstream project in a pipeline. Requires the Jenkins :jenkins-wiki:`Build Pipeline Plugin @@ -1787,7 +1787,7 @@ def pipeline(parser, xml_parent, data): XML.SubElement(pippub, 'downstreamProjectNames').text = data['project'] -def email(parser, xml_parent, data): +def email(registry, xml_parent, data): """yaml: email Email notifications on build failure. Requires the Jenkins :jenkins-wiki:`Mailer Plugin @@ -1828,7 +1828,7 @@ def email(parser, xml_parent, data): data.get('send-to-individuals', False)).lower() -def claim_build(parser, xml_parent, data): +def claim_build(registry, xml_parent, data): """yaml: claim-build Claim build failures Requires the Jenkins :jenkins-wiki:`Claim Plugin `. @@ -1842,7 +1842,7 @@ def claim_build(parser, xml_parent, data): XML.SubElement(xml_parent, 'hudson.plugins.claim.ClaimPublisher') -def base_email_ext(parser, xml_parent, data, ttype): +def base_email_ext(registry, xml_parent, data, ttype): trigger = XML.SubElement(xml_parent, 'hudson.plugins.emailext.plugins.trigger.' + ttype) @@ -1866,7 +1866,7 @@ def base_email_ext(parser, xml_parent, data, ttype): XML.SubElement(email, 'sendToRecipientList').text = 'true' -def email_ext(parser, xml_parent, data): +def email_ext(registry, xml_parent, data): """yaml: email-ext Extend Jenkin's built in email notification Requires the Jenkins :jenkins-wiki:`Email-ext Plugin @@ -1942,33 +1942,33 @@ def email_ext(parser, xml_parent, data): XML.SubElement(emailext, 'recipientList').text = '$DEFAULT_RECIPIENTS' ctrigger = XML.SubElement(emailext, 'configuredTriggers') if data.get('always', False): - base_email_ext(parser, ctrigger, data, 'AlwaysTrigger') + base_email_ext(registry, ctrigger, data, 'AlwaysTrigger') if data.get('unstable', False): - base_email_ext(parser, ctrigger, data, 'UnstableTrigger') + base_email_ext(registry, ctrigger, data, 'UnstableTrigger') if data.get('first-failure', False): - base_email_ext(parser, ctrigger, data, 'FirstFailureTrigger') + base_email_ext(registry, ctrigger, data, 'FirstFailureTrigger') if data.get('not-built', False): - base_email_ext(parser, ctrigger, data, 'NotBuiltTrigger') + base_email_ext(registry, ctrigger, data, 'NotBuiltTrigger') if data.get('aborted', False): - base_email_ext(parser, ctrigger, data, 'AbortedTrigger') + base_email_ext(registry, ctrigger, data, 'AbortedTrigger') if data.get('regression', False): - base_email_ext(parser, ctrigger, data, 'RegressionTrigger') + base_email_ext(registry, ctrigger, data, 'RegressionTrigger') if data.get('failure', True): - base_email_ext(parser, ctrigger, data, 'FailureTrigger') + base_email_ext(registry, ctrigger, data, 'FailureTrigger') if data.get('second-failure', False): - base_email_ext(parser, ctrigger, data, 'SecondFailureTrigger') + base_email_ext(registry, ctrigger, data, 'SecondFailureTrigger') if data.get('improvement', False): - base_email_ext(parser, ctrigger, data, 'ImprovementTrigger') + base_email_ext(registry, ctrigger, data, 'ImprovementTrigger') if data.get('still-failing', False): - base_email_ext(parser, ctrigger, data, 'StillFailingTrigger') + base_email_ext(registry, ctrigger, data, 'StillFailingTrigger') if data.get('success', False): - base_email_ext(parser, ctrigger, data, 'SuccessTrigger') + base_email_ext(registry, ctrigger, data, 'SuccessTrigger') if data.get('fixed', False): - base_email_ext(parser, ctrigger, data, 'FixedTrigger') + base_email_ext(registry, ctrigger, data, 'FixedTrigger') if data.get('still-unstable', False): - base_email_ext(parser, ctrigger, data, 'StillUnstableTrigger') + base_email_ext(registry, ctrigger, data, 'StillUnstableTrigger') if data.get('pre-build', False): - base_email_ext(parser, ctrigger, data, 'PreBuildTrigger') + base_email_ext(registry, ctrigger, data, 'PreBuildTrigger') content_type_mime = { 'text': 'text/plain', @@ -2014,7 +2014,7 @@ def email_ext(parser, xml_parent, data): matrix_dict.get(matrix_trigger) -def fingerprint(parser, xml_parent, data): +def fingerprint(registry, xml_parent, data): """yaml: fingerprint Fingerprint files to track them across builds @@ -2034,7 +2034,7 @@ def fingerprint(parser, xml_parent, data): 'record-artifacts', False)).lower() -def aggregate_tests(parser, xml_parent, data): +def aggregate_tests(registry, xml_parent, data): """yaml: aggregate-tests Aggregate downstream test results @@ -2052,7 +2052,7 @@ def aggregate_tests(parser, xml_parent, data): 'include-failed-builds', False)).lower() -def aggregate_flow_tests(parser, xml_parent, data): +def aggregate_flow_tests(registry, xml_parent, data): """yaml: aggregate-flow-tests Aggregate downstream test results in a Build Flow job. Requires the Jenkins :jenkins-wiki:`Build Flow Test Aggregator Plugin @@ -2074,7 +2074,7 @@ def aggregate_flow_tests(parser, xml_parent, data): data.get('show-test-results-trend', True)).lower() -def cppcheck(parser, xml_parent, data): +def cppcheck(registry, xml_parent, data): """yaml: cppcheck Cppcheck result publisher Requires the Jenkins :jenkins-wiki:`Cppcheck Plugin `. @@ -2140,7 +2140,7 @@ def cppcheck(parser, xml_parent, data): str(gdisplay.get('information', False)).lower() -def logparser(parser, xml_parent, data): +def logparser(registry, xml_parent, data): """yaml: logparser Requires the Jenkins :jenkins-wiki:`Log Parser Plugin `. @@ -2164,7 +2164,7 @@ def logparser(parser, xml_parent, data): XML.SubElement(clog, 'parsingRulesPath').text = data.get('parse-rules', '') -def copy_to_master(parser, xml_parent, data): +def copy_to_master(registry, xml_parent, data): """yaml: copy-to-master Copy files to master from slave Requires the Jenkins :jenkins-wiki:`Copy To Slave Plugin @@ -2195,7 +2195,7 @@ def copy_to_master(parser, xml_parent, data): XML.SubElement(cm, 'overrideDestinationFolder').text = 'true' -def jira(parser, xml_parent, data): +def jira(registry, xml_parent, data): """yaml: jira Update relevant JIRA issues Requires the Jenkins :jenkins-wiki:`JIRA Plugin `. @@ -2208,7 +2208,7 @@ def jira(parser, xml_parent, data): XML.SubElement(xml_parent, 'hudson.plugins.jira.JiraIssueUpdater') -def growl(parser, xml_parent, data): +def growl(registry, xml_parent, data): """yaml: growl Push notifications to growl client. Requires the Jenkins :jenkins-wiki:`Growl Plugin `. @@ -2237,7 +2237,7 @@ def growl(parser, xml_parent, data): helpers.convert_mapping_to_xml(growl, data, mapping, fail_required=True) -def groovy_postbuild(parser, xml_parent, data): +def groovy_postbuild(registry, xml_parent, data): """yaml: groovy-postbuild Execute a groovy script. Requires the Jenkins :jenkins-wiki:`Groovy Postbuild Plugin @@ -2277,7 +2277,7 @@ def groovy_postbuild(parser, xml_parent, data): 'script': data, } # There are incompatible changes, we need to know version - info = parser.registry.get_plugin_info('groovy-postbuild') + info = registry.get_plugin_info('groovy-postbuild') version = pkg_resources.parse_version(info.get('version', "0")) # Version specific predicates matrix_parent_support = version >= pkg_resources.parse_version("1.9") @@ -2379,7 +2379,7 @@ def base_publish_over(xml_parent, data, console_prefix, return (outer, transfersset) -def cifs(parser, xml_parent, data): +def cifs(registry, xml_parent, data): """yaml: cifs Upload files via CIFS. Requires the Jenkins :jenkins-wiki:`Publish over CIFS Plugin @@ -2420,7 +2420,7 @@ def cifs(parser, xml_parent, data): plugin_reference_tag) -def cigame(parser, xml_parent, data): +def cigame(registry, xml_parent, data): """yaml: cigame This plugin introduces a game where users get points for improving the builds. @@ -2435,7 +2435,7 @@ def cigame(parser, xml_parent, data): XML.SubElement(xml_parent, 'hudson.plugins.cigame.GamePublisher') -def sonar(parser, xml_parent, data): +def sonar(registry, xml_parent, data): """yaml: sonar Sonar plugin support. Requires the Jenkins `Sonar Plugin. @@ -2498,7 +2498,7 @@ def sonar(parser, xml_parent, data): helpers.config_file_provider_settings(sonar, data) -def performance(parser, xml_parent, data): +def performance(registry, xml_parent, data): """yaml: performance Publish performance test results from jmeter and junit. Requires the Jenkins :jenkins-wiki:`Performance Plugin @@ -2566,7 +2566,7 @@ def performance(parser, xml_parent, data): sys.exit(1) -def join_trigger(parser, xml_parent, data): +def join_trigger(registry, xml_parent, data): """yaml: join-trigger Trigger a job after all the immediate downstream jobs have completed @@ -2588,14 +2588,14 @@ def join_trigger(parser, xml_parent, data): publishers = XML.SubElement(jointrigger, 'joinPublishers') for pub in data.get('publishers', []): - for edited_node in create_publishers(parser, pub): + 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 -def jabber(parser, xml_parent, data): +def jabber(registry, xml_parent, data): """yaml: jabber Integrates Jenkins with the Jabber/XMPP instant messaging protocol Requires the Jenkins :jenkins-wiki:`Jabber Plugin `. @@ -2682,7 +2682,7 @@ def jabber(parser, xml_parent, data): XML.SubElement(j, 'matrixMultiplier').text = 'ONLY_CONFIGURATIONS' -def workspace_cleanup(parser, xml_parent, data): +def workspace_cleanup(registry, xml_parent, data): """yaml: workspace-cleanup (post-build) Requires the Jenkins :jenkins-wiki:`Workspace Cleanup Plugin @@ -2757,7 +2757,7 @@ def workspace_cleanup(parser, xml_parent, data): XML.SubElement(p, 'notFailBuild').text = 'false' -def maven_deploy(parser, xml_parent, data): +def maven_deploy(registry, xml_parent, data): """yaml: maven-deploy Deploy artifacts to Maven repository. @@ -2790,7 +2790,7 @@ def maven_deploy(parser, xml_parent, data): XML.SubElement(p, 'releaseEnvVar').text = data['release-env-var'] -def artifactory(parser, xml_parent, data): +def artifactory(registry, xml_parent, data): """yaml: artifactory Uses/requires the Artifactory plugin to deploy artifacts to Artifactory Server. @@ -2928,7 +2928,7 @@ def artifactory(parser, xml_parent, data): helpers.artifactory_env_vars_patterns(artifactory, data) -def test_fairy(parser, xml_parent, data): +def test_fairy(registry, xml_parent, data): """yaml: test-fairy This plugin helps you to upload Android APKs or iOS IPA files to www.testfairy.com. @@ -3030,7 +3030,7 @@ def test_fairy(parser, xml_parent, data): raise InvalidAttributeError('platform', platform, valid_platforms) -def text_finder(parser, xml_parent, data): +def text_finder(registry, xml_parent, data): """yaml: text-finder This plugin lets you search keywords in the files you specified and additionally check build status @@ -3067,7 +3067,7 @@ def text_finder(parser, xml_parent, data): XML.SubElement(finder, 'unstableIfFound').text = unstable_if_found -def html_publisher(parser, xml_parent, data): +def html_publisher(registry, xml_parent, data): """yaml: html-publisher This plugin publishes HTML reports. @@ -3106,7 +3106,7 @@ def html_publisher(parser, xml_parent, data): XML.SubElement(ptarget, 'wrapperName').text = "htmlpublisher-wrapper.html" -def rich_text_publisher(parser, xml_parent, data): +def rich_text_publisher(registry, xml_parent, data): """yaml: rich-text-publisher This plugin puts custom rich text message to the Build pages and Job main page. @@ -3148,7 +3148,7 @@ def rich_text_publisher(parser, xml_parent, data): XML.SubElement(reporter, 'parserName').text = parser_name -def tap(parser, xml_parent, data): +def tap(registry, xml_parent, data): """yaml: tap Adds support to TAP test result files @@ -3204,7 +3204,7 @@ def tap(parser, xml_parent, data): helpers.convert_mapping_to_xml(tap, data, mappings, fail_required=True) -def post_tasks(parser, xml_parent, data): +def post_tasks(registry, xml_parent, data): """yaml: post-tasks Adds support to post build task plugin @@ -3257,7 +3257,7 @@ def post_tasks(parser, xml_parent, data): task.get('script', '')) -def postbuildscript(parser, xml_parent, data): +def postbuildscript(registry, xml_parent, data): """yaml: postbuildscript Executes additional builders, script or Groovy after the build is complete. @@ -3350,8 +3350,7 @@ def postbuildscript(parser, xml_parent, data): if step == 'builders': build_steps_xml = XML.SubElement(pbs_xml, 'buildSteps') for builder in script_data: - parser.registry.dispatch('builder', parser, 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 @@ -3390,7 +3389,7 @@ def postbuildscript(parser, xml_parent, data): execute_on_xml.text = execute_on.upper() -def xml_summary(parser, xml_parent, data): +def xml_summary(registry, xml_parent, data): """yaml: xml-summary Adds support for the Summary Display Plugin @@ -3415,7 +3414,7 @@ def xml_summary(parser, xml_parent, data): data.get('shown-on-project-page', 'false')) -def robot(parser, xml_parent, data): +def robot(registry, xml_parent, data): """yaml: robot Adds support for the Robot Framework Plugin @@ -3470,7 +3469,7 @@ def robot(parser, xml_parent, data): not data.get('archive-output-xml', True)).lower() -def warnings(parser, xml_parent, data): +def warnings(registry, xml_parent, data): """yaml: warnings Generate trend report for compiler warnings in the console log or in log files. Requires the Jenkins :jenkins-wiki:`Warnings Plugin @@ -3650,7 +3649,7 @@ def warnings(parser, xml_parent, data): XML.SubElement(warnings, 'defaultEncoding').text = encoding -def sloccount(parser, xml_parent, data): +def sloccount(registry, xml_parent, data): """yaml: sloccount Generates the trend report for SLOCCount @@ -3678,7 +3677,7 @@ def sloccount(parser, xml_parent, data): XML.SubElement(top, 'encoding').text = data.get('charset', 'UTF-8') -def ircbot(parser, xml_parent, data): +def ircbot(registry, xml_parent, data): """yaml: ircbot ircbot enables Jenkins to send build notifications via IRC and lets you interact with Jenkins via an IRC bot. @@ -3795,7 +3794,7 @@ def ircbot(parser, xml_parent, data): XML.SubElement(top, 'matrixMultiplier').text = matrix_dict.get(matrix) -def plot(parser, xml_parent, data): +def plot(registry, xml_parent, data): """yaml: plot Plot provides generic plotting (or graphing). @@ -3946,7 +3945,7 @@ def plot(parser, xml_parent, data): XML.SubElement(plugin, 'style').text = style -def git(parser, xml_parent, data): +def git(registry, xml_parent, data): """yaml: git This plugin will configure the Jenkins Git plugin to push merge results, tags, and/or branches to @@ -4049,7 +4048,7 @@ def git(parser, xml_parent, data): xml_note, note['note'], note_mappings, fail_required=True) -def github_notifier(parser, xml_parent, data): +def github_notifier(registry, xml_parent, data): """yaml: github-notifier Set build status on Github commit. Requires the Jenkins :jenkins-wiki:`Github Plugin `. @@ -4063,7 +4062,7 @@ def github_notifier(parser, xml_parent, data): 'com.cloudbees.jenkins.GitHubCommitNotifier') -def gitlab_notifier(parser, xml_parent, data): +def gitlab_notifier(registry, xml_parent, data): """yaml: gitlab-notifier Set build status on GitLab commit. Requires the Jenkins :jenkins-wiki:`GitLab Plugin `. @@ -4078,7 +4077,7 @@ def gitlab_notifier(parser, xml_parent, data): 'com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher') -def zulip(parser, xml_parent, data): +def zulip(registry, xml_parent, data): """yaml: zulip Set build status on zulip. Requires the Jenkins :jenkins-wiki:`Humbug Plugin `. @@ -4092,7 +4091,7 @@ def zulip(parser, xml_parent, data): 'hudson.plugins.humbug.HumbugNotifier') -def build_publisher(parser, xml_parent, data): +def build_publisher(registry, xml_parent, data): """yaml: build-publisher This plugin allows records from one Jenkins to be published on another Jenkins. @@ -4134,7 +4133,7 @@ def build_publisher(parser, xml_parent, data): XML.SubElement(logrotator, 'artifactNumToKeep').text = "-1" -def stash(parser, xml_parent, data): +def stash(registry, xml_parent, data): """yaml: stash This plugin will configure the Jenkins Stash Notifier plugin to notify Atlassian Stash after job completes. @@ -4166,10 +4165,10 @@ def stash(parser, xml_parent, data): else: XML.SubElement(top, 'stashUserName' ).text = helpers.get_value_from_yaml_or_config_file( - 'username', 'stash', data, parser) + 'username', 'stash', data, registry.jjb_config) XML.SubElement(top, 'stashUserPassword' ).text = helpers.get_value_from_yaml_or_config_file( - 'password', 'stash', data, parser) + 'password', 'stash', data, registry.jjb_config) XML.SubElement(top, 'ignoreUnverifiedSSLPeer').text = str( data.get('ignore-ssl', False)).lower() @@ -4178,7 +4177,7 @@ def stash(parser, xml_parent, data): data.get('include-build-number', False)).lower() -def dependency_check(parser, xml_parent, data): +def dependency_check(registry, xml_parent, data): """yaml: dependency-check Dependency-Check is an open source utility that identifies project dependencies and checks if there are any known, publicly disclosed, @@ -4249,7 +4248,7 @@ def dependency_check(parser, xml_parent, data): '[DEPENDENCYCHECK] ', dependency_check, data) -def description_setter(parser, xml_parent, data): +def description_setter(registry, xml_parent, data): """yaml: description-setter This plugin sets the description for each build, based upon a RegEx test of the build log file. @@ -4289,7 +4288,7 @@ def description_setter(parser, xml_parent, data): XML.SubElement(descriptionsetter, 'setForMatrix').text = for_matrix -def doxygen(parser, xml_parent, data): +def doxygen(registry, xml_parent, data): """yaml: doxygen This plugin parses the Doxygen descriptor (Doxyfile) and provides a link to the generated Doxygen documentation. @@ -4332,7 +4331,7 @@ def doxygen(parser, xml_parent, data): data.get('folder', '')) -def sitemonitor(parser, xml_parent, data): +def sitemonitor(registry, xml_parent, data): """yaml: sitemonitor This plugin checks the availability of an url. @@ -4355,7 +4354,7 @@ def sitemonitor(parser, xml_parent, data): XML.SubElement(site, 'mUrl').text = siteurl['url'] -def testng(parser, xml_parent, data): +def testng(registry, xml_parent, data): """yaml: testng This plugin publishes TestNG test reports. @@ -4423,7 +4422,7 @@ def testng(parser, xml_parent, data): 'threshold-mode', threshold_mode, valid_threshold_modes) -def artifact_deployer(parser, xml_parent, data): +def artifact_deployer(registry, xml_parent, data): """yaml: artifact-deployer This plugin makes it possible to copy artifacts to remote locations. @@ -4489,7 +4488,7 @@ def artifact_deployer(parser, xml_parent, data): XML.SubElement(deployer, 'deployEvenBuildFail').text = deploy_if_fail -def s3(parser, xml_parent, data): +def s3(registry, xml_parent, data): """yaml: s3 Upload build artifacts to Amazon S3. @@ -4568,7 +4567,7 @@ def s3(parser, xml_parent, data): XML.SubElement(pair, 'value').text = tag.get('value') -def ruby_metrics(parser, xml_parent, data): +def ruby_metrics(registry, xml_parent, data): """yaml: ruby-metrics Rcov plugin parses rcov html report files and shows it in Jenkins with a trend graph. @@ -4616,7 +4615,7 @@ def ruby_metrics(parser, xml_parent, data): raise JenkinsJobsException('Coverage metric targets must be set') -def fitnesse(parser, xml_parent, data): +def fitnesse(registry, xml_parent, data): """yaml: fitnesse Publish Fitnesse test results @@ -4636,7 +4635,7 @@ def fitnesse(parser, xml_parent, data): XML.SubElement(fitnesse, 'fitnessePathToXmlResultsIn').text = results -def valgrind(parser, xml_parent, data): +def valgrind(registry, xml_parent, data): """yaml: valgrind This plugin publishes Valgrind Memcheck XML results. @@ -4701,7 +4700,7 @@ def valgrind(parser, xml_parent, data): data.get('publish-if-failed', False)).lower() -def pmd(parser, xml_parent, data): +def pmd(registry, xml_parent, data): """yaml: pmd Publish trend reports with PMD. Requires the Jenkins :jenkins-wiki:`PMD Plugin `. @@ -4770,7 +4769,7 @@ def pmd(parser, xml_parent, data): helpers.build_trends_publisher('[PMD] ', xml_element, data) -def scan_build(parser, xml_parent, data): +def scan_build(registry, xml_parent, data): """yaml: scan-build Publishes results from the Clang scan-build static analyzer. @@ -4813,7 +4812,7 @@ def scan_build(parser, xml_parent, data): helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True) -def dry(parser, xml_parent, data): +def dry(registry, xml_parent, data): """yaml: dry Publish trend reports with DRY. Requires the Jenkins :jenkins-wiki:`DRY Plugin `. @@ -4892,7 +4891,7 @@ def dry(parser, xml_parent, data): xml_element, data, settings, fail_required=True) -def shining_panda(parser, xml_parent, data): +def shining_panda(registry, xml_parent, data): """yaml: shining-panda Publish coverage.py results. Requires the Jenkins :jenkins-wiki:`ShiningPanda Plugin `. @@ -4913,7 +4912,7 @@ def shining_panda(parser, xml_parent, data): data['html-reports-directory']) -def downstream_ext(parser, xml_parent, data): +def downstream_ext(registry, xml_parent, data): """yaml: downstream-ext Trigger multiple downstream jobs when a job is completed and condition is met. @@ -4983,7 +4982,7 @@ def downstream_ext(parser, xml_parent, data): data.get('only-on-local-scm-change', False)).lower() -def rundeck(parser, xml_parent, data): +def rundeck(registry, xml_parent, data): """yaml: rundeck Trigger a rundeck job when the build is complete. @@ -5034,13 +5033,13 @@ def rundeck(parser, xml_parent, data): helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True) -def create_publishers(parser, action): +def create_publishers(registry, action): dummy_parent = XML.Element("dummy") - parser.registry.dispatch('publisher', parser, dummy_parent, action) + registry.dispatch('publisher', dummy_parent, action) return list(dummy_parent) -def conditional_publisher(parser, xml_parent, data): +def conditional_publisher(registry, xml_parent, data): """yaml: conditional-publisher Conditionally execute some post-build steps. Requires the Jenkins :jenkins-wiki:`Flexible Publish Plugin `. @@ -5195,7 +5194,7 @@ def conditional_publisher(parser, xml_parent, data): 'value.' % kind) def publish_action(parent, action): - for edited_node in create_publishers(parser, 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' @@ -5240,7 +5239,7 @@ def conditional_publisher(parser, xml_parent, data): action_parent = cond_publisher plugin_info = \ - parser.registry.get_plugin_info("Flexible Publish Plugin") + registry.get_plugin_info("Flexible Publish Plugin") version = pkg_resources.parse_version(plugin_info.get('version', '0')) # XML tag changed from publisher to publisherList in v0.13 @@ -5262,7 +5261,7 @@ def conditional_publisher(parser, xml_parent, data): raise JenkinsJobsException('action must be set for each condition') -def scoverage(parser, xml_parent, data): +def scoverage(registry, xml_parent, data): """yaml: scoverage Publish scoverage results as a trend graph. Requires the Jenkins :jenkins-wiki:`Scoverage Plugin `. @@ -5290,7 +5289,7 @@ def scoverage(parser, xml_parent, data): scoverage, data, mappings, fail_required=True) -def display_upstream_changes(parser, xml_parent, data): +def display_upstream_changes(registry, xml_parent, data): """yaml: display-upstream-changes Display SCM changes of upstream jobs. Requires the Jenkins :jenkins-wiki:`Display Upstream Changes Plugin @@ -5307,7 +5306,7 @@ def display_upstream_changes(parser, xml_parent, data): 'DisplayUpstreamChangesRecorder') -def gatling(parser, xml_parent, data): +def gatling(registry, xml_parent, data): """yaml: gatling Publish gatling results as a trend graph Requires the Jenkins :jenkins-wiki:`Gatling Plugin `. @@ -5323,7 +5322,7 @@ def gatling(parser, xml_parent, data): XML.SubElement(gatling, 'enabled').text = 'true' -def logstash(parser, xml_parent, data): +def logstash(registry, xml_parent, data): """yaml: logstash Send job's console log to Logstash for processing and analyis of your job data. Also stores test metrics from Junit. @@ -5356,7 +5355,7 @@ def logstash(parser, xml_parent, data): helpers.convert_mapping_to_xml(logstash, data, mapping, fail_required=True) -def image_gallery(parser, xml_parent, data): +def image_gallery(registry, xml_parent, data): """yaml: image-gallery Produce an image gallery using Javascript library. Requires the Jenkins :jenkins-wiki:`Image Gallery Plugin`. @@ -5430,7 +5429,7 @@ def image_gallery(parser, xml_parent, data): include_comparative_elements(gallery_config, gallery_def) -def naginator(parser, xml_parent, data): +def naginator(registry, xml_parent, data): """yaml: naginator Automatically reschedule a build after a build failure Requires the Jenkins :jenkins-wiki:`Naginator Plugin `. @@ -5494,7 +5493,7 @@ def naginator(parser, xml_parent, data): data.get('max-failed-builds', '0')) -def disable_failed_job(parser, xml_parent, data): +def disable_failed_job(registry, xml_parent, data): """yaml: disable-failed-job Automatically disable failed jobs. @@ -5544,7 +5543,7 @@ def disable_failed_job(parser, xml_parent, data): XML.SubElement(xml_element, 'optionalBrockChecked').text = 'false' -def google_cloud_storage(parser, xml_parent, data): +def google_cloud_storage(registry, xml_parent, data): """yaml: google-cloud-storage Upload build artifacts to Google Cloud Storage. Requires the Jenkins :jenkins-wiki:`Google Cloud Storage plugin @@ -5742,7 +5741,7 @@ def google_cloud_storage(parser, xml_parent, data): properties, upload_element, types) -def flowdock(parser, xml_parent, data): +def flowdock(registry, xml_parent, data): """yaml: flowdock This plugin publishes job build results to a Flowdock flow. @@ -5820,7 +5819,7 @@ def flowdock(parser, xml_parent, data): gen_setting('NotBuilt', False) -def clamav(parser, xml_parent, data): +def clamav(registry, xml_parent, data): """yaml: clamav Check files with ClamAV, an open source antivirus engine. Requires the Jenkins :jenkins-wiki:`ClamAV Plugin `. @@ -5852,7 +5851,7 @@ def clamav(parser, xml_parent, data): helpers.convert_mapping_to_xml(clamav, data, mappings, fail_required=True) -def testselector(parser, xml_parent, data): +def testselector(registry, xml_parent, data): """yaml: testselector This plugin allows you to choose specific tests you want to run. @@ -5908,7 +5907,7 @@ def testselector(parser, xml_parent, data): 'multiplicity-field', '') -def cloudformation(parser, xml_parent, data): +def cloudformation(registry, xml_parent, data): """yaml: cloudformation Create cloudformation stacks before running a build and optionally delete them at the end. Requires the Jenkins :jenkins-wiki:`AWS @@ -5983,7 +5982,7 @@ def cloudformation(parser, xml_parent, data): region_dict) -def whitesource(parser, xml_parent, data): +def whitesource(registry, xml_parent, data): """yaml: whitesource This plugin brings automatic open source management to Jenkins users. @@ -6037,7 +6036,7 @@ def whitesource(parser, xml_parent, data): XML.SubElement(whitesource, 'ignorePomModules').text = 'false' -def hipchat(parser, xml_parent, data): +def hipchat(registry, xml_parent, data): """yaml: hipchat Publisher that sends hipchat notifications on job events Requires the Jenkins :jenkins-wiki:`Hipchat Plugin @@ -6108,7 +6107,7 @@ def hipchat(parser, xml_parent, data): data['complete-message']) -def slack(parser, xml_parent, data): +def slack(registry, xml_parent, data): """yaml: slack Publisher that sends slack notifications on job events. @@ -6180,7 +6179,7 @@ def slack(parser, xml_parent, data): logger = logging.getLogger(__name__) - plugin_info = parser.registry.get_plugin_info('Slack Notification Plugin') + plugin_info = registry.get_plugin_info('Slack Notification Plugin') plugin_ver = pkg_resources.parse_version(plugin_info.get('version', "0")) mapping = ( @@ -6247,7 +6246,7 @@ def slack(parser, xml_parent, data): _add_xml(slack, xml_name, value) -def phabricator(parser, xml_parent, data): +def phabricator(registry, xml_parent, data): """yaml: phabricator Integrate with `Phabricator `_ @@ -6289,7 +6288,7 @@ def phabricator(parser, xml_parent, data): data.get('comment-with-console-link-on-failure')).lower() -def openshift_build_canceller(parser, xml_parent, data): +def openshift_build_canceller(registry, xml_parent, data): """yaml: openshift-build-canceller This action is intended to provide cleanup for a Jenkins job which failed because a build is hung (instead of terminating with a failure code); @@ -6340,7 +6339,7 @@ def openshift_build_canceller(parser, xml_parent, data): helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def openshift_deploy_canceller(parser, xml_parent, data): +def openshift_deploy_canceller(registry, xml_parent, data): """yaml: openshift-deploy-canceller This action is intended to provide cleanup for any OpenShift deployments left running when the Job completes; this step will allow you to perform @@ -6388,7 +6387,7 @@ def openshift_deploy_canceller(parser, xml_parent, data): helpers.convert_mapping_to_xml(osb, data, mapping, fail_required=True) -def github_pull_request_merge(parser, xml_parent, data): +def github_pull_request_merge(registry, xml_parent, data): """yaml: github-pull-request-merge This action merges the pull request that triggered the build (see the github pull request trigger) @@ -6440,8 +6439,8 @@ class Publishers(jenkins_jobs.modules.base.Base): component_type = 'publisher' component_list_type = 'publishers' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): publishers = XML.SubElement(xml_parent, 'publishers') for action in data.get('publishers', []): - self.registry.dispatch('publisher', parser, publishers, action) + self.registry.dispatch('publisher', publishers, action) diff --git a/jenkins_jobs/modules/reporters.py b/jenkins_jobs/modules/reporters.py index d562e938f..86ab179b2 100644 --- a/jenkins_jobs/modules/reporters.py +++ b/jenkins_jobs/modules/reporters.py @@ -39,7 +39,7 @@ from jenkins_jobs.modules.helpers import build_trends_publisher from jenkins_jobs.modules.helpers import findbugs_settings -def email(parser, xml_parent, data): +def email(registry, xml_parent, data): """yaml: email Email notifications on build failure. @@ -71,7 +71,7 @@ def email(parser, xml_parent, data): XML.SubElement(mailer, 'perModuleEmail').text = 'true' -def findbugs(parser, xml_parent, data): +def findbugs(registry, xml_parent, data): """yaml: findbugs FindBugs reporting for builds @@ -142,7 +142,7 @@ class Reporters(jenkins_jobs.modules.base.Base): component_type = 'reporter' component_list_type = 'reporters' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): if 'reporters' not in data: return @@ -153,4 +153,4 @@ class Reporters(jenkins_jobs.modules.base.Base): reporters = XML.SubElement(xml_parent, 'reporters') for action in data.get('reporters', []): - self.registry.dispatch('reporter', parser, reporters, action) + self.registry.dispatch('reporter', reporters, action) diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index fffed89b9..236143d87 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -46,7 +46,7 @@ import jenkins_jobs.modules.base from jenkins_jobs.modules.helpers import convert_mapping_to_xml -def git(parser, xml_parent, data): +def git(registry, xml_parent, data): """yaml: git Specifies the git SCM repository for this job. Requires the Jenkins :jenkins-wiki:`Git Plugin `. @@ -476,7 +476,7 @@ def git(parser, xml_parent, data): data.get('repo-name', '')) -def cvs(parser, xml_parent, data): +def cvs(registry, xml_parent, data): """yaml: cvs Specifies the CVS SCM repository for this job. Requires the Jenkins :jenkins-wiki:`CVS Plugin `. @@ -606,7 +606,7 @@ def cvs(parser, xml_parent, data): data.get(opt, val)).lower() -def repo(parser, xml_parent, data): +def repo(registry, xml_parent, data): """yaml: repo Specifies the repo SCM repository for this job. Requires the Jenkins :jenkins-wiki:`Repo Plugin `. @@ -683,7 +683,7 @@ def repo(parser, xml_parent, data): XML.SubElement(ip, 'string').text = str(ignored_project) -def store(parser, xml_parent, data): +def store(registry, xml_parent, data): """yaml: store Specifies the Visualworks Smalltalk Store repository for this job. Requires the Jenkins :jenkins-wiki:`Visualworks Smalltalk Store Plugin @@ -745,7 +745,7 @@ def store(parser, xml_parent, data): XML.SubElement(scm, 'generateParcelBuilderInputFile').text = 'false' -def svn(parser, xml_parent, data): +def svn(registry, xml_parent, data): """yaml: svn Specifies the svn SCM repository for this job. @@ -872,7 +872,7 @@ def svn(parser, xml_parent, data): xe.text = str(val) -def tfs(parser, xml_parent, data): +def tfs(registry, xml_parent, data): """yaml: tfs Specifies the Team Foundation Server repository for this job. Requires the Jenkins :jenkins-wiki:`Team Foundation Server Plugin @@ -970,7 +970,7 @@ def tfs(parser, xml_parent, data): 'Browser'}) -def workspace(parser, xml_parent, data): +def workspace(registry, xml_parent, data): """yaml: workspace Specifies the cloned workspace for this job to use as a SCM source. Requires the Jenkins :jenkins-wiki:`Clone Workspace SCM Plugin @@ -1110,7 +1110,7 @@ def hg(self, xml_parent, data): "with browser.") -def openshift_img_streams(parser, xml_parent, data): +def openshift_img_streams(registry, xml_parent, data): """yaml: openshift-img-streams Rather than a Build step extension plugin, this is an extension of the Jenkins SCM plugin, where this baked-in polling mechanism provided by @@ -1165,7 +1165,7 @@ def openshift_img_streams(parser, xml_parent, data): convert_mapping_to_xml(scm, data, mapping, fail_required=True) -def bzr(parser, xml_parent, data): +def bzr(registry, xml_parent, data): """yaml: bzr Specifies the bzr SCM repository for this job. Requires the Jenkins :jenkins-wiki:`Bazaar Plugin `. @@ -1224,7 +1224,7 @@ def bzr(parser, xml_parent, data): data['opengrok-root-module']) -def url(parser, xml_parent, data): +def url(registry, xml_parent, data): """yaml: url Watch for changes in, and download an artifact from a particular url. @@ -1262,10 +1262,10 @@ class SCM(jenkins_jobs.modules.base.Base): component_type = 'scm' component_list_type = 'scm' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): scms_parent = XML.Element('scms') for scm in data.get('scm', []): - self.registry.dispatch('scm', parser, scms_parent, 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'}) diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index 270be46bb..aafac2dff 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -207,7 +207,7 @@ def build_gerrit_skip_votes(xml_parent, data): XML.SubElement(skip_vote_node, tag_name).text = 'false' -def gerrit(parser, xml_parent, data): +def gerrit(registry, xml_parent, data): """yaml: gerrit Trigger on a Gerrit event. @@ -614,7 +614,7 @@ def gerrit(parser, xml_parent, data): convert_mapping_to_xml(gtrig, data, message_mappings, fail_required=True) -def pollscm(parser, xml_parent, data): +def pollscm(registry, xml_parent, data): """yaml: pollscm Poll the SCM to determine if there has been a change. @@ -671,7 +671,7 @@ def build_content_type(xml_parent, entries, namespace, collection_suffix, XML.SubElement(content_entry, element_name).text = entry -def pollurl(parser, xml_parent, data): +def pollurl(registry, xml_parent, data): """yaml: pollurl Trigger when the HTTP response from a URL changes. Requires the Jenkins :jenkins-wiki:`URLTrigger Plugin `. @@ -773,7 +773,7 @@ def pollurl(parser, xml_parent, data): 'ContentEntry', *content_type[0:3]) -def timed(parser, xml_parent, data): +def timed(registry, xml_parent, data): """yaml: timed Trigger builds at certain times. @@ -788,7 +788,7 @@ def timed(parser, xml_parent, data): XML.SubElement(scmtrig, 'spec').text = data -def bitbucket(parser, xml_parent, data): +def bitbucket(registry, xml_parent, data): """yaml: bitbucket Trigger a job when bitbucket repository is pushed to. Requires the Jenkins :jenkins-wiki:`BitBucket Plugin @@ -803,7 +803,7 @@ def bitbucket(parser, xml_parent, data): XML.SubElement(bbtrig, 'spec').text = '' -def github(parser, xml_parent, data): +def github(registry, xml_parent, data): """yaml: github Trigger a job when github repository is pushed to. Requires the Jenkins :jenkins-wiki:`GitHub Plugin `. @@ -818,7 +818,7 @@ def github(parser, xml_parent, data): XML.SubElement(ghtrig, 'spec').text = '' -def github_pull_request(parser, xml_parent, data): +def github_pull_request(registry, xml_parent, data): """yaml: github-pull-request Build pull requests in github and report results. Requires the Jenkins :jenkins-wiki:`GitHub Pull Request Builder Plugin @@ -1025,7 +1025,7 @@ def github_pull_request(parser, xml_parent, data): XML.SubElement(error_comment_elem, 'result').text = 'ERROR' -def gitlab_merge_request(parser, xml_parent, data): +def gitlab_merge_request(registry, xml_parent, data): """yaml: gitlab-merge-request Build merge requests in gitlab and report results. Requires the Jenkins :jenkins-wiki:`Gitlab MergeRequest Builder Plugin. @@ -1057,7 +1057,7 @@ def gitlab_merge_request(parser, xml_parent, data): XML.SubElement(ghprb, '__projectPath').text = data.get('project-path') -def gitlab(parser, xml_parent, data): +def gitlab(registry, xml_parent, data): """yaml: gitlab Makes Jenkins act like a GitLab CI server. Requires the Jenkins :jenkins-wiki:`GitLab Plugin @@ -1148,7 +1148,7 @@ def gitlab(parser, xml_parent, data): gitlab = XML.SubElement( xml_parent, 'com.dabsquared.gitlabjenkins.GitLabPushTrigger' ) - plugin_info = parser.registry.get_plugin_info('GitLab Plugin') + plugin_info = registry.get_plugin_info('GitLab Plugin') plugin_ver = pkg_resources.parse_version(plugin_info.get('version', "0")) valid_merge_request = ['never', 'source', 'both'] @@ -1205,7 +1205,7 @@ def gitlab(parser, xml_parent, data): _add_xml(gitlab, xml_name, value) -def build_result(parser, xml_parent, data): +def build_result(registry, xml_parent, data): """yaml: build-result Configure jobB to monitor jobA build result. A build is scheduled if there is a new build result that matches your criteria (unstable, failure, ...). @@ -1272,7 +1272,7 @@ def build_result(parser, xml_parent, data): XML.SubElement(model_checked, 'checked').text = result_dict[result] -def reverse(parser, xml_parent, data): +def reverse(registry, xml_parent, data): """yaml: reverse This trigger can be configured in the UI using the checkbox with the following text: 'Build after other projects are built'. @@ -1327,7 +1327,7 @@ def reverse(parser, xml_parent, data): str(hudson_model.THRESHOLDS[result]['complete']).lower() -def monitor_folders(parser, xml_parent, data): +def monitor_folders(registry, xml_parent, data): """yaml: monitor-folders Configure Jenkins to monitor folders. Requires the Jenkins :jenkins-wiki:`Filesystem Trigger Plugin @@ -1370,7 +1370,7 @@ def monitor_folders(parser, xml_parent, data): not data.get('check-fewer', True)).lower() -def monitor_files(parser, xml_parent, data): +def monitor_files(registry, xml_parent, data): """yaml: monitor-files Configure Jenkins to monitor files. Requires the Jenkins :jenkins-wiki:`Filesystem Trigger Plugin @@ -1514,7 +1514,7 @@ def monitor_files(parser, xml_parent, data): file_info.get('ignore-modificaton-date', True)).lower() -def ivy(parser, xml_parent, data): +def ivy(registry, xml_parent, data): """yaml: ivy Poll with an Ivy script Requires the Jenkins :jenkins-wiki:`IvyTrigger Plugin @@ -1562,7 +1562,7 @@ def ivy(parser, xml_parent, data): XML.SubElement(it, 'triggerLabel').text = label -def script(parser, xml_parent, data): +def script(registry, xml_parent, data): """yaml: script Triggers the job using shell or batch script. Requires the Jenkins :jenkins-wiki:`ScriptTrigger Plugin @@ -1607,7 +1607,7 @@ def script(parser, xml_parent, data): XML.SubElement(st, 'triggerLabel').text = label -def groovy_script(parser, xml_parent, data): +def groovy_script(registry, xml_parent, data): """yaml: groovy-script Triggers the job using a groovy script. Requires the Jenkins :jenkins-wiki:`ScriptTrigger Plugin @@ -1659,7 +1659,7 @@ def groovy_script(parser, xml_parent, data): XML.SubElement(gst, 'triggerLabel').text = label -def rabbitmq(parser, xml_parent, data): +def rabbitmq(registry, xml_parent, data): """yaml: rabbitmq This plugin triggers build using remote build message in RabbitMQ queue. Requires the Jenkins :jenkins-wiki:`RabbitMQ Build Trigger Plugin @@ -1693,11 +1693,11 @@ class Triggers(jenkins_jobs.modules.base.Base): component_type = 'trigger' component_list_type = 'triggers' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): triggers = data.get('triggers', []) if not triggers: return trig_e = XML.SubElement(xml_parent, 'triggers', {'class': 'vector'}) for trigger in triggers: - self.registry.dispatch('trigger', parser, trig_e, trigger) + self.registry.dispatch('trigger', trig_e, trigger) diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index 060ef2aa0..991ba71c4 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -44,7 +44,7 @@ logger = logging.getLogger(__name__) MIN_TO_SEC = 60 -def docker_custom_build_env(parser, xml_parent, data): +def docker_custom_build_env(registry, xml_parent, data): """yaml: docker-custom-build-env Allows the definition of a build environment for a job using a Docker container. @@ -155,7 +155,7 @@ def docker_custom_build_env(parser, xml_parent, data): XML.SubElement(entry_xml, 'net').text = data.get('net', 'bridge') -def ci_skip(parser, xml_parent, data): +def ci_skip(registry, xml_parent, data): """yaml: ci-skip Skip making a build for certain push. Just add [ci skip] into your commit's message to let Jenkins know, @@ -183,7 +183,7 @@ def ci_skip(parser, xml_parent, data): }) -def config_file_provider(parser, xml_parent, data): +def config_file_provider(registry, xml_parent, data): """yaml: config-file-provider Provide configuration files (i.e., settings.xml for maven etc.) which will be copied to the job's workspace. @@ -212,7 +212,7 @@ def config_file_provider(parser, xml_parent, data): config_file_provider_builder(cfp, data) -def logfilesize(parser, xml_parent, data): +def logfilesize(registry, xml_parent, data): """yaml: logfilesize Abort the build if its logfile becomes too big. Requires the Jenkins :jenkins-wiki:`Logfilesizechecker Plugin @@ -246,7 +246,7 @@ def logfilesize(parser, xml_parent, data): convert_mapping_to_xml(lfswrapper, data, mapping, fail_required=True) -def timeout(parser, xml_parent, data): +def timeout(registry, xml_parent, data): """yaml: timeout Abort the build if it runs too long. Requires the Jenkins :jenkins-wiki:`Build Timeout Plugin @@ -310,7 +310,7 @@ def timeout(parser, xml_parent, data): prefix = 'hudson.plugins.build__timeout.' twrapper = XML.SubElement(xml_parent, prefix + 'BuildTimeoutWrapper') - plugin_info = parser.registry.get_plugin_info( + plugin_info = registry.get_plugin_info( "Jenkins build timeout plugin") version = pkg_resources.parse_version(plugin_info.get("version", "0")) @@ -425,7 +425,7 @@ def timeout(parser, xml_parent, data): XML.SubElement(twrapper, 'timeoutType').text = tout_type -def timestamps(parser, xml_parent, data): +def timestamps(registry, xml_parent, data): """yaml: timestamps Add timestamps to the console log. Requires the Jenkins :jenkins-wiki:`Timestamper Plugin `. @@ -439,7 +439,7 @@ def timestamps(parser, xml_parent, data): 'hudson.plugins.timestamper.TimestamperBuildWrapper') -def ansicolor(parser, xml_parent, data): +def ansicolor(registry, xml_parent, data): """yaml: ansicolor Translate ANSI color codes to HTML in the console log. Requires the Jenkins :jenkins-wiki:`Ansi Color Plugin `. @@ -466,7 +466,7 @@ def ansicolor(parser, xml_parent, data): XML.SubElement(cwrapper, 'colorMapName').text = colormap -def build_keeper(parser, xml_parent, data): +def build_keeper(registry, xml_parent, data): """yaml: build-keeper Keep builds based on specific policy. Requires the Jenkins :jenkins-wiki:`Build Keeper Plugin @@ -539,7 +539,7 @@ def build_keeper(parser, xml_parent, data): InvalidAttributeError('policy', policy, valid_policies) -def live_screenshot(parser, xml_parent, data): +def live_screenshot(registry, xml_parent, data): """yaml: live-screenshot Show live screenshots of running jobs in the job list. Requires the Jenkins :jenkins-wiki:`Live-Screenshot Plugin @@ -571,7 +571,7 @@ def live_screenshot(parser, xml_parent, data): convert_mapping_to_xml(live, data, mapping, fail_required=True) -def mask_passwords(parser, xml_parent, data): +def mask_passwords(registry, xml_parent, data): """yaml: mask-passwords Hide passwords in the console log. Requires the Jenkins :jenkins-wiki:`Mask Passwords Plugin @@ -587,7 +587,7 @@ def mask_passwords(parser, xml_parent, data): 'MaskPasswordsBuildWrapper') -def workspace_cleanup(parser, xml_parent, data): +def workspace_cleanup(registry, xml_parent, data): """yaml: workspace-cleanup (pre-build) Requires the Jenkins :jenkins-wiki:`Workspace Cleanup Plugin @@ -636,7 +636,7 @@ def workspace_cleanup(parser, xml_parent, data): data.get('external-deletion-command', '')) -def m2_repository_cleanup(parser, xml_parent, data): +def m2_repository_cleanup(registry, xml_parent, data): """yaml: m2-repository-cleanup Configure M2 Repository Cleanup Requires the Jenkins :jenkins-wiki:`M2 Repository Cleanup @@ -664,7 +664,7 @@ def m2_repository_cleanup(parser, xml_parent, data): XML.SubElement(p, 'string').text = pattern -def rvm_env(parser, xml_parent, data): +def rvm_env(registry, xml_parent, data): """yaml: rvm-env Set the RVM implementation Requires the Jenkins :jenkins-wiki:`Rvm Plugin `. @@ -703,7 +703,7 @@ def rvm_env(parser, xml_parent, data): 'ruby-class': 'String'}).text = "rvm" -def rbenv(parser, xml_parent, data): +def rbenv(registry, xml_parent, data): """yaml: rbenv Set the rbenv implementation. Requires the Jenkins :jenkins-wiki:`rbenv plugin `. @@ -788,7 +788,7 @@ def rbenv(parser, xml_parent, data): 'pluginid': 'rbenv'}) -def build_name(parser, xml_parent, data): +def build_name(registry, xml_parent, data): """yaml: build-name Set the name of the build Requires the Jenkins :jenkins-wiki:`Build Name Setter Plugin @@ -810,7 +810,7 @@ def build_name(parser, xml_parent, data): XML.SubElement(bsetter, 'template').text = data['name'] -def port_allocator(parser, xml_parent, data): +def port_allocator(registry, xml_parent, data): """yaml: port-allocator Assign unique TCP port numbers Requires the Jenkins :jenkins-wiki:`Port Allocator Plugin @@ -841,7 +841,7 @@ def port_allocator(parser, xml_parent, data): XML.SubElement(dpt, 'name').text = name -def locks(parser, xml_parent, data): +def locks(registry, xml_parent, data): """yaml: locks Control parallel execution of jobs. Requires the Jenkins :jenkins-wiki:`Locks and Latches Plugin @@ -866,7 +866,7 @@ def locks(parser, xml_parent, data): XML.SubElement(lockwrapper, 'name').text = lock -def copy_to_slave(parser, xml_parent, data): +def copy_to_slave(registry, xml_parent, data): """yaml: copy-to-slave Copy files to slave before build Requires the Jenkins :jenkins-wiki:`Copy To Slave Plugin @@ -912,7 +912,7 @@ def copy_to_slave(parser, xml_parent, data): XML.SubElement(cs, 'hudsonHomeRelative').text = 'false' -def inject(parser, xml_parent, data): +def inject(registry, xml_parent, data): """yaml: inject Add or override environment variables to the whole build process Requires the Jenkins :jenkins-wiki:`EnvInject Plugin `. @@ -944,7 +944,7 @@ def inject(parser, xml_parent, data): XML.SubElement(info, 'loadFilesFromMaster').text = 'false' -def inject_ownership_variables(parser, xml_parent, data): +def inject_ownership_variables(registry, xml_parent, data): """yaml: inject-ownership-variables Inject ownership variables to the build as environment variables. Requires the Jenkins :jenkins-wiki:`EnvInject Plugin ` @@ -968,7 +968,7 @@ def inject_ownership_variables(parser, xml_parent, data): str(data.get('job-variables', False)).lower() -def inject_passwords(parser, xml_parent, data): +def inject_passwords(registry, xml_parent, data): """yaml: inject-passwords Inject passwords to the build as environment variables. Requires the Jenkins :jenkins-wiki:`EnvInject Plugin `. @@ -999,7 +999,7 @@ def inject_passwords(parser, xml_parent, data): XML.SubElement(entry, 'value').text = password['password'] -def env_file(parser, xml_parent, data): +def env_file(registry, xml_parent, data): """yaml: env-file Add or override environment variables to the whole build process Requires the Jenkins :jenkins-wiki:`Environment File Plugin @@ -1019,7 +1019,7 @@ def env_file(parser, xml_parent, data): eib, 'filePath', data.get('properties-file')) -def env_script(parser, xml_parent, data): +def env_script(registry, xml_parent, data): """yaml: env-script Add or override environment variables to the whole build process. Requires the Jenkins :jenkins-wiki:`Environment Script Plugin @@ -1058,7 +1058,7 @@ def env_script(parser, xml_parent, data): XML.SubElement(el, 'onlyRunOnParent').text = only_on_parent -def jclouds(parser, xml_parent, data): +def jclouds(registry, xml_parent, data): """yaml: jclouds Uses JClouds to provide slave launching on most of the currently usable Cloud infrastructures. @@ -1111,7 +1111,7 @@ def jclouds(parser, xml_parent, data): 'JCloudsOneOffSlave') -def openstack(parser, xml_parent, data): +def openstack(registry, xml_parent, data): """yaml: openstack Provision slaves from OpenStack on demand. Requires the Jenkins :jenkins-wiki:`Openstack Cloud Plugin `. @@ -1172,7 +1172,7 @@ def openstack(parser, xml_parent, data): XML.SubElement(xml_parent, tag_prefix + 'JCloudsOneOffSlave') -def build_user_vars(parser, xml_parent, data): +def build_user_vars(registry, xml_parent, data): """yaml: build-user-vars Set environment variables to the value of the user that started the build. Requires the Jenkins :jenkins-wiki:`Build User Vars Plugin @@ -1186,7 +1186,7 @@ def build_user_vars(parser, xml_parent, data): XML.SubElement(xml_parent, 'org.jenkinsci.plugins.builduser.BuildUser') -def release(parser, xml_parent, data): +def release(registry, xml_parent, data): """yaml: release Add release build configuration Requires the Jenkins :jenkins-wiki:`Release Plugin `. @@ -1222,7 +1222,7 @@ def release(parser, xml_parent, data): if parameters: pdef = XML.SubElement(relwrap, 'parameterDefinitions') for param in parameters: - parser.registry.dispatch('parameter', parser, pdef, param) + registry.dispatch('parameter', pdef, param) builder_steps = { 'pre-build': 'preBuildSteps', @@ -1232,13 +1232,12 @@ def release(parser, xml_parent, data): } for step in builder_steps.keys(): for builder in data.get(step, []): - parser.registry.dispatch('builder', parser, - XML.SubElement(relwrap, - builder_steps[step]), - builder) + registry.dispatch('builder', + XML.SubElement(relwrap, builder_steps[step]), + builder) -def sauce_ondemand(parser, xml_parent, data): +def sauce_ondemand(registry, xml_parent, data): """yaml: sauce-ondemand Allows you to integrate Sauce OnDemand with Jenkins. You can automate the setup and tear down of Sauce Connect and integrate @@ -1342,7 +1341,7 @@ def sauce_ondemand(parser, xml_parent, data): XML.SubElement(sauce, 'options').text = options -def pathignore(parser, xml_parent, data): +def pathignore(registry, xml_parent, data): """yaml: pathignore This plugin allows SCM-triggered jobs to ignore build requests if only certain paths have changed. @@ -1378,7 +1377,7 @@ def pathignore(parser, xml_parent, data): }) -def pre_scm_buildstep(parser, xml_parent, data): +def pre_scm_buildstep(registry, xml_parent, data): """yaml: pre-scm-buildstep Execute a Build Step before running the SCM Requires the Jenkins :jenkins-wiki:`pre-scm-buildstep `. @@ -1408,11 +1407,11 @@ def pre_scm_buildstep(parser, xml_parent, data): 'PreSCMBuildStepsWrapper') bs = XML.SubElement(bsp, 'buildSteps') for step in data: - for edited_node in create_builders(parser, step): + for edited_node in create_builders(registry, step): bs.append(edited_node) -def logstash(parser, xml_parent, data): +def logstash(registry, xml_parent, data): """yaml: logstash build wrapper Dump the Jenkins console output to Logstash Requires the Jenkins :jenkins-wiki:`logstash plugin `. @@ -1471,7 +1470,7 @@ def logstash(parser, xml_parent, data): key_sub_element.text = str(redis_config.get('key', 'logstash')) -def mongo_db(parser, xml_parent, data): +def mongo_db(registry, xml_parent, data): """yaml: mongo-db build wrapper Initalizes a MongoDB database while running the build. Requires the Jenkins :jenkins-wiki:`MongoDB plugin `. @@ -1506,7 +1505,7 @@ def mongo_db(parser, xml_parent, data): convert_mapping_to_xml(mongodb, data, mapping, fail_required=True) -def delivery_pipeline(parser, xml_parent, data): +def delivery_pipeline(registry, xml_parent, data): """yaml: delivery-pipeline If enabled the job will create a version based on the template. The version will be set to the environment variable PIPELINE_VERSION and @@ -1543,7 +1542,7 @@ def delivery_pipeline(parser, xml_parent, data): convert_mapping_to_xml(pvc, data, mapping, fail_required=True) -def matrix_tie_parent(parser, xml_parent, data): +def matrix_tie_parent(registry, xml_parent, data): """yaml: matrix-tie-parent Tie parent to a node. Requires the Jenkins :jenkins-wiki:`Matrix Tie Parent Plugin @@ -1563,7 +1562,7 @@ def matrix_tie_parent(parser, xml_parent, data): XML.SubElement(mtp, 'labelName').text = data['node'] -def exclusion(parser, xml_parent, data): +def exclusion(registry, xml_parent, data): """yaml: exclusion Add a resource to use for critical sections to establish a mutex on. If another job specifies the same resource, the second job will wait for the @@ -1590,7 +1589,7 @@ def exclusion(parser, xml_parent, data): XML.SubElement(dit, 'name').text = str(resource).upper() -def ssh_agent_credentials(parser, xml_parent, data): +def ssh_agent_credentials(registry, xml_parent, data): """yaml: ssh-agent-credentials Sets up the user for the ssh agent plugin for jenkins. @@ -1658,7 +1657,7 @@ def ssh_agent_credentials(parser, xml_parent, data): XML.SubElement(entry_xml, xml_key).text = user -def credentials_binding(parser, xml_parent, data): +def credentials_binding(registry, xml_parent, data): """yaml: credentials-binding Binds credentials to environment variables using the credentials binding plugin for jenkins. @@ -1762,7 +1761,7 @@ def credentials_binding(parser, xml_parent, data): credential_xml.text = params.get('credential-id') -def custom_tools(parser, xml_parent, data): +def custom_tools(registry, xml_parent, data): """yaml: custom-tools Requires the Jenkins :jenkins-wiki:`Custom Tools Plugin `. @@ -1800,7 +1799,7 @@ def custom_tools(parser, xml_parent, data): 'convertHomesToUppercase').text = convert_home -def nodejs_installator(parser, xml_parent, data): +def nodejs_installator(registry, xml_parent, data): """yaml: nodejs-installator Requires the Jenkins :jenkins-wiki:`NodeJS Plugin `. @@ -1822,7 +1821,7 @@ def nodejs_installator(parser, xml_parent, data): raise MissingAttributeError(e.args[0]) -def xvnc(parser, xml_parent, data): +def xvnc(registry, xml_parent, data): """yaml: xvnc Enable xvnc during the build. Requires the Jenkins :jenkins-wiki:`xvnc plugin `. @@ -1852,7 +1851,7 @@ def xvnc(parser, xml_parent, data): convert_mapping_to_xml(xwrapper, data, mapping, fail_required=True) -def job_log_logger(parser, xml_parent, data): +def job_log_logger(registry, xml_parent, data): """yaml: job-log-logger Enable writing the job log to the underlying logging system. Requires the Jenkins :jenkins-wiki:`Job Log Logger plugin @@ -1873,7 +1872,7 @@ def job_log_logger(parser, xml_parent, data): data.get('suppress-empty', True)).lower() -def xvfb(parser, xml_parent, data): +def xvfb(registry, xml_parent, data): """yaml: xvfb Enable xvfb during the build. Requires the Jenkins :jenkins-wiki:`Xvfb Plugin `. @@ -1934,7 +1933,7 @@ def xvfb(parser, xml_parent, data): 'shutdown-with-build', False)).lower() -def android_emulator(parser, xml_parent, data): +def android_emulator(registry, xml_parent, data): """yaml: android-emulator Automates many Android development tasks including SDK installation, build file generation, emulator creation and launch, @@ -2020,7 +2019,7 @@ def android_emulator(parser, xml_parent, data): XML.SubElement(root, 'executable').text = str(data.get('exe', '')) -def artifactory_maven(parser, xml_parent, data): +def artifactory_maven(registry, xml_parent, data): """yaml: artifactory-maven Wrapper for non-Maven projects. Requires the :jenkins-wiki:`Artifactory Plugin ` @@ -2065,7 +2064,7 @@ def artifactory_maven(parser, xml_parent, data): 'release-repo-key', '') -def artifactory_generic(parser, xml_parent, data): +def artifactory_generic(registry, xml_parent, data): """yaml: artifactory-generic Wrapper for non-Maven projects. Requires the :jenkins-wiki:`Artifactory Plugin ` @@ -2124,7 +2123,7 @@ def artifactory_generic(parser, xml_parent, data): artifactory_common_details(details, data) # Get plugin information to maintain backwards compatibility - info = parser.registry.get_plugin_info('artifactory') + info = registry.get_plugin_info('artifactory') version = pkg_resources.parse_version(info.get('version', '0')) if version >= pkg_resources.parse_version('2.3.0'): @@ -2161,7 +2160,7 @@ def artifactory_generic(parser, xml_parent, data): artifactory_env_vars_patterns(artifactory, data) -def artifactory_maven_freestyle(parser, xml_parent, data): +def artifactory_maven_freestyle(registry, xml_parent, data): """yaml: artifactory-maven-freestyle Wrapper for Free Stype projects. Requires the Artifactory plugin. Requires :jenkins-wiki:`Artifactory Plugin ` @@ -2305,7 +2304,7 @@ def artifactory_maven_freestyle(parser, xml_parent, data): artifactory_optional_props(artifactory, data, 'wrappers') -def maven_release(parser, xml_parent, data): +def maven_release(registry, xml_parent, data): """yaml: maven-release Wrapper for Maven projects Requires :jenkins-wiki:`M2 Release Plugin ` @@ -2357,8 +2356,8 @@ class Wrappers(jenkins_jobs.modules.base.Base): component_type = 'wrapper' component_list_type = 'wrappers' - def gen_xml(self, parser, xml_parent, data): + def gen_xml(self, xml_parent, data): wrappers = XML.SubElement(xml_parent, 'buildWrappers') for wrap in data.get('wrappers', []): - self.registry.dispatch('wrapper', parser, wrappers, wrap) + self.registry.dispatch('wrapper', wrappers, wrap) diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py index f88d341dc..d9194fd1e 100644 --- a/jenkins_jobs/parser.py +++ b/jenkins_jobs/parser.py @@ -27,7 +27,6 @@ from jenkins_jobs.constants import MAGIC_MANAGE_STRING from jenkins_jobs.errors import JenkinsJobsException from jenkins_jobs.formatter import deep_format import jenkins_jobs.local_yaml as local_yaml -from jenkins_jobs.registry import ModuleRegistry from jenkins_jobs import utils from jenkins_jobs.xml_config import XmlJob @@ -71,7 +70,7 @@ def combination_matches(combination, match_combinations): class YamlParser(object): - def __init__(self, jjb_config=None, plugins_info=None): + def __init__(self, jjb_config=None): self.data = {} self.jobs = [] self.xml_jobs = [] @@ -80,9 +79,6 @@ class YamlParser(object): self.keep_desc = jjb_config.yamlparser['keep_descriptions'] self.path = jjb_config.yamlparser['include_path'] - self.registry = ModuleRegistry(jjb_config, - plugins_info) - def load_files(self, fn): # handle deprecated behavior, and check that it's not a file like @@ -220,11 +216,11 @@ class YamlParser(object): job["description"] = description + \ self._get_managed_string().lstrip() - def expandYaml(self, jobs_glob=None): + def expandYaml(self, registry, jobs_glob=None): changed = True while changed: changed = False - for module in self.registry.modules: + for module in registry.modules: if hasattr(module, 'handle_data'): if module.handle_data(self.data): changed = True @@ -372,23 +368,23 @@ class YamlParser(object): # project does not otherwise have a description. return "\n\n" + MAGIC_MANAGE_STRING - def generateXML(self): + def generateXML(self, registry): for job in self.jobs: - self.xml_jobs.append(self.getXMLForJob(job)) + self.xml_jobs.append(self.getXMLForJob(job, registry)) - def getXMLForJob(self, data): + def getXMLForJob(self, data, registry): kind = data.get('project-type', 'freestyle') for ep in pkg_resources.iter_entry_points( group='jenkins_jobs.projects', name=kind): Mod = ep.load() - mod = Mod(self.registry) + mod = Mod(registry) xml = mod.root_xml(data) - self.gen_xml(xml, data) + self.gen_xml(xml, data, registry) job = XmlJob(xml, data['name']) return job - def gen_xml(self, xml, data): - for module in self.registry.modules: + def gen_xml(self, xml, data, registry): + for module in registry.modules: if hasattr(module, 'gen_xml'): - module.gen_xml(self, xml, data) + module.gen_xml(xml, data) diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py index 66fd20637..433e61787 100644 --- a/jenkins_jobs/registry.py +++ b/jenkins_jobs/registry.py @@ -118,8 +118,14 @@ class ModuleRegistry(object): def getHandler(self, category, name): return self.handlers[category][name] - def dispatch(self, component_type, - parser, xml_parent, + @property + def parser_data(self): + return self.__parser_data + + def set_parser_data(self, parser_data): + self.__parser_data = parser_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 @@ -219,7 +225,7 @@ class ModuleRegistry(object): component_list_type, eps) # check for macro first - component = parser.data.get(component_type, {}).get(name) + component = self.parser_data.get(component_type, {}).get(name) if component: if name in eps and name not in self.masked_warned: # Warn only once for each macro @@ -232,11 +238,10 @@ class ModuleRegistry(object): # Pass component_data in as template data to this function # so that if the macro is invoked with arguments, # the arguments are interpolated into the real defn. - self.dispatch(component_type, - parser, xml_parent, b, component_data) + self.dispatch(component_type, xml_parent, b, component_data) elif name in eps: func = eps[name].load() - func(parser, xml_parent, component_data) + func(self, xml_parent, component_data) else: raise JenkinsJobsException("Unknown entry point or macro '{0}' " "for component type: '{1}'.". diff --git a/tests/base.py b/tests/base.py index c4737f5f2..661656950 100644 --- a/tests/base.py +++ b/tests/base.py @@ -40,6 +40,7 @@ from jenkins_jobs.modules import project_matrix from jenkins_jobs.modules import project_maven from jenkins_jobs.modules import project_multijob from jenkins_jobs.parser import YamlParser +from jenkins_jobs.registry import ModuleRegistry from jenkins_jobs.xml_config import XmlJob # This dance deals with the fact that we want unittest.mock if @@ -152,22 +153,24 @@ class BaseTestCase(LoggingFixture): self.addDetail("plugins-info", text_content(str(plugins_info))) - parser = YamlParser(jjb_config, plugins_info) + parser = YamlParser(jjb_config) + registry = ModuleRegistry(jjb_config, plugins_info) + registry.set_parser_data(parser.data) - pub = self.klass(parser.registry) + pub = self.klass(registry) project = None if ('project-type' in yaml_content): if (yaml_content['project-type'] == "maven"): - project = project_maven.Maven(parser.registry) + project = project_maven.Maven(registry) elif (yaml_content['project-type'] == "matrix"): - project = project_matrix.Matrix(parser.registry) + project = project_matrix.Matrix(registry) elif (yaml_content['project-type'] == "flow"): - project = project_flow.Flow(parser.registry) + project = project_flow.Flow(registry) elif (yaml_content['project-type'] == "multijob"): - project = project_multijob.MultiJob(parser.registry) + project = project_multijob.MultiJob(registry) elif (yaml_content['project-type'] == "externaljob"): - project = project_externaljob.ExternalJob(parser.registry) + project = project_externaljob.ExternalJob(registry) if project: xml_project = project.root_xml(yaml_content) @@ -175,7 +178,7 @@ class BaseTestCase(LoggingFixture): xml_project = XML.Element('project') # Generate the XML tree directly with modules/general - pub.gen_xml(parser, xml_project, yaml_content) + pub.gen_xml(xml_project, yaml_content) # Prettify generated XML pretty_xml = XmlJob(xml_project, 'fixturejob').output().decode('utf-8') @@ -197,9 +200,11 @@ class SingleJobTestCase(BaseTestCase): parser = YamlParser(config) parser.parse(self.in_filename) + registry = ModuleRegistry(config) + registry.set_parser_data(parser.data) # Generate the XML tree - parser.expandYaml() - parser.generateXML() + parser.expandYaml(registry) + parser.generateXML(registry) parser.xml_jobs.sort(key=operator.attrgetter('name')) diff --git a/tests/cmd/subcommands/test_test.py b/tests/cmd/subcommands/test_test.py index 8db1eddca..64aa21167 100644 --- a/tests/cmd/subcommands/test_test.py +++ b/tests/cmd/subcommands/test_test.py @@ -131,7 +131,7 @@ class TestTests(CmdTestsBase): self.assertIn("'ascii' codec can't encode character", str(e)) @mock.patch('jenkins_jobs.cli.subcommand.update.YamlParser.generateXML') - @mock.patch('jenkins_jobs.parser.ModuleRegistry') + @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. @@ -155,7 +155,7 @@ class TestTests(CmdTestsBase): plugins_info_list) @mock.patch('jenkins_jobs.cli.subcommand.update.YamlParser.generateXML') - @mock.patch('jenkins_jobs.parser.ModuleRegistry') + @mock.patch('jenkins_jobs.cli.subcommand.update.ModuleRegistry') def test_bogus_plugins_info_stub_option(self, registry_mock, generateXML_mock): """