I like it:
private void createReleaseTag() { def tagName = "release/${project.version}" ("git tag $tagName").execute() ("git push --tags").execute() }
EDIT: A Larger Version
private void createReleaseTag() { def tagName = "release/${version}" try { runCommands("git", "tag", "-d", tagName) } catch (Exception e) { println(e.message) } runCommands("git", "status") runCommands("git", "tag", tagName) } private String runCommands(String... commands) { def process = new ProcessBuilder(commands).redirectErrorStream(true).start() process.waitFor() def result = '' process.inputStream.eachLine { result += it + '\n' } def errorResult = process.exitValue() == 0 if (!errorResult) { throw new IllegalStateException(result) } return result }
You can handle the exception.
source share