Skip to content

Instantly share code, notes, and snippets.

@kaosf
Created June 26, 2022 06:48
Show Gist options
  • Save kaosf/42610e6ea58fea778fdb8985efaafce8 to your computer and use it in GitHub Desktop.
Save kaosf/42610e6ea58fea778fdb8985efaafce8 to your computer and use it in GitHub Desktop.
Update `releaseVersion = '.*'` in `Jenkinsfile` automatically.
#!/bin/bash
VERSION_LINE=$(grep "releaseVersion = '.*'" Jenkinsfile)
[[ $VERSION_LINE =~ releaseVersion\ =\ \'(.*)\' ]] && VERSION=${BASH_REMATCH[1]}
if [[ -z $VERSION ]]; then
echo "Could not find version in Jenkinsfile"
VERSION=$(date +%Y%m%d).0
else
DATE=$(echo $VERSION | cut -d. -f1)
TODAY=$(date +%Y%m%d)
if [[ $DATE == $TODAY ]]; then
VERSION=$(echo $VERSION | cut -d. -f2)
VERSION=$((VERSION+1))
VERSION=$DATE.$VERSION
else
VERSION=$TODAY.0
fi
fi
read -p "$VERSION, OK? y/N: " -n 1 -r ANSWER
if [[ $ANSWER != "y" ]]; then
VERSION=""
while [[ -z $VERSION ]]; do
read -p "Version: " VERSION
done
fi
sed -i Jenkinsfile -e "s/releaseVersion = '.*'/releaseVersion = '$VERSION'/"
git add Jenkinsfile
git commit -m "Version $VERSION"
@kaosf
Copy link
Author

kaosf commented Jun 26, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment