Created
September 27, 2025 05:33
-
-
Save up1/23a38db07afd56377ccf334510f61659 to your computer and use it in GitHub Desktop.
Jenkins pipeline :: detect change by folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def hasChanges(String path) { | |
| return !sh(script: "git diff --name-only HEAD~1 HEAD | grep '${path}' || true", returnStdout: true).trim().isEmpty() | |
| } | |
| pipeline { | |
| agent any | |
| stages { | |
| stage('Detect changes') { | |
| steps { | |
| script { | |
| if (hasChanges('frontend/')) { | |
| echo "Changes detected in frontend/" | |
| } else { | |
| echo "No changes in frontend/" | |
| } | |
| if (hasChanges('backend/')) { | |
| echo "Changes detected in backend/" | |
| } else { | |
| echo "No changes in backend/" | |
| } | |
| } | |
| } | |
| } | |
| stage('Frontend change') { | |
| when { | |
| changeset "**/frontend/**" | |
| } | |
| steps { | |
| echo "Frontend files have changed" | |
| } | |
| } | |
| stage('Backend change') { | |
| when { | |
| changeset "**/backend/**" | |
| } | |
| steps { | |
| echo "Backend files have changed" | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment