我在我的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-12-17 10:31:57
这个问题可以通过使用传统的SCM选项来解决。转到Jenkins -> Manage Jenkins -> Configure,并为共享库选择"Legacy SCM“选项。这将彻底解决这个问题,它对我们是有效的。

发布于 2021-01-19 21:10:31
我是否正确地理解您不希望共享库中的更改触发项目/管道的构建?
如果是这样的话,您可以通过修改@Library("my_shared_lib") _语句以包含changelog=false参数来实现这一点,就像@Library("my_shared_lib", changelog=false) _那样。
对于特定的库,您也可以在全局范围内这样做--取消选中Include @Library changes in job recent changes复选框(在globally配置中)。
https://devops.stackexchange.com/questions/10904
复制相似问题