Skip to content
Snippets Groups Projects

Try Catch Version

1 file
+ 22
18
Compare changes
  • Side-by-side
  • Inline
+ 22
18
@@ -2,23 +2,27 @@ apply plugin: "com.palantir.git-version"
@@ -2,23 +2,27 @@ apply plugin: "com.palantir.git-version"
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile) {
doFirst {
doFirst {
def versionFile = new File("${projectDir}/src/main/resources/version/nshmp-haz-version.json")
try {
new File(versionFile.getParent()).mkdirs()
def versionFile = new File("${projectDir}/src/main/resources/version/nshmp-haz-version.json")
def details = versionDetails()
new File(versionFile.getParent()).mkdirs()
def ciProjectUrl = System.getenv("CI_PROJECT_URL")
def details = versionDetails()
def branch = System.getenv("CI_COMMIT_BRANCH")
def ciProjectUrl = System.getenv("CI_PROJECT_URL")
def versionInfo = [
def branch = System.getenv("CI_COMMIT_BRANCH")
branchName: branch ? branch : details.branchName,
def versionInfo = [
commitDistance: details.commitDistance,
branchName: branch ? branch : details.branchName,
gitHash: details.gitHash,
commitDistance: details.commitDistance,
gitHashFull: details.gitHashFull,
gitHash: details.gitHash,
isCleanTag: details.isCleanTag,
gitHashFull: details.gitHashFull,
lastTag: details.lastTag,
isCleanTag: details.isCleanTag,
projectName: project.name,
lastTag: details.lastTag,
url: ciProjectUrl ? ciProjectUrl : 'git config --get remote.origin.url'.execute().text.replace('\n', ''),
projectName: project.name,
version: details.version,
url: ciProjectUrl ? ciProjectUrl : "git config --get remote.origin.url".execute().text.replace("\n", ""),
]
version: details.version,
def json = groovy.json.JsonOutput.toJson(versionInfo)
]
versionFile.write(groovy.json.JsonOutput.prettyPrint(json))
def json = groovy.json.JsonOutput.toJson(versionInfo)
 
versionFile.write(groovy.json.JsonOutput.prettyPrint(json))
 
} catch (Exception e) {
 
println("Failed to create version file.")
 
}
}
}
}
}
Loading