DevOps Tutorial · Git and CI/CD · Lesson 14 of 25

Versioning and Artifacts

Version releases with semantic versioning and Git tags, and store build outputs in artifact and container registries.

Create a free account to save this page, take notes and track your progress. Sign in

Semantic versioning

MAJOR.MINOR.PATCH, for example 2.4.1:

  • MAJOR for incompatible changes,
  • MINOR for new backward-compatible features,
  • PATCH for backward-compatible fixes.

Libraries and APIs others depend on should follow it strictly. Services deployed continuously often just use the commit SHA or a build number.

Bumping semantic versionsTry it yourself
def bump(version, change):
    major, minor, patch = map(int, version.split("."))
    if change == "breaking":
        return f"{major + 1}.0.0"
    if change == "feature":
        return f"{major}.{minor + 1}.0"
    return f"{major}.{minor}.{patch + 1}"

version = "2.4.1"
for change in ["fix", "feature", "breaking"]:
    print(f"{version} + {change:8} -> {bump(version, change)}")

Output

2.4.1 + fix      -> 2.4.2
2.4.1 + feature  -> 2.5.0
2.4.1 + breaking -> 3.0.0

Tags

Mark releases with Git tags; many pipelines publish a release when a tag like v2.4.1 is pushed.

Tagging releases
git init -q -b main lib && cd lib
echo "1" > v && git add . && git commit -qm "Release 1.0" && git tag v1.0.0
echo "2" > v && git commit -qam "Add export" && git tag v1.1.0
echo "3" > v && git commit -qam "Fix export bug" && git tag v1.1.1
git tag --sort=-v:refname
echo "changes since v1.1.0:"
git log --oneline v1.1.0..HEAD

Output

v1.1.1
v1.1.0
v1.0.0
changes since v1.1.0:
2a3f500 Fix export bug

Run this on your computer — see “Get Started” for setup.

Artifacts and registries

An artifact is a build output: a container image, a .jar, a Python wheel, a zipped Lambda function. Store them in a registry (Amazon ECR, Azure Container Registry, Google Artifact Registry, GitHub Packages, JFrog Artifactory, Nexus), never rebuild them per environment, and:

  • tag images with the commit SHA (immutable) plus convenience tags, and deploy by SHA or digest;
  • turn on vulnerability scanning and retention rules;
  • make tags immutable so v2.4.1 can never point to different content.

Test yourself

A library adds a new optional parameter without breaking existing callers. Version 3.2.5 becomes...

  1. 4.0.0
  2. 3.3.0
  3. 3.2.6
  4. 3.2.5-new
Show answer

Answer: 3.3.0

A backward-compatible feature bumps MINOR and resets PATCH.

Was this page helpful?