Created
May 13, 2019 02:29
-
-
Save rufoa/2807ad19328f70dc81fec25c317661b8 to your computer and use it in GitHub Desktop.
Jenkins [skip ci] implementation for multi-branch declarative pipeline
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
// change 'agent' lines as appropriate | |
pipeline { | |
agent none | |
stages { | |
stage('Run CI?') { | |
agent any | |
steps { | |
script { | |
if (sh(script: "git log -1 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]'", returnStatus: true) == 0) { | |
currentBuild.result = 'NOT_BUILT' | |
error 'Aborting because commit message contains [skip ci]' | |
} | |
} | |
} | |
} | |
stage('next stage') { | |
agent { dockerfile true } | |
steps { | |
echo 'next stage here...' | |
} | |
} | |
} | |
} |
@tylerlwsmith 😄 IIRC this has difficulty with squashed commits and/or pushing several commits at once, some of which have [skip ci]. So watch out for that!
Good to know, thank you 😁
I just stumbled across this, and if anyone's wondering about addressing multiple pushed commits, this SO answer is a fantastic resource for traversing all commit messages instead of just the first:
https://stackoverflow.com/a/60390768/3405140
def getChangesSinceLastSuccessfulBuild() {
def changes = []
def build = currentBuild
while (build != null && build.result != 'SUCCESS') {
changes += (build.changeSets.collect { changeSet ->
(changeSet.items.collect { item ->
(item.affectedFiles.collect { affectedFile ->
affectedFile.path
}).flatten()
}).flatten()
}).flatten()
build = build.previousBuild
}
return changes.unique()
}
Thank you for that @moertel!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're a hero 🦸