project version from maven to sonar using hudson

前端 未结 5 717
情话喂你
情话喂你 2021-01-16 20:37

i am using maven2 , hudson and sonar while doing sonar analysis - i would like some way to append the Hudson build# to the maven version of the project

The project

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-16 21:04

    You can use Groovy script to read the version and put on environment variable: Getting Maven Version in Jenkins

    I used this script on time to parse the version:

    def project = new XmlParser().parse("/pom.xml")
    def artifactId =  project.artifactId.text().trim()
    def version = project.version.text().trim()
    println "ArtifactId: [" + artifactId + "]"
    println "Version: [" + version + "]"
    

    After set "Additional properties" field with: -Dsonar.projectVersion=${MAVEN_VERSION}-${BUILD_NUMBER}

    If Jenkins don't get the variable, try install: https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

提交回复
热议问题