dockerjenkinssemantic-versioning

Semver: Automate tagging and push with Jenkins


My default/base docker image on my project builds tag 1.0.0. My goal is to automate that with a semver versioning on my Jenkins build so on my next build , tag and push, the next version should be 1.1.0 then 1.2.0, etc ... I have this bash script below to add to my build that I am calling from Jenkins but the tag I get is 1.0.1. Please let me know what I am missing. I know I am close.

#!/bin/bash

latest_tag="1.0.0"

# Extract the MAJOR, MINOR, and PATCH numbers from the latest tag
IFS='.' read -r -a version_parts <<< "$latest_tag"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}

# Determine the type of version bump
if [ "$1" == "major" ]; then
    major=$((major + 1))
    minor=0
    patch=0
elif [ "$1" == "minor" ]; then
    minor=$((minor + 1))
    patch=0
else
    patch=$((patch + 1))
fi

# Construct the new version tag
new_tag="$major.$minor.$patch"

# Output the new tag
echo $new_tag

Thanks


Solution

  • what I am missing

    The argument to the script ./versioning.sh minor.