feat: add support for specifying the git user's identity

This gives control over who's identity gets used for newly created
commits.

Change-Id: I8ceaabdaafa2be9c4abcfea8a2afb847d01ed0e6
This commit is contained in:
Giel van Schijndel 2020-09-16 12:38:19 +02:00
parent afc2b6fd42
commit eec4770574
5 changed files with 35 additions and 0 deletions

View File

@ -264,6 +264,9 @@ def git(registry, xml_parent, data):
* **clean** (`dict`)
* **after** (`bool`) - Clean the workspace after checkout
* **before** (`bool`) - Clean the workspace before checkout
* **committer** (`dict`)
* **name** (`str`) - Name to use as author of new commits
* **email** (`str`) - E-mail address to use for new commits
* **excluded-users**: (`list(string)`) - list of users to ignore
revisions from when polling for changes.
(if polling is enabled, optional)
@ -524,6 +527,22 @@ def git_extensions(xml_parent, data):
ext = XML.SubElement(tr, "extension", {"class": ext_name})
else:
ext = XML.SubElement(xml_parent, ext_name)
committer = data.get("committer", {})
if committer:
ext_name = impl_prefix + "UserIdentity"
if trait:
trait_name = "com.cloudbees.jenkins.plugins.bitbucket.notifications.SkipNotificationsTrait"
trait_name = "UserIdentityTrait"
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)
name = committer.get("name")
if name:
XML.SubElement(ext, "name").text = name
email = committer.get("email")
if email:
XML.SubElement(ext, "email").text = email
if not trait and "excluded-users" in data:
excluded_users = "\n".join(data["excluded-users"])
ext = XML.SubElement(xml_parent, impl_prefix + "UserExclusion")

View File

@ -83,6 +83,11 @@
<jenkins.plugins.git.traits.CleanBeforeCheckoutTrait>
<extension class="hudson.plugins.git.extensions.impl.CleanBeforeCheckout"/>
</jenkins.plugins.git.traits.CleanBeforeCheckoutTrait>
<jenkins.plugins.git.traits.UserIdentityTrait>
<extension class="hudson.plugins.git.extensions.impl.UserIdentity">
<email>no-reply@ci.example.com</email>
</extension>
</jenkins.plugins.git.traits.UserIdentityTrait>
<jenkins.plugins.git.traits.CloneOptionTrait>
<extension class="hudson.plugins.git.extensions.impl.CloneOption">
<shallow>true</shallow>

View File

@ -54,6 +54,9 @@ scm:
clean:
after: true
before: true
committer:
user: CI System
email: no-reply@ci.example.com
prune: true
shallow-clone: true
depth: 3

View File

@ -65,6 +65,11 @@
<jenkins.plugins.git.traits.CleanBeforeCheckoutTrait>
<extension class="hudson.plugins.git.extensions.impl.CleanBeforeCheckout"/>
</jenkins.plugins.git.traits.CleanBeforeCheckoutTrait>
<jenkins.plugins.git.traits.UserIdentityTrait>
<extension class="hudson.plugins.git.extensions.impl.UserIdentity">
<email>no-reply@ci.example.com</email>
</extension>
</jenkins.plugins.git.traits.UserIdentityTrait>
<jenkins.plugins.git.traits.CloneOptionTrait>
<extension class="hudson.plugins.git.extensions.impl.CloneOption">
<shallow>true</shallow>

View File

@ -50,6 +50,9 @@ scm:
clean:
after: true
before: true
committer:
user: CI System
email: no-reply@ci.example.com
prune: true
shallow-clone: true
depth: 3