1

I have an automatic build script for my build server that builds Android applications. As part of this building process, I need to increment two parameters in one of the Android application files after the build and commit this file into the Git repository.

So I have to build the following bash script:

#!/bin/bash
clear
echo "Start of Pull command"
git pull
echo "End of Pull command"
echo "Start of incrementedRelease build"
gradle incrementedRelease
echo "End of incrementedRelease build"
echo "Start of Commit command"
git commit -a -m "======================== Commit to change Manifest Version ======================"
echo "End of Commit command"
echo "Start of Push command"
git push
echo "End of Push command"

Now, the issue is that instead of creating a commit with the name:

Commit to change Manifest Version

I want to pass the current application version.

For I have created a version.txt file that contains the current version that will be released, I want in the process of the build for it to get the value from this file and put it as part of the commit name, as well as update this file automatically with the next version for the next commit.

Cristian Ciupitu
  • 5,513
  • 2
  • 37
  • 47
Emil Adz
  • 135
  • 1
  • 1
  • 8

1 Answers1

2

in your version.txt put it as a shell variable such as APPVER="version"

Then in your bash script use . /path/to/version.txt then export the variable with the line export APPVER

this will then import that variable into your build script and use it where you want the name by using the variable $APPVER

Commit to change Manifest $APPVER

in answer to comment

MAJOR=`echo $APPVER| cut -c1-1`
export MAJOR

MINOR=`echo $APPVER | cut -c3-5`
export MINOR


NEWVER=$((MINOR + 1))
export NEWVER


echo APPVER=$MAJOR.$NEWVER > /path/to/version.txt

EDIT: forgot to add the export command EDIT: added way to increment... and fixed some mistakes and formating

Fegnoid
  • 889
  • 4
  • 7
  • So, few questions: as I understand in order for the file to be available I need to to add it with a (dot)(.) to the begging of the script, and right after it add export APPVER in the scrpit. this will allow me to use $APPVER in the commit name? – Emil Adz Aug 28 '14 at 13:18
  • Lets say that the text in the file is APPVER="1.110" how can I increment the version by 1 to "1.111"? – Emil Adz Aug 28 '14 at 13:19
  • Well this works great, I just left with upgrading the file to the new version. Could you tell me how can I update the APPVER parameter in the version.txt file? – Emil Adz Aug 28 '14 at 13:32
  • The problem is bash doesn't deal with floating point numbers such as 1.110 it can only handle integers, i have thought of an idea that may do the job but would involve rules around how your version is done - i will add it to my answer – Fegnoid Aug 28 '14 at 13:37
  • So what if I make two parameters in my version file: MAJOR and MINOT and I connect them on output like $MAJOR+"."+$MINOR (If it's even written this way in Linux) and update only the minor version. This would be sufficient for me, can this be done? – Emil Adz Aug 28 '14 at 13:39
  • Yes, see my edit to the answer – Fegnoid Aug 28 '14 at 13:46
  • Thanks for you help, there is only one problem. When the file is rewritten the new version is assigned only the file is changed to version only without the APPVER – Emil Adz Aug 28 '14 at 13:54
  • yes, i saw my mistake and have edited to reflect the correct echo into the file, sorry – Fegnoid Aug 28 '14 at 13:54
  • Yes, seen this now. Let me check this for a sec. – Emil Adz Aug 28 '14 at 13:55