From badab0264717db63a0b048df95910b9f90c3710d Mon Sep 17 00:00:00 2001 From: Bao Nguyen Date: Thu, 8 Jun 2017 19:04:46 -0700 Subject: Add `do-not-fetch-tags` to CloneOption for Git In one of the recent change to Git plugin behavior[1], tags are also search as part of branches. This cause projects that build on all branches to also build on all tags. This change allowing for tags to be ignored. Default this option is false and missing from XML output. [1] https://github.com/jenkinsci/git-plugin/pull/340 [2] https://github.com/jenkinsci/git-plugin/commit/bfeda3e661531bd9baec937ec4a4944ac482692c Change-Id: I2ed2290f9ef8ecd0d9e96aad1d7cbce2964bf2da --- jenkins_jobs/modules/scm.py | 12 ++++++++++- tests/scm/fixtures/git-cloneoptions01.xml | 34 ++++++++++++++++++++++++++++++ tests/scm/fixtures/git-cloneoptions01.yaml | 6 ++++++ tests/scm/fixtures/git002.xml | 1 + tests/scm/fixtures/git002.yaml | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/scm/fixtures/git-cloneoptions01.xml create mode 100644 tests/scm/fixtures/git-cloneoptions01.yaml diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index dbbfc8e9..a7c50e69 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -170,6 +170,8 @@ def git(registry, xml_parent, data): * **scm-name** (`string`) - The unique scm name for this Git SCM (optional) * **shallow-clone** (`bool`) - Perform shallow clone (default false) + * **do-not-fetch-tags** (`bool`) - Perform a clone without tags + (default false) * **sparse-checkout** (`dict`) * **paths** (`list`) - List of paths to sparse checkout. (optional) * **submodule** (`dict`) @@ -373,10 +375,18 @@ def git(registry, xml_parent, data): if 'scm-name' in data: ext = XML.SubElement(exts_node, impl_prefix + 'ScmName') XML.SubElement(ext, 'name').text = str(data['scm-name']) - if 'shallow-clone' in data or 'timeout' in data: + clone_options = ( + "shallow-clone", + "timeout", + "do-not-fetch-tags" + ) + if any(key in data for key in clone_options): clo = XML.SubElement(exts_node, impl_prefix + 'CloneOption') XML.SubElement(clo, 'shallow').text = str( data.get('shallow-clone', False)).lower() + if 'do-not-fetch-tags' in data: + XML.SubElement(clo, 'noTags').text = str( + data.get('do-not-fetch-tags', False)).lower() if 'timeout' in data: XML.SubElement(clo, 'timeout').text = str(data['timeout']) if 'sparse-checkout' in data: diff --git a/tests/scm/fixtures/git-cloneoptions01.xml b/tests/scm/fixtures/git-cloneoptions01.xml new file mode 100644 index 00000000..0de9fccc --- /dev/null +++ b/tests/scm/fixtures/git-cloneoptions01.xml @@ -0,0 +1,34 @@ + + + + 2 + + + origin + +refs/heads/*:refs/remotes/origin/* + https://github.com/openstack-infra/jenkins-job-builder.git + + + + + master + + + false + false + false + false + Default + + + + + + + false + true + + + + + diff --git a/tests/scm/fixtures/git-cloneoptions01.yaml b/tests/scm/fixtures/git-cloneoptions01.yaml new file mode 100644 index 00000000..5a6a8f3d --- /dev/null +++ b/tests/scm/fixtures/git-cloneoptions01.yaml @@ -0,0 +1,6 @@ +scm: + - git: + url: https://github.com/openstack-infra/jenkins-job-builder.git + branches: + - master + do-not-fetch-tags: true diff --git a/tests/scm/fixtures/git002.xml b/tests/scm/fixtures/git002.xml index fcd474b1..3f487551 100644 --- a/tests/scm/fixtures/git002.xml +++ b/tests/scm/fixtures/git002.xml @@ -35,6 +35,7 @@ false + false 20 diff --git a/tests/scm/fixtures/git002.yaml b/tests/scm/fixtures/git002.yaml index 9376df58..c1d37a02 100644 --- a/tests/scm/fixtures/git002.yaml +++ b/tests/scm/fixtures/git002.yaml @@ -7,6 +7,7 @@ scm: browser: githubweb browser-url: http://github.com/foo/example.git timeout: 20 + do-not-fetch-tags: false changelog-against: remote: origin branch: master -- cgit