jenkinsfile: filter stage execution based on path (#613)

Signed-off-by: markoburcul <marko@status.im>
This commit is contained in:
Marko Burčul 2024-10-11 16:55:32 +02:00 committed by GitHub
parent b7be3d762b
commit f1fa827d42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 53 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.9.11' library 'status-jenkins-lib@v1.9.11'
def changesDetected = false
pipeline { pipeline {
agent { label 'linux' } agent { label 'linux' }
@ -27,7 +29,32 @@ pipeline {
} }
stages { stages {
stage('Check Changed Files') {
steps {
script {
// Get the list of changed files
def changedFiles = sh(
script: "git diff --name-only origin/main...HEAD",
returnStdout: true
).trim()
// Check if the changes are relevant
def isRelevant = changedFiles.split('\n').any { file ->
file.startsWith('apps/connector/')
}
// If no relevant changes, skip the build
if (isRelevant) {
changesDetected = true
}
}
}
}
stage('Install') { stage('Install') {
when {
expression { changesDetected }
}
steps { steps {
dir("${env.WORKSPACE}/apps/connector") { dir("${env.WORKSPACE}/apps/connector") {
script { script {
@ -42,6 +69,9 @@ pipeline {
} }
stage('Build') { stage('Build') {
when {
expression { changesDetected }
}
steps { steps {
dir("${env.WORKSPACE}/apps/connector") { dir("${env.WORKSPACE}/apps/connector") {
script { script {
@ -56,6 +86,9 @@ pipeline {
} }
stage('Zip') { stage('Zip') {
when {
expression { changesDetected }
}
steps { steps {
dir("${env.WORKSPACE}/apps/connector") { dir("${env.WORKSPACE}/apps/connector") {
zip( zip(
@ -68,6 +101,9 @@ pipeline {
} }
stage('Archive') { stage('Archive') {
when {
expression { changesDetected }
}
steps { steps {
dir("${env.WORKSPACE}/apps/connector") { dir("${env.WORKSPACE}/apps/connector") {
archiveArtifacts( archiveArtifacts(
@ -79,6 +115,9 @@ pipeline {
} }
stage('Upload') { stage('Upload') {
when {
expression { changesDetected }
}
steps { steps {
dir("${env.WORKSPACE}/apps/connector") { dir("${env.WORKSPACE}/apps/connector") {
script { script {
@ -90,8 +129,20 @@ pipeline {
} }
post { post {
success { script { github.notifyPR(true) } } success {
failure { script { github.notifyPR(false) } } script {
if(changesDetected) {
github.notifyPR(true)
}
}
}
failure {
script {
if(changesDetected) {
github.notifyPR(false)
}
}
}
cleanup { cleanWs() } cleanup { cleanWs() }
} }
} }