diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index 338b633a6..fffed89b9 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -611,19 +611,19 @@ def repo(parser, xml_parent, data): Specifies the repo SCM repository for this job. Requires the Jenkins :jenkins-wiki:`Repo Plugin `. - :arg str manifest-url: URL of the repo manifest - :arg str manifest-branch: The branch of the manifest to use (optional) + :arg str manifest-url: URL of the repo manifest (required) + :arg str manifest-branch: The branch of the manifest to use (default '') :arg str manifest-file: Initial manifest file to use when initialising - (optional) + (default '') :arg str manifest-group: Only retrieve those projects in the manifest - tagged with the provided group name (optional) + tagged with the provided group name (default '') :arg list(str) ignore-projects: a list of projects in which changes would - not be considered to trigger a build when pooling (optional) + not be considered to trigger a build when pooling (default '') :arg str destination-dir: Location relative to the workspace root to clone - under (optional) - :arg str repo-url: custom url to retrieve the repo application (optional) + under (default '') + :arg str repo-url: custom url to retrieve the repo application (default '') :arg str mirror-dir: Path to mirror directory to reference when - initialising (optional) + initialising (default '') :arg int jobs: Number of projects to fetch simultaneously (default 0) :arg int depth: Specify the depth in history to sync from the source. The default is to sync all of the history. Use 1 to just sync the most @@ -643,7 +643,7 @@ def repo(parser, xml_parent, data): :arg bool show-all-changes: When this is checked --first-parent is no longer passed to git log when determining changesets (default false) :arg str local-manifest: Contents of .repo/local_manifest.xml, written - prior to calling sync (optional) + prior to calling sync (default '') Example: @@ -653,43 +653,27 @@ def repo(parser, xml_parent, data): scm = XML.SubElement(xml_parent, 'scm', {'class': 'hudson.plugins.repo.RepoScm'}) - if 'manifest-url' in data: - XML.SubElement(scm, 'manifestRepositoryUrl').text = \ - data['manifest-url'] - else: - raise JenkinsJobsException("Must specify a manifest url") - mapping = [ # option, xml name, default value - ("manifest-branch", 'manifestBranch', ''), - ("manifest-file", 'manifestFile', ''), - ("manifest-group", 'manifestGroup', ''), - ("destination-dir", 'destinationDir', ''), - ("repo-url", 'repoUrl', ''), - ("mirror-dir", 'mirrorDir', ''), - ("jobs", 'jobs', 0), - ("depth", 'depth', 0), - ("current-branch", 'currentBranch', True), - ("reset-first", 'resetFirst', False), - ("quiet", 'quiet', True), - ("force-sync", 'forceSync', False), - ("no-tags", 'noTags', False), - ("trace", 'trace', False), - ("show-all-changes", 'showAllChanges', False), - ("local-manifest", 'localManifest', ''), + ('manifest-url', 'manifestRepositoryUrl', None), + ('manifest-branch', 'manifestBranch', ''), + ('manifest-file', 'manifestFile', ''), + ('manifest-group', 'manifestGroup', ''), + ('destination-dir', 'destinationDir', ''), + ('repo-url', 'repoUrl', ''), + ('mirror-dir', 'mirrorDir', ''), + ('jobs', 'jobs', 0), + ('depth', 'depth', 0), + ('current-branch', 'currentBranch', True), + ('reset-first', 'resetFirst', False), + ('quiet', 'quiet', True), + ('force-sync', 'forceSync', False), + ('no-tags', 'noTags', False), + ('trace', 'trace', False), + ('show-all-changes', 'showAllChanges', False), + ('local-manifest', 'localManifest', ''), ] - - for elem in mapping: - (optname, xmlname, val) = elem - val = data.get(optname, val) - # Skip adding xml entry if default is empty string and no value given - if not val and elem[2] is '': - continue - xe = XML.SubElement(scm, xmlname) - if type(elem[2]) == bool: - xe.text = str(val).lower() - else: - xe.text = str(val) + convert_mapping_to_xml(scm, data, mapping, fail_required=True) # ignore-projects does not follow the same pattern of the other parameters, # so process it here: diff --git a/tests/macros/fixtures/scm/multi-scms002.xml b/tests/macros/fixtures/scm/multi-scms002.xml index aafbc0574..9e15c2f30 100644 --- a/tests/macros/fixtures/scm/multi-scms002.xml +++ b/tests/macros/fixtures/scm/multi-scms002.xml @@ -27,6 +27,7 @@ false false false +