auto-semver/vars/runAutoSemver.groovy

49 lines
1.3 KiB
Groovy
Raw Normal View History

2019-12-20 18:44:07 +01:00
#!/usr/bin/env groovy
/**
* Runs "semver -n" and updates environment variables ${env.SEMVER_NEW_VERSION}, ${env.SEMVER_RESOLVED_VERSION},
* ${env.VERSION}, and ${env.SEMVER_STATUS}
2019-12-20 18:44:07 +01:00
*
* @param dockerImage (Optional) The docker image with semver to run in environment
*
*/
// Run Auto Semver
2020-02-21 23:44:15 +01:00
def call(dockerImage = "rightbrainnetworks/auto-semver:latest", debug = false) {
2019-12-20 18:44:07 +01:00
def docker_image = docker.image(dockerImage)
docker_image.pull()
docker_image.inside{
2020-02-21 23:44:15 +01:00
def args = ""
if(debug)
{
args="--debug"
}
2019-12-20 18:44:07 +01:00
def RETURN_STATUS
def regex = '^\\s*current_version\\s*=\\s*\\K[^\\s]+'
2020-02-21 23:44:15 +01:00
RETURN_STATUS = sh(script: "semver -n ${args}", returnStatus: true)
2019-12-20 18:44:07 +01:00
echo "Semver Return Status: ${RETURN_STATUS}"
env.SEMVER_STATUS = RETURN_STATUS
switch (RETURN_STATUS) {
case "0":
echo 'Versioned will push after build/test.'
break
case "128":
echo 'Unknown Semver Failure'
sh 'exit 1'
break
default:
echo 'No versioning required.'
break
}
env.SEMVER_NEW_VERSION = sh(script: "grep -Po '${regex}' .bumpversion.cfg", returnStdout: true).trim()
2020-02-21 23:44:15 +01:00
env.SEMVER_RESOLVED_VERSION = getVersion("-d ${args}")
2019-12-20 18:44:07 +01:00
2019-12-20 21:12:39 +01:00
env.VERSION = env.SEMVER_RESOLVED_VERSION
2019-12-20 18:44:07 +01:00
}
}