CI/CD: Enforcing release number in Subversion (SVN) commit messageGepubliceerd: Auteur: Richard Velden Categorie: Oracle
While working on our CI/CD implementation, we were looking for a way to enforce everyone to include the release number in the SVN commit message. However, this should happen only whenever someone merges into the Release branch. Our automated build script uses this release number from the SVN commit to version each component and release artifact. We will show how to enforce this on the SVN server using a pre-commit hook.
Use case: Release number
Each time a developer merges changes into the release branch, our CI/CD server kicks in to build and deploy a new release. In our case, we require developers to enter a release number into the SVN commit message, to enable our build/deploy scripting to determine the version of this release and its artifacts.
Using a pre-commit hook, SVN enables administrators to do a few checks before actually committing sources into the repository.
Each time before a commit is persisted, a batch script is run from the SVNROOT folder.
Pre-commit hook requirements
First, our pre-commit hook should only enforce a release number in the comments for commits in the release branch. Secondly, we need to check the commit message to contain a specific release number format.
SVN provides us with a great utility (svnlook) to get information about a specific commit transaction. We were content with only the use of ‘svnlook log’ and ‘svnlook changed’.
For the first requirement, we used the svnlook changed command to see what folder location was changed. Every time we find /branches/Release we need to check the commit message/
For the second requirement, we’ve used svnlook log to check the commit message.
In the next sections, we will show both a Linux and Windows implementation of this particular pre-commit hook.
- echo "Repository $REPOS" >&2
- echo "TXN $TXN" >&2
- RELEASE=`$SVNLOOK log -t "$TXN" "$REPOS" | grep -o "SOA_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]"`
- FOLDER=`$SVNLOOK changed "$REPOS" | grep -o "SOA/branches/Release"`
- # Only check the release branch
- if [ "$FOLDER" == "SOA/branches/Release" ]
- # If the RELEASE variable does not contain any match, raise error and abort commit (exit1)
- if [ "$RELEASE" == "" ]
- echo "No valid release number (e.g.: SOA_2019_41_01)" >&2
- exit 1
- echo "Valid release number found $RELEASE" >&2
- # All checks passed, so allow the commit.
- exit 0
- setlocal EnableDelayedExpansion
- set REPOS=%1
- set TXN=%2
- svnlook changed %REPOS% -t %TXN% | findstr "SOA/branches/Release" > null >&2
- if not errorlevel 1 (
- svnlook log %REPOS% -t %TXN% | findstr /R "SOA_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]" > null >&2
- if errorlevel 1 (goto err)
- exit 0
- echo. 1>&2
- echo REPOS %REPOS% 1>&2
- echo TXN %TXN% 1>&2
- echo Your commit has been blocked because you didn't enter a valid release number (e.g.: SOA_2019_41_01). 1>&2
- echo Please write a log message containing a release number and describe the changes made and try again. 1>&2
- echo Thanks 1>&2
- exit 1