【发布时间】:2020-02-25 17:59:19
【问题描述】:
我在我的 git 存储库中定义了 Jenkins Pipeline 工作。
// File: deployment/jenkinsfiles/staging/Merge
@Library("my_shared_lib") _
import com.company.myteam.Constants
pipeline {
agent { label "common" }
triggers {
pollSCM("H/2 * * * *")
}
options {
buildDiscarder(logRotator(numToKeepStr: "50", artifactNumToKeepStr: "50"))
}
stages {
stage ("Staging Merge") {
steps {
script {
def config = new Constants().repoconfig
ansiColor("xterm") {
myteam.pipelines.stagingMerge(config)
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
然后我创建了 jenkins 作业配置,如下所示。
现在,当我检查 Git Polling Log 时,它的轮询 shared-library 也是。
Started on Feb 25, 2020 5:33:07 PM
Using strategy: Default
[poll] Last Built Revision: Revision 681f996e689bdeb9cfca2b167002b8ccd99590cb (origin/staging)
using credential github_username_with_token
> git --version # timeout=10
using GIT_ASKPASS to set credentials Github Service Account Username with token
> git ls-remote -h https://myuser@github.company.com/myteam/myrepo # timeout=10
Found 6 remote heads on https://myuser@github.company.com/myteam/myrepo
[poll] Latest remote head revision on refs/heads/staging is: 681f996e689bdeb9cfca2b167002b8ccd99590cb - already built by 53
Using strategy: Default
[poll] Last Built Revision: Revision e80628ec7c9dbc59decbc81a3b884dcaa963a8dc (refs/remotes/origin/master)
using credential github_username_with_token
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repositories
> git config remote.origin.url https://myuser@github.company.com/myteam/jenkins-shared-libraries.git # timeout=10
Fetching upstream changes from https://myuser@github.company.com/myteam/jenkins-shared-libraries.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials Github Service Account Username with token
> git fetch --tags --progress https://myuser@github.company.com/myteam/jenkins-shared-libraries.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Polling for changes in
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
> git log --full-history --no-abbrev --format=raw -M -m --raw e80628ec7c9dbc59decbc81a3b884dcaa963a8dc..869b3a16e07d21a88d557f1857376bfed7717a6e # timeout=10
每当我更改 jenkins-shared-library 中的代码时,它都会开始构建工作。
我尝试了https://issues.jenkins.io/browse/JENKINS-39615?focusedCommentId=280729&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-280729 中给出的workaround,但没有运气。
我将pollSCM 更改为githubPush,但这也会在我更改shared-library 时触发。
我尝试了https://issues.jenkins-ci.org/browse/JENKINS-41497 中给出的解决方案,如Ignore on push notifications 为githubPush(),但仍然是它的触发工作。
在搬到pipeline 之前,我有freestyle 项目。 Source Code Management 部分,我们可以在其中定义分支,githubPush() 仅在该分支上侦听。
当我们选择项目类型为pipeline 时,没有源代码管理部分。可能是因为它监听了所有的推送事件。
通过push 或poll,我想限制我的jenkins 作业仅在myrepo.git 发生更改时触发。
【问题讨论】:
标签: git jenkins push-notification jenkins-pipeline polling