The guide below will show you how to auto-increment the version of your application in any Git repository using Buddy’s pipeline.

The pipeline we’re about to create uses parameters to define which digit we want to raise (major/minor/patch), determines $latest_version with a script, and pushes the tag to your repository:

1. Add Git repository

The first step is adding the repo with your project. In this example we’ll use GitHub:

2. Configure pipeline settings

Now we can add the delivery pipeline. Let’s configure it so that it runs on every push to the Master branch:

3. Configure pipeline actions

3.1 Add environment variables

Before we get down to the actions we need to add a couple of variables that we’ll use in a script later on. Switch to the Variables tab and add these three keys:

  • $major
  • $minor
  • $patch
  • Make sure to set the type to Settable as we need the action to remember the value before every execution.
  • Unless you already have a tag version in your repo, set all Values to zero.

3.2 Set version type

By default, the pipeline will increment the patch version (0.0.1) on every push. Let’s add an action that will allow us to raise a minor (0.1.0) or major (1.0.0) number on manual trigger: Pass arguments.

Add these two parameters:

  • $is_major
  • $is_minor

The parameters can be either true or false. In this example we have uploaded a file with these values to the filesystem and selected them in the parameter options so we don’t have to enter them manually every time the action is executed.

Trigger condition

Since we want to run this action only in manual mode, we need to set the Trigger condition. Reveal the extra options at the bottom, set the condition to ‘environment variable’ and enter the values as follows:

From now on, whenever you run the pipeline manually, Buddy will ask you which version type you want to increase. If neither major nor minor is selected, the patch number will be incremented.

3.3 Set version number

The next step is adding an action with the versioning script. Select the Custom build action and paste the script below in the commands field. The script raises the selected version type by 1 and creates the tag for your commit:

if [ -n "$is_major" ] && ($is_major) ; then 
 ((major=major+1))
 minor=0
 patch=0
elif [ -n "$is_minor" ] && ($is_minor) ; then
 ((minor=minor+1))
 patch=0
else
 ((patch=patch+1))
fi
latest_version=$major"."$minor"."$patch
#add tag
git tag "$latest_version"

Buddy uses isolated Docker containers to run build commands. The results are then saved to the filesystem and used across the whole pipeline.

3.4 Push the tag to the repository

With the version defined and tag created, we can finally push it to our project. Select the Git Push action and configure authentication details to your repository:

You can also use environmental variables to store sensitive data like server credentials.

Summary

When ready, make a push to your repository and check the results. Then, run the pipeline in manual mode: if everything’s been configured correctly, Buddy will ask you for the version type and increment the tag in your repository:

Buddy is 100% customer driven. If there’s a feature or integration you miss, let us know in the comments below or directly at support@buddy.works.