Reputation: 12047
I have a Jenkinsfile for several multibranch pipelines in the same repository, and one thing I find frustrating is that all pipelines are triggered when I make any change, when often in reality only one pipeline actually needs to be triggered.
Is it possible, using a Jenkins file, to selectively include or exclude paths that will result in a build being triggered?
I'm thinking of something similar to below, but looking at the documentation I cannot see any reference to such a simple way of doing this. However, I'm new to Jenkins so I'm hoping that I'm missing something.
pipeline {
agent {
label 'Codebuild'
}
trigger {
include '/some/path
}
stages {
stage('Do the magic') {
steps {
script {
...do stuff here...
}
}
}
}
}
Upvotes: 2
Views: 1559
Reputation: 3076
You can use the when condition
to determine whether the stage should be executed depending on the given condition.
In this can you can use the option/condition changeset
to limit stage execution only to the case when specific files are changed.
For more info about when
and changeset
option :
https://www.jenkins.io/doc/book/pipeline/syntax/#when
Example:
stages {
stage('Do the magic') {
// Below condition you can change based on your usecase
when { changeset "src/*.js"}
steps {
sh "make build"
...
}
}
}
Upvotes: 2