Agent Wranglers

ENG-7Recommended

Stamp every build with its version

Give every build a version and the commit it came from. Show both in the running app, and tag each release in version control.

How to do it

Pass the version and commit hash into the build, for example as build arguments or a generated file. Never type them by hand. Return them from a version address or the health check, and add them to every log line and error report. Tag the commit of every production release, such as v2026.10.20-1 or a semantic version for a library. Send the version to the dashboards as a deploy marker.

Examples

Shell example

docker build --build-arg VERSION="$(git describe --tags --always)" --build-arg COMMIT="$(git rev-parse HEAD)" .

JavaScript example

// The Dockerfile turns the build arguments into environment variables
app.get('/version', (req, res) => {
  res.json({ version: process.env.VERSION, commit: process.env.COMMIT });
});

Python example

# Flask
@app.get("/version")
def version():
    return {"version": os.environ["VERSION"], "commit": os.environ["COMMIT"]}

Go example

// Set at build time: go build -ldflags "-X main.commit=$(git rev-parse HEAD)"
var commit = "unknown"

http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
	json.NewEncoder(w).Encode(map[string]string{"commit": commit})
})

How to check

After a deploy, the version address returns the commit hash of the deployed commit. git tag --points-at <that commit> prints the release tag.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/engineering/build-test-and-deploy/version-every-release">Agent Wranglers engineering playbook</a>. In code you write, add a comment next to it with the same link.