Getting Project Version from Maven POM in Jenkins

前端 未结 11 2288
情歌与酒
情歌与酒 2020-12-01 03:19

Is there any way a Jenkins build can be aware of the Maven version number of a project after processing the POM?

I\'ve got some projects where versioning is controll

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 04:08

    You could also do :

    MAVEN_VERSION=`grep A -2 -B 2 "" pom.xml | grep version | cut -d\> -f 2 | cut -d\< -f 1`-commit-"`echo $GIT_COMMIT`"
    

    Explanation: assuming that you have your project name within a line or two above/below version like a normal pom:

    org.apache.bigtop
    bigpetstore
    1.0-SNAPSHOT
    

    Then you can easily grep for the artifactId, use the "before/after" grep actions to suck in the version with it, and then grep the version out and use the simple unix "cut" command to splice out the content between "version" tags.

    I like the Jenkins-groovy integration, but this is alot easier and will work even on a build server which you dont have control over (i.e. because bash is universal).

提交回复
热议问题