Reputation: 479
I'm using Azure Devops yaml pipelines for the build process of my iOS application. During runtime, I want to auto-increment the CFBundle Version Number after each build in the info.plist file.
Eg: version starts from 0.0.1 -> 0.0.99 -> 0.1.0 -> 0.1.99 -> 0.2.0 ->............-> 0.99.99 -> 1.0.0
Any advise on how I can achieve this without using any third party extensions? Thanks!
Upvotes: 2
Views: 2654
Reputation: 1918
If you want to keep $(MARKETING_VERSION) in Info.plist for CFBundleShortVersionString but want to increase version after successful archive or build then use following script following script will increase like 1.0 to 2.0 but ofcourse that logic can be modified using @Jobert's solution etc
Script to increase app version in Xcode >= 13
Upvotes: 0
Reputation: 1652
You can achieve that by implementing a script
step before building your app.
This script would use the PlistBuddy
tool to read and increment the version numbers (assuming you're using a macos machine on Azure DevOps).
I'm also assuming you're using a semantic versioning system major.minor.patch
as described here.
This script should get to increment the version number as you described and then write it to the Info.plist
file of your app. Note to change the path to that file if you have it differently in your project
- script: |
buildPlist="$(Build.SourcesDirectory)/Info.plist" # Enter the path to your plist file here
maxSubversionNumber=99 # Set what will be the maximum number to increment each sub version to
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist")
majorVersion=`echo $versionNumber | awk -F "." '{print ($1 == "" ? 0 : $1)}'`
minorVersion=`echo $versionNumber | awk -F "." '{print ($2 == "" ? 0 : $2)}'`
patchVersion=`echo $versionNumber | awk -F "." '{print ($3 == "" ? 0 : $3)}'`
if [[ $patchVersion -ge $maxSubversionNumber ]]
then
patchVersion=0
if [[ $minorVersion -ge $maxSubversionNumber ]]
then
minorVersion=0
majorVersion=$(($majorVersion + 1))
else
minorVersion=$(($minorVersion + 1))
fi
else
patchVersion=$(($patchVersion + 1))
fi
newVersionNumber=`echo $versionNumber | awk -F "." '{print '$majorVersion' "." '$minorVersion' ".'$patchVersion'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $newVersionNumber" "$buildPlist"
Upvotes: 3