Skip to content

Instantly share code, notes, and snippets.

@ryancurrah
Last active April 6, 2020 23:42
Show Gist options
  • Save ryancurrah/61f650247e1e198b38740264df505666 to your computer and use it in GitHub Desktop.
Save ryancurrah/61f650247e1e198b38740264df505666 to your computer and use it in GitHub Desktop.
shouldSkipBuild.groovy
// Check if we can skip the build if only boilerplate files have changed
skipBuild = shouldSkipBuild(['README.md', 'CHANGELOG.md', '.gitignore'])
#!/usr/bin/groovy
// Skip build checks if the files passed into the array of strings are the ONLY files changed in the commit.
//
// This allows you to modify your `README.md` or `CHANGELOG.md` boilerplate files as much as
// you want without causing a full build to be triggered if they are the only files changed.
//
// @param skipFiles (Required) A list of files to skip
// @return True if the build can be skipped. False if the build should not be skipped.
def call (ArrayList skipFiles) {
if (!skipFiles) {
error "Missing skipFiles argument in shouldSkipBuild step"
}
ArrayList commitedFiles = sh(returnStdout: true, script: 'git diff-tree --no-commit-id --name-only -r HEAD').trim().split('\n')
// If the commitedFile is not in the skipFiles list then do NOT skip the build
for (String commitedFile:commitedFiles) {
if (!skipFiles.contains(commitedFile)) {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment