Skip to content
Snippets Groups Projects

Versions

3 files
+ 27
21
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 23
16
@@ -4,21 +4,28 @@ tasks.withType(JavaCompile) {
doFirst {
def versionFile = new File("${projectDir}/src/main/resources/version/nshmp-ws-static-version.json")
new File(versionFile.getParent()).mkdirs()
def details = versionDetails()
def ciProjectUrl = System.getenv("CI_PROJECT_URL")
def branch = System.getenv("CI_COMMIT_BRANCH")
def versionInfo = [
branchName: branch ? branch : details.branchName,
commitDistance: details.commitDistance,
gitHash: details.gitHash,
gitHashFull: details.gitHashFull,
isCleanTag: details.isCleanTag,
lastTag: details.lastTag,
projectName: rootProject.name,
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))
try {
def details = versionDetails()
def ciProjectUrl = System.getenv("CI_PROJECT_URL")
def branch = System.getenv("CI_COMMIT_BRANCH")
def versionInfo = [
branchName: branch ? branch : details.branchName,
commitDistance: details.commitDistance,
gitHash: details.gitHash,
gitHashFull: details.gitHashFull,
isCleanTag: details.isCleanTag,
lastTag: details.lastTag,
projectName: project.name,
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))
} catch (Exception e) {
println("Failed to create version file. Writing blank file.")
println(e)
versionFile.write('{}')
}
}
}
Loading