summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBao Nguyen <bao@fastly.com>2017-06-08 19:04:46 -0700
committerBao Nguyen <ngqbao@gmail.com>2017-06-11 10:36:33 -0700
commitbadab0264717db63a0b048df95910b9f90c3710d (patch)
treeddeedc21b033f465050b09c11b2add5e71fbd6dd
parent3985a338c464437b07985da7a264d75d2cbbd711 (diff)
downloadpython-jenkins-job-builder-badab0264717db63a0b048df95910b9f90c3710d.tar.gz
python-jenkins-job-builder-badab0264717db63a0b048df95910b9f90c3710d.tar.xz
python-jenkins-job-builder-badab0264717db63a0b048df95910b9f90c3710d.zip
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
-rw-r--r--jenkins_jobs/modules/scm.py12
-rw-r--r--tests/scm/fixtures/git-cloneoptions01.xml34
-rw-r--r--tests/scm/fixtures/git-cloneoptions01.yaml6
-rw-r--r--tests/scm/fixtures/git002.xml1
-rw-r--r--tests/scm/fixtures/git002.yaml1
5 files changed, 53 insertions, 1 deletions
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+ <scm class="hudson.plugins.git.GitSCM">
+ <configVersion>2</configVersion>
+ <userRemoteConfigs>
+ <hudson.plugins.git.UserRemoteConfig>
+ <name>origin</name>
+ <refspec>+refs/heads/*:refs/remotes/origin/*</refspec>
+ <url>https://github.com/openstack-infra/jenkins-job-builder.git</url>
+ </hudson.plugins.git.UserRemoteConfig>
+ </userRemoteConfigs>
+ <branches>
+ <hudson.plugins.git.BranchSpec>
+ <name>master</name>
+ </hudson.plugins.git.BranchSpec>
+ </branches>
+ <disableSubmodules>false</disableSubmodules>
+ <recursiveSubmodules>false</recursiveSubmodules>
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
+ <remotePoll>false</remotePoll>
+ <gitTool>Default</gitTool>
+ <submoduleCfg class="list"/>
+ <reference/>
+ <gitConfigName/>
+ <gitConfigEmail/>
+ <extensions>
+ <hudson.plugins.git.extensions.impl.CloneOption>
+ <shallow>false</shallow>
+ <noTags>true</noTags>
+ </hudson.plugins.git.extensions.impl.CloneOption>
+ <hudson.plugins.git.extensions.impl.WipeWorkspace/>
+ </extensions>
+ </scm>
+</project>
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 @@
</hudson.plugins.git.extensions.impl.ChangelogToBranch>
<hudson.plugins.git.extensions.impl.CloneOption>
<shallow>false</shallow>
+ <noTags>false</noTags>
<timeout>20</timeout>
</hudson.plugins.git.extensions.impl.CloneOption>
<hudson.plugins.git.extensions.impl.CheckoutOption>
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