Jenkinsfile - 僅在特定子目錄中發生更改時構建,如何管理後期操作

Jenkinsfile - 僅在特定子目錄中發生更改時構建,如何管理後期操作

基本上,我們在這裡進行主幹開發,並在同一目錄下獲得大量服務。

我有一個透過 GitHub webhook 觸發的 Jenkins 作業,並且僅當該儲存庫的特定目錄發生變更時才會執行一些操作:

pipeline {
        agent any
        stages {
                stage('Building') {
                when { changeset "subdirectory/*"}
                        steps {
                                -- do whatever is configured
                        }
                }
                stage('Deploying to Dev') {
                when { changeset "subdirectory/*"}
                        steps {
                                -- do whatever is configured
                        }
                }
        }
}

那部分工作正常。在我手動觸發的另一個 Jenkinsfile 中,我也有這個,用於在 Slack 上發送通知:

        post {
                success {
                        slackSend channel: '#my-notif-channel',
                        color: 'good',
                        message: "Yay ! "
                }
                failure {
                        slackSend channel: '#my-notif-channel',
                        color: 'danger',
                        message: "Nay !"
                }
        }

問題是,無論該目錄是否發生更改,都會發送通知。有沒有辦法僅在我的子目錄發生更改時啟用該區塊?

相關內容