Created
October 17, 2016 15:51
-
-
Save nblair/c8a24d31f2a2508667eaee5ce0f3774b to your computer and use it in GitHub Desktop.
Groovy script to help Jenkins identify the version of the artifact it just built.
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
/** | |
* Reads the version of the artifact from the Spring Boot application.yml. | |
* Depends on the following in build.gradle: | |
<pre> | |
processResources { | |
filesMatching('application.yml') { | |
expand(project.properties) | |
} | |
} | |
</pre> | |
*/ | |
import org.yaml.snakeyaml.Yaml | |
import hudson.model.* | |
def build = Thread.currentThread().executable | |
Yaml yaml = new Yaml() | |
Object data = yaml.load(new File("${build.workspace}/build/resources/main/application.yml").newDataInputStream()) | |
def version = data['info']['release']['version'] | |
println "Artifact version is $version" | |
build.addAction( | |
new ParametersAction([ | |
new StringParameterValue("ARTIFACT_VERSION", version), | |
]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment