【问题标题】:Pipeline script get commiter on gitlabgitlab 上的管道脚本 git commit
【发布时间】:2017-10-30 09:59:29
【问题描述】:

我们刚刚开始使用 Jenkins 来构建我们的项目。 我正在弄清楚如何在管道脚本中的 Gitlab 上获取提交者。 这是我现在想出的脚本:

checkout([$class: 'GitSCM', branches: [[name: ':origin/development']], 
        doGenerateSubmoduleConfigurations: false, 
        extensions: [[$class: 'AuthorInChangelog']],  submoduleCfg: [], 
        userRemoteConfigs: [[credentialsId: 'gitlab-jenkins-ssh-key', url: 
        'git@192.168.100.890:root/hello-world-example.git']]])

我想AuthorInChangelog 可以帮助我在 Gitlab 上获得提交者,但它没有。如果我在正确的轨道上,请告诉我。

【问题讨论】:

  • 这是签出代码的方法。您如何尝试获取/使用提交者?有关您正在尝试做什么的更多信息(即管道代码)。

标签: jenkins groovy gitlab jenkins-pipeline


【解决方案1】:

以下 groovy 函数将返回提交者的名称:

def getCommitter(){
  cmtrws = sh(returnStdout: true, script:'''
      git show -s --format=\'%ce\' | tr -d "'" | cut -d@ -f1
  ''').trim()
  return cmtrws
}

为了使用它:

def committer = getCommitter()

或者,如果您更喜欢使用 bash 块:

committer=$(git show -s --format=\'%ce\' | tr -d "'" | cut -d@ -f1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-17
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 2021-03-11
    • 2022-01-19
    相关资源
    最近更新 更多