Created
May 1, 2016 16:57
-
-
Save andreiRS/417fd445abf11d787a2430d3dd9beef5 to your computer and use it in GitHub Desktop.
Gradle task to print all local branches that contain a commit when CI uses detached head strategy
This file contains 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
task printCommitBranches(type: Exec) { | |
executable "bash" | |
args "-c", "git branch --contains HEAD" | |
//store the output instead of printing to the console: | |
standardOutput = new ByteArrayOutputStream() | |
doLast { | |
// split the output of the git command per newline and remove indentation whitespaces | |
def outputLines = standardOutput.toString().split(/\r?\n\s+/) | |
// if detached head, remove the line | |
outputLines = outputLines.findAll({ it.contains("HEAD") == false }) | |
print outputLines.join(",") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment