Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save su-ar/5d059d4cbc1857d23a60276fff6c20eb to your computer and use it in GitHub Desktop.

Select an option

Save su-ar/5d059d4cbc1857d23a60276fff6c20eb 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