Jenkins: How to use a variable from a pre-build shell in the Maven “Goals and options”

后端 未结 6 1555
别跟我提以往
别跟我提以往 2020-12-24 12:20

I have a Maven job in Jenkins. Before the actual build step I have an \"Execute shell\" pre-build step. In that shell I set a variable:

REVISION=$(cat .build         


        
6条回答
  •  余生分开走
    2020-12-24 12:40

    I had a very similar problem, trying to compute a build version and inject it into the build. After running into all the same issues (not expanding, etc), I used the "Generate environment variables from script" option, which interprets the output as tag=value pairs into Jenkins variables. The script :

      #generate a version code that is high enough to surpass previously published clients
      val=`expr 150000 + $BUILD_NUMBER`
      echo VERSION_CODE=$val
    

    After this, I was able to inject $VERSION_CODE into maven as follows :

      -Dbuild.vercode=${VERSION_CODE}
    

    Hope that works for you.

提交回复
热议问题