首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果共享库更改,Jenkins触发构建

如果共享库更改,Jenkins触发构建
EN

DevOps用户
提问于 2020-02-25 18:01:43
回答 2查看 2K关注 0票数 4

我在我的git中定义了Jenkins Pipeline工作。

代码语言:javascript
复制
// 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也是如此。

代码语言:javascript
复制
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中更改代码时,它的起始构建就会用于该作业。

我试过workaroundhttps://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时,没有源代码管理部分。可能是因为这个原因,它倾听所有的推事件。

通过pushpoll,我希望将jenkins的工作限制为只在myrepo.git上有更改时触发。

EN

回答 2

DevOps用户

发布于 2020-12-17 10:31:57

这个问题可以通过使用传统的SCM选项来解决。转到Jenkins -> Manage Jenkins -> Configure,并为共享库选择"Legacy SCM“选项。这将彻底解决这个问题,它对我们是有效的。

票数 3
EN

DevOps用户

发布于 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配置中)。

票数 1
EN
页面原文内容由DevOps提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://devops.stackexchange.com/questions/10904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档