Skip to content

Instantly share code, notes, and snippets.

@mocella
Created February 16, 2024 14:47
Show Gist options
  • Save mocella/59e188a1a563c39eb7cada33e2d36dd2 to your computer and use it in GitHub Desktop.
Save mocella/59e188a1a563c39eb7cada33e2d36dd2 to your computer and use it in GitHub Desktop.
Finish Release ADO Pipeline and Bash Script
#!/bin/bash
git --version
BUILD_SOURCE_BRANCH=$1
if [[ -z ${BUILD_SOURCE_BRANCH} ]]; then
echo "Null source branch"
exit 1
fi
git config --global user.email "[email protected]"
git config --global user.name "DevOps"
SOURCE_BRANCH=`echo ${BUILD_SOURCE_BRANCH} | cut -d'/' -f3-4`
VERSION=`echo ${SOURCE_BRANCH} | cut -d'/' -f2`
echo "REPOSITORY"
git remote -v
echo "BUILD SOURCE BRANCH ${BUILD_SOURCE_BRANCH}"
echo "SOURCE BRANCH ${SOURCE_BRANCH}"
echo "VERSION ${VERSION}"
if [[ "${SOURCE_BRANCH}" != *"release"* ]]; then
echo "source branch must be a release branch"
exit 1
fi
# Enable exit on errors so script will die if any one command fails
set -e
echo "CHECKING OUT SOURCE BRANCH"
git checkout -f $SOURCE_BRANCH
git pull
echo "CHECKING OUT MASTER"
git checkout -f master
git pull
#FOR /F %%i IN ('git rev-list --left-only --count origin/master...%sourceBranch%') DO SET aheadCountMaster=%%i
#If %aheadCountMaster% NEQ 0 (echo "Release branch is behind master!" & exit /b 1)
MASTERCNT=`git rev-list --left-only --count origin/master...${SOURCE_BRANCH}`
if [[ ${MASTERCNT} -ne 0 ]]; then
echo "release branch is behind master! Aborting merge..."
exit 1
fi
echo "MERGING RELEASE INTO MASTER"
git merge --ff -m "${VERSION}" $SOURCE_BRANCH
echo "CREATING TAG"
git tag -a $VERSION -m "${VERSION}"
echo "CHECKING OUT DEVELOP"
git checkout develop
git pull
echo "MERGING RELEASE INTO DEVELOP"
git merge --ff -m "${VERSION}" $SOURCE_BRANCH
echo "MERGING TAG INTO DEVELOP"
git merge $VERSION
echo "PUSHING MASTER"
git push origin master
echo "PUSHING DEVELOP"
git push origin develop
echo "PUSHING TAGS"
git push origin $VERSION
echo "DELETING RELEASE"
git push origin --delete $SOURCE_BRANCH
set +e
pool:
name: DefaultPool
# Do not automatically trigger build
trigger: none
steps:
- checkout: self
clean: true
persistCredentials: true
- bash: |
chmod +x ./finish-release.sh
./finish-release.sh $(Build.SourceBranch)
displayName: 'Run Finish Release Script'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment