【问题标题】:Jenkins pipeline with Git polling doesn't run带有 Git 轮询的 Jenkins 管道不运行
【发布时间】:2019-03-13 22:38:02
【问题描述】:

我有一个带有分支参数的 Jenkins 作业,设置为每 5 分钟轮询一次 SCM,并从 SCM 运行管道脚本:

脚本所做的第一件事是删除之前的工作区并获取源代码的新副本:

#!/usr/bin/env groovy
node {
    try {
        stage('Get Source') {
            // Clear the workspace
            deleteDir()

            // Get the source code
            checkout scm
        }

        // Stages for building and running unit tests...
    }
}

根据 Git 轮询日志,它每 5 分钟检查一次存储库,但没有发现任何更改:

Started on Mar 13, 2019 4:29:34 PM
Using strategy: Default
[poll] Last Built Revision: Revision 47251333f2d6c740275f24dd667255e66f7b5665 (refs/remotes/origin/master)
using credential **********
 > git --version # timeout=10
using GIT_SSH to set credentials Jenkins SSH Authentication Key
 > git ls-remote -h git@bitbucket.org:myuser/myrepo.git # timeout=10
Found 1 remote heads on git@bitbucket.org:myuser/myrepo.git
Using strategy: Default
[poll] Last Built Revision: Revision 47251333f2d6c740275f24dd667255e66f7b5665 (refs/remotes/origin/master)
using credential **********
 > git --version # timeout=10
using GIT_SSH to set credentials Jenkins SSH Authentication Key
 > git ls-remote -h git@bitbucket.org:myuser/myrepo.git # timeout=10
Found 1 remote heads on git@bitbucket.org:myuser/myrepo.git
Done. Took 1.8 sec
No changes

但是,在 47251333f2d6c740275f24dd667255e66f7b5665 之后还有几个额外的提交已被推送到远程 master 分支。

我读到here,在 SCM 轮询开始工作之前,该作业必须手动运行一次,但我已经手动运行了几次。我做错了什么?

【问题讨论】:

  • 对不起,如果这对您没有帮助,但是:您为什么使用轮询?是强制性的吗?你听说过 webhook 吗?这是一种更有效的当前策略。
  • 我的 Jenkins 服务器在专用网络上,所以我认为来自 Bitbucket 的 webhook 不会起作用。

标签: git jenkins jenkins-pipeline


【解决方案1】:

我想我找到了问题所在。因为我的管道脚本配置中的分支说明符是*/${BRANCH},所以我必须在结帐步骤中指定它:

#!/usr/bin/env groovy
node {
    try {
        def repo = 'dice-seeker-android'
        def branch = params.Branch
        def credentialsID = params.CredentialsID

        stage('Get Source') {
            // Clear the workspace
            deleteDir()

            // Get the source code
            checkout([
                $class: 'GitSCM',
                branches: [[
                    name: '*/' + branch
                ]],
                extensions: [[
                    $class: 'RelativeTargetDirectory',
                    relativeTargetDir: repo
                ]],
                userRemoteConfigs: [[
                    credentialsId: credentialsID,
                    url: 'git@bitbucket.org:myuser/' + repo + '.git'
                ]]
            ])
        }

        // Stages for building and running unit tests...
    }
}

这意味着我还必须包含一个使用我的 SSH 密钥的凭据参数。

最后,我不得不手动运行一次作业。现在它似乎正在发生变化。

如果有人有更好的解决方案,需要更少的代码,我仍然有兴趣了解它。

【讨论】:

    【解决方案2】:

    脚本中的第一步是删除工作区并获取更新的工作区(包含所有新提交),所以我猜它已经更新了。这就是它没有检测到您的提交的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      相关资源
      最近更新 更多