6

Within my Jenkinsfile I would like to read some metadata from a Gradle buildscript, e.g. group, baseNameand version. With Maven, I can do something like this:

def pom = readMavenPom file: 'pom.xml'
env.POM_VERSION         = pom.version
env.POM_ARTIFACT_ID     = pom.artifactId
env.POM_GROUP_ID        = pom.groupId

Question is: how can I do the same thing with Gradle, given I have a build.gradle that looks like this:

ext {
    group = 'my.group.com'
    baseName = 'myapplication'
    version = '0.5.2-SNAPSHOT'
}

Maybe there is a "trick" to read Gradle build information in a Jenkinsfile since both is Groovy, but I am a Groovy newb :)

Michael Lihs
  • 7,460
  • 17
  • 52
  • 85
  • try to [readFile](https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace) and find the relevant text – Amityo Dec 09 '16 at 19:36
  • An option would be to use `gradle.properties` and the [`readProperties`](https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readproperties-code-read-properties-from-files-in-the-workspace-or-text) step. Could possibly help by knowing exactly what you are trying to do in your `Jenkinsfile`. – mkobit Dec 10 '16 at 23:08
  • I'm trying to create a versioned jar artifact that I can then upload to Artifactory. Therefore I need the version and artifact name to add the build number and then push it to the repo. Maybe it's also possible to do this completely in Gradle - but as I said: I'm a Gradle newb :) – Michael Lihs Dec 11 '16 at 00:50
  • ideas: http://stackoverflow.com/questions/39140744/get-gradle-variables-in-jenkins-pipeline-script?rq=1 – Michael Lihs Dec 12 '16 at 23:11

0 Answers0