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] bfeda3e661

Change-Id: I2ed2290f9ef8ecd0d9e96aad1d7cbce2964bf2da
This commit is contained in:
Bao Nguyen 2017-06-08 19:04:46 -07:00 committed by Bao Nguyen
parent 3985a338c4
commit badab02647
5 changed files with 53 additions and 1 deletions

View File

@ -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:

View File

@ -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>

View File

@ -0,0 +1,6 @@
scm:
- git:
url: https://github.com/openstack-infra/jenkins-job-builder.git
branches:
- master
do-not-fetch-tags: true

View File

@ -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>

View File

@ -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