Reputation: 11
We have just started to use Jenkins to build for our projects. I'm figuring out how to get committer on Gitlab in pipeline script. Here is the script I came up to right now:
checkout([$class: 'GitSCM', branches: [[name: ':origin/development']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'AuthorInChangelog']], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'gitlab-jenkins-ssh-key', url:
'[email protected]:root/hello-world-example.git']]])
I suppose AuthorInChangelog
can help me to get committer on Gitlab but it didn't. Please let me know if I'm on the right track.
Upvotes: 1
Views: 348
Reputation: 6305
The following groovy function will return the name of the committer:
def getCommitter(){
cmtrws = sh(returnStdout: true, script:'''
git show -s --format=\'%ce\' | tr -d "'" | cut -d@ -f1
''').trim()
return cmtrws
}
In order to use it:
def committer = getCommitter()
Or if you prefer to use a bash block:
committer=$(git show -s --format=\'%ce\' | tr -d "'" | cut -d@ -f1)
Upvotes: 2