diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py
index 4d56964e5..140884f20 100644
--- a/jenkins_jobs/modules/scm.py
+++ b/jenkins_jobs/modules/scm.py
@@ -307,6 +307,7 @@ def git(registry, xml_parent, data):
* **per-build-tag** (`bool`) - Create a tag in the workspace for every
build. (default is inverse of skip-tag if set, otherwise false)
* **prune** (`bool`) - Prune remote branches (default false)
+ * **prune-tags** (`bool`) - Prune tags if they no longer exist on the remote (default false)
* **scm-name** (`string`) - The unique scm name for this Git SCM
(optional)
* **shallow-clone** (`bool`) - Perform shallow clone (default false)
@@ -763,6 +764,15 @@ def git_extensions(xml_parent, data):
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
+ prune = str(data.get("prune-tags", False)).lower()
+ if prune == "true":
+ ext_name = impl_prefix + "PruneStaleTag"
+ if trait:
+ trait_name = "PruneStaleTagTrait"
+ tr = XML.SubElement(xml_parent, trait_prefix + trait_name)
+ ext = XML.SubElement(tr, "extension", {"class": ext_name})
+ else:
+ ext = XML.SubElement(xml_parent, ext_name)
ignore_notify_commits = str(data.get("ignore-notify", False)).lower()
if not trait and ignore_notify_commits == "true":
XML.SubElement(xml_parent, impl_prefix + "IgnoreNotifyCommit")
diff --git a/tests/multibranch/fixtures/scm_git_full.xml b/tests/multibranch/fixtures/scm_git_full.xml
index f3b7fa68d..e6f0f194c 100644
--- a/tests/multibranch/fixtures/scm_git_full.xml
+++ b/tests/multibranch/fixtures/scm_git_full.xml
@@ -110,6 +110,9 @@
+
+
+
diff --git a/tests/multibranch/fixtures/scm_git_full.yaml b/tests/multibranch/fixtures/scm_git_full.yaml
index 65e51b761..eef8c4d03 100644
--- a/tests/multibranch/fixtures/scm_git_full.yaml
+++ b/tests/multibranch/fixtures/scm_git_full.yaml
@@ -71,6 +71,7 @@ scm:
after: true
before: true
prune: true
+ prune-tags: true
local-branch: true
sparse-checkout:
paths: