当特定文件夹中的文件发生更改时触发多分支管道

Posted

技术标签:

【中文标题】当特定文件夹中的文件发生更改时触发多分支管道【英文标题】:Trigger a multibranch pipeline when there is a change in files in specific folder 【发布时间】:2021-08-03 19:48:09 【问题描述】:

当文件夹中的某些文件被推送到 BitBucket 时,我想运行多分支管道。我尝试过轮询忽略对某些路径的提交。但管道没有触发。任何人都可以帮助解决问题。如何在包含的轮询区域内准确指定路径会忽略对某些路径的提交。

【问题讨论】:

【参考方案1】:

我在包含1.txt2.txt 的Git 存储库中使用了以下Jenkinsfile

pipeline 
    agent any

    stages 
        
        stage('1.txt in changelog') 
            when 
                // see https://www.jenkins.io/doc/book/pipeline/syntax/#built-in-conditions
                changelog '1.txt'
            
            steps 
                echo '1.txt in changelog'
            
        
 
        stage('2.txt in changelog') 
            when 
                changelog '2.txt'
            
            steps 
                echo '2.txt in changelog'
            
        
        
        stage('1.txt in changeset') 
            when 
                changeset '1.txt'
            
            steps 
                echo '1.txt in changeset'
            
        
 
        stage('2.txt in changeset') 
            when 
                changeset '2.txt'
            
            steps 
                echo '2.txt in changeset'
            
        
        
    

更改并推送2.txt 后,相应多分支管道项目的控制台输出显示:

...
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] 
[Pipeline] stage
[Pipeline]  (1.txt in changelog)
Stage "1.txt in changelog" skipped due to when conditional
[Pipeline] 
[Pipeline] // stage
[Pipeline] stage
[Pipeline]  (2.txt in changelog)
[Pipeline] echo
2.txt in changelog
[Pipeline] 
[Pipeline] // stage
[Pipeline] stage
[Pipeline]  (1.txt in changeset)
Stage "1.txt in changeset" skipped due to when conditional
[Pipeline] 
[Pipeline] // stage
[Pipeline] stage
[Pipeline]  (2.txt in changeset)
[Pipeline] echo
2.txt in changeset
[Pipeline] 
[Pipeline] // stage
[Pipeline] 
[Pipeline] // withEnv
[Pipeline] 
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

这同样适用于创建2.txt,但适用于删除它。

【讨论】:

以上是关于当特定文件夹中的文件发生更改时触发多分支管道的主要内容,如果未能解决你的问题,请参考以下文章

仅当特定文件集发生更改时如何触发构建

从git中的现有分支创建新分支时如何不触发管道?

如何排除对管道 yaml 文件的更改以触发构建 i azure devops?

如果 SharePoint 上的一个特定文件发生更改,则触发操作

仅针对特定分支的 gitlab 触发管道

特定 Bucket 文件夹上的 Cloud Function 存储触发器