Add CI_MERGEREQUEST_SOURCE and CI_MERGEREQUEST_COMMIT to gitlab-ci.yml predefined variables

With those variables we could execute a script to automatically create a new tag whenever a merge request is accepted. Basically, the idea here is to check the branch's name to determine which version number will be incremented.

.gitlab-ci.yml

versioning:
    stage: packaging
    script:
    - increment_version.sh $CI_MERGEREQUEST_SOURCE $CI_MERGEREQUEST_COMMIT
    only: master`

increment_version.sh

SOURCE_BRANCH=`echo $1 | awk -F'/' '{print toupper($1)}'`
TAG_COMMIT=``git rev-list --tags --max-count=1``
VERSION=`git describe --tags $TAG_COMMIT | sed "s/^//"`
MAJOR=`echo $VERSION | sed "s/^\([0-9]*\).*/\1/"`
MINOR=`echo $VERSION | sed "s/[0-9]*\.\([0-9]*\).*/\1/"`
PATCH=`echo $VERSION | sed "s/[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/"`
BUILD=$2

NEXT_MAJOR_VERSION=`expr $MAJOR + 1`.0.0-b$BUILD
NEXT_MINOR_VERSION=$MAJOR.`expr $MINOR + 1`.0-b$BUILD
NEXT_PATCH_VERSION=$MAJOR.$MINOR.`expr $PATCH + 1`-b$BUILD

if [[ $SOURCE_BRANCH == "CHANGE" ]]; then
	echo git tag -a $NEXT_MAJOR_VERSION
elif [[ $SOURCE_BRANCH == "FEATURE" ]]; then
	echo git tag -a $NEXT_MINOR_VERSION
elif [[ $SOURCE_BRANCH == "PATCH" ]]; then
	echo git tag -a $NEXT_PATCH_VERSION
else
	echo "ERROR: Branch name must start with CHANGE, FEATURE or PATCH, nevertheless source branch is $SOURCE_BRANCH."
	exit 1
fi

~"feature proposal"

Edited Aug 20, 2020 by Jackie Porter
Assignee Loading
Time tracking Loading