【问题标题】:what is git branch name in jenkins pipeline when invoked by gitlab webhook当由 gitlab webhook 调用时,jenkins 管道中的 git 分支名称是什么
【发布时间】:2019-04-03 07:07:48
【问题描述】:

我可以使用 webhook 从 gitlab 合并请求中调用一个简单的 Jenkins 管道。现在我想知道进行结帐的源分支是什么。示例:如果我将代码推送到开发分支,则在我的管道脚本中我会签出开发分支。谢谢。

node {
  stage('Build') {
    def mybranch = '?' // get branch name from gitlab webhook
    git branch: mybranch,
    credentialsId: 'mycredential',
    url: 'myurl'
    // ...
  }
}

【问题讨论】:

    标签: gitlab jenkins-pipeline git-webhooks


    【解决方案1】:

    您可以通过env.gitlabBranch获取当前分支名称。

    参考:gitlab-plugin

    【讨论】:

      【解决方案2】:

      您可以参数化您的管道并使用 webhook 有效负载数据来填写分支值,如 here 所述。

      【讨论】:

        【解决方案3】:

        GitLab 插件创建了很多有用的环境变量。 You can see them in here.我想你需要的是CI_COMMIT_REF_NAME

        【讨论】:

          猜你喜欢
          • 2015-12-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-04-01
          • 2021-01-11
          • 1970-01-01
          • 2018-04-11
          • 2018-01-13
          相关资源
          最近更新 更多