Getting Project Version from Maven POM in Jenkins

前端 未结 11 2287
情歌与酒
情歌与酒 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 03:57

    Based on @Akom`s answer the pre steps to have POM_VERSION are:

    1. "Inject environment variables" with property file your_property_file. Note if you select "Inject environment variables to the build process" the file needs to exist in the jenkins workspace.
    2. run in a pre step execute shell the follwing bash script.

    Script

    mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -l project_version
    # grep for the version pattern rather than not mentioning '\['
    echo "POM_VERSION=$(grep -E  '^[0-9.]+(-SNAPSHOT)?$' project_version)" > your_property_file
    

提交回复
热议问题