我在我的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中更改代码时,它的起始构建就会用于该作业。
我试过workaround在https://issues.jenkins.io/browse/JENKINS-39615?focusedCommentId=280729&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-280729,但没有运气。
我将pollSCM更改为githubPush,但这也会在更改shared-library时触发。
我尝试了在https://issues.jenkins-ci.org/browse/JENKINS-41497中给出的Ignore on push notifications for githubPush()的解决方案,但仍然是它的触发工作。
在搬到pipeline之前,我有freestyle项目。其中有节源代码管理,我们可以在其中定义分支,而githubPush()只监听该分支。

当我们选择项目类型为pipeline时,没有源代码管理部分。可能是因为这个原因,它倾听所有的推事件。
通过push或poll,我希望将jenkins的工作限制为只在myrepo.git上有更改时触发。
发布于 2020-02-26 15:58:27
我不知道如何在这个Task Type中修复它。但是,如果您可以切换到多分支管道。该任务类型解决了此问题。

https://stackoverflow.com/questions/60400663
复制相似问题