Skip to content

Instantly share code, notes, and snippets.

@nblair
Created October 17, 2016 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nblair/c8a24d31f2a2508667eaee5ce0f3774b to your computer and use it in GitHub Desktop.
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.
/**
* 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