project version from maven to sonar using hudson

前端 未结 5 677
情话喂你
情话喂你 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 20:49

    Had the same need and solved as suggested with Groovy parsing the pom.

    import jenkins.util.*;
    import jenkins.model.*;
    
    def thr = Thread.currentThread();
    def currentBuild = thr?.executable;
    def workspace = currentBuild.getModuleRoot().absolutize().toString();
    
    def project = new XmlSlurper().parse(new File("$workspace/pom.xml"))
    
    def param = new hudson.model.StringParameterValue("project.version", project.version.toString())
    currentBuild.addAction(new hudson.model.ParametersAction(param));
    

    Add this script as a post step of type "Execute system Groovy script" (so it's not needed to install Groovy) and paste the code in the "Groovy command".

提交回复
热议问题