---
title: "Stamp every build with its version · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/version-every-release
updated: 2026-10-20
licence: "All rights reserved"
---

# Stamp every build with its version

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy)
- Rule: 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: 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](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/health-check-and-rollback), 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](https://agentwranglers.se/playbook/operations/metrics-and-traces/deploy-markers).
- 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.

Example:

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

```js
// 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
# Flask
@app.get("/version")
def version():
    return {"version": os.environ["VERSION"], "commit": os.environ["COMMIT"]}
```

```go
// 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})
})
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers engineering playbook: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/version-every-release`.

- Previous: [Run the tests inside the container build](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/container-build-gated-by-tests)
- Next: [Deploy in one step and roll back by itself](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/atomic-deploys-with-rollback)
- [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy)
