Score:0

Jenkinsfile - Build only if change in a specific subdirectory, how to manage post action

co flag
SBO

Basically, we're doing trunk development here, and got tons of services under the same directory.

I have a Jenkins job that is triggered through GitHub webhook, and that will do some actions only if there's a change in a specific directory of that repo :

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
                        }
                }
        }
}

That part works fine. In my other Jenkinsfile that we trigger manually, I also have this, to send a notification on Slack :

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

Issue with this is, whether there was a change or not in that directory, the notification will be sent. Is there a way to enable that block only when a change in my subdir ?

Jörg avatar
jo flag
I tried the first part and that did not even work: https://github.com/hohwille/jenkins-multimodule-pipeline/issues/1
Jörg avatar
jo flag
thanks for sharing. The pattern syntax requires two asterisks to also include changes in subfolders. Here is my runnable demo app with Jenkinsfile: https://github.com/hohwille/jenkins-multimodule-pipeline
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.