scm: add support for hudson.plugins.git.util.AncestryBuildChooser

Adds a new scm.git choosing-strategy 'ancestry', corresponding to
AncestryBuildChooser, and two new options if that strategy is
selected, maximum-age and ancestor-sha1.

Includes doc and test updates.

Change-Id: Ib94f6100d4891b4196a6326c0678f638b4edbeab
Signed-off-by: Dan Mick <danmick@gmail.com>
This commit is contained in:
Dan Mick 2025-02-11 20:56:54 -08:00
parent 6fc0a3ba25
commit 60f0316389
3 changed files with 60 additions and 2 deletions

@ -260,8 +260,14 @@ def git(registry, xml_parent, data):
* **branch** (`string`) - name of the branch to create changelog
against (default 'master')
* **choosing-strategy**: (`string`) - Jenkins class for selecting what
to build. Can be one of `default`,`inverse`, or `gerrit`
to build. Can be one of `default`,`inverse`, `gerrit`, or `ancestry`
(default 'default')
* **maximum-age** (`int`) - Maximum age, in days, of commits to examine
for build (when choosing-strategy=ancestry)
(default: none)
* **ancestor-sha1** (`string`) - If set, only branches including this
commit will be built (when choosing-strategy=ancestry)
(default: none)
* **clean** (`dict`)
* **after** (`dict`) - Clean the workspace after checkout
* **remove-stale-nested-repos** (`bool`) - Deletes untracked
@ -489,6 +495,7 @@ def git_extensions(xml_parent, data):
"gerrit.trigger.hudsontrigger.GerritTriggerBuildChooser"
),
"inverse": "hudson.plugins.git.util.InverseBuildChooser",
"ancestry": "hudson.plugins.git.util.AncestryBuildChooser",
}
if not trait and "basedir" in data:
@ -509,8 +516,17 @@ def git_extensions(xml_parent, data):
raise ValueError(
"Invalid choosing-strategy %r" % data.get("choosing-strategy")
)
ext = XML.SubElement(xml_parent, impl_prefix + "BuildChooserSetting")
XML.SubElement(ext, "buildChooser", {"class": choosing_strategy})
chooser = XML.SubElement(ext, "buildChooser", {"class": choosing_strategy})
if choosing_strategy == choosing_strategies["ancestry"]:
maximum_age = data.get("maximum-age", None)
ancestor_sha1 = data.get("ancestor-sha1", None)
if maximum_age:
XML.SubElement(chooser, "maximumAgeInDays").text = str(maximum_age)
if ancestor_sha1:
XML.SubElement(chooser, "ancestorCommitSha1").text = ancestor_sha1
if "clean" in data:
# Keep support for old format 'clean' configuration by checking
# if 'clean' is boolean. Else we're using the new extensions style.

@ -0,0 +1,36 @@
<?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://example.com/git/repo</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>**</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.BuildChooserSetting>
<buildChooser class="hudson.plugins.git.util.AncestryBuildChooser">
<maximumAgeInDays>7</maximumAgeInDays>
<ancestorCommitSha1>ancestor-sha1</ancestorCommitSha1>
</buildChooser>
</hudson.plugins.git.extensions.impl.BuildChooserSetting>
<hudson.plugins.git.extensions.impl.WipeWorkspace/>
</extensions>
</scm>
</project>

@ -0,0 +1,6 @@
scm:
- git:
url: https://example.com/git/repo
choosing-strategy: ancestry
maximum-age: 7
ancestor-sha1: ancestor-sha1