带有 Git 轮询的 Jenkins 管道无法运行

Dav*_*edy 5 git jenkins jenkins-pipeline

我有一个带有分支参数的 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...
    }
}
Run Code Online (Sandbox Code Playgroud)

根据 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
Run Code Online (Sandbox Code Playgroud)

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

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

小智 -2

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