Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read versionName of build.gradle from Jenkins

I'm using Jenkins for my Android app builds. On every build, I get some info, like build number, etc...

I'm searching a way to read the versionName value of in the build.gradle when Jenkins build the job. I know we can get the buildNumber with the $BUILD_NUMBERenv variable, but how to get the versionName?

like image 556
ejay Avatar asked Nov 05 '16 19:11

ejay


1 Answers

You could do this by adding an Execute Shell step which determines the versionName, and exporting it as an environment variable using the EnvInject Plugin.

Assuming your build.gradle contains:

versionName = myname

You can add this script:

v=$(cat build.gradle  | grep versionName | awk '{print $3}')
echo MY_VERSION_NAME=${v} > env.properties
like image 98
sgargel Avatar answered Sep 21 '22 12:09

sgargel