fix: switch GitVersion to ContinuousDelivery mode
ContinuousDeployment + tag: '' causes GitVersion to emit a clean version (e.g. 1.2.5) on every untagged main commit, making it impossible to distinguish released from unreleased builds.
Change
# GitVersion.yml
mode: ContinuousDelivery # was: ContinuousDeployment
ContinuousDelivery mode preserves tag: '' semantics while appending build metadata to untagged commits:
| State | Before | After |
|---|---|---|
Untagged commit on main
|
1.2.5 |
1.2.5+3 → Docker: 1.2.5-3 |
Tagged commit (v1.2.5) |
1.2.5 |
1.2.5 |
Original prompt
Problem
Currently
GitVersion.ymlusesmode: ContinuousDeploymentwithtag: ''on themainbranch. This causes GitVersion to produce a clean version like1.2.5even when the1.2.5tag has not been created yet (the latest tag is1.2.4). The expected behavior is that untagged commits should produce a version with build metadata like1.2.5+3, and only produce a clean1.2.5when the tag is actually created.Fix
In
GitVersion.yml, changemodefromContinuousDeploymenttoContinuousDelivery. Everything else stays the same.Before:
mode: ContinuousDeployment tag-prefix: '[vV]?' branches: main: regex: ^main$ tag: '' increment: PatchAfter:
mode: ContinuousDelivery tag-prefix: '[vV]?' branches: main: regex: ^main$ tag: '' increment: PatchThis single-line change ensures:
- Untagged commits on
mainproduce versions like1.2.5+3(with build metadata)- Only when the
1.2.5tag is actually created will GitVersion output a clean1.2.5The following is the prior conversation context from the user's chat exploration (may be truncated):
User: 目前gitversion產生了是1.2.5,但是目前還沒tag 1.2.5,应该错的。分析一下,应该是1.2.5-xxx之類的才對。
Assistant:
Let me look at the failing job logs and understand the GitVersion configuration.
Assistant: 找到根本原因了。問題出在你的
GitVersion.yml配置。問題分析
你目前最新的 tag 是
1.2.4(發佈於 2026-04-13),還沒有1.2.5tag。當main上有新 commit(在1.2.4之後),GitVersion 應該產生類似1.2.5-ci.3這樣的 pre-release 版號,但它卻直接產生了1.2.5。根因:
tag: ''(空字串)mode: ContinuousDeployment tag-prefix: '[vV]?' branches: main: regex: ^main$ tag: '' increment: Patch在 GitVersion 中,
tag: ''(空字串)的意思是:不加任何 pre-release 標籤。這代表 GitVersion 在main分支上會直接產出乾淨的1.2.5,即便還沒有這個 tag 存在。這是
ContinuousDeploymentmode 的特性——它會自動遞增版號。搭配tag: '',就等於告訴 GitVersion:「main 上的每個 commit 都是正式版本」,所以1.2.4之後的下一個 commit 直接變成1.2.5。修正方式
如果你希望在 tag
1.2.5真正打上去之前,版號帶有 pre-release 後綴(如1.2.5-ci.3),有兩種做法:方案 A:改
tag為非空字串(推薦)mode: ContinuousDeployment tag-prefix: '[vV]?' branches: main: regex: ^main$ tag: ci increment: Patch這樣 GitVersion 會產生:
1.2.5-ci.1、1.2.5-ci.2、1.2.5-ci.3...
直到你真正打了1.2.5tag 時,才會輸出乾淨的1.2.5。方案 B:改用
ContinuousDeliverymodemode: ContinuousDelivery tag-prefix: '[vV]?' branches: main: regex: ^main$ tag: '' increment: Patch在
ContinuousDelivery模式下,即便tag: '',GitVersion 也會在未打 tag 的 commit 上產生帶有+Nmetadata 的版號(如1.2.5+3),不過+在 Docker tag 中會被你的 workflow 替換成-,變成1.2.5-3。兩種模式的差異
ContinuousDeploymentContinuousDelivery理念 每個 commit 都可能直接部署 版本由人工打 tag 決定 tag: ''行為直接給乾淨版號( 1.2.5)← 你目前的問題給帶 metadata 的版號( 1.2.5+3)tag: 'ci'行為給 1.2.5-ci.3給 1.2.5-ci.3建議
如果你的流程是「先合併到 main → CI 產 Docker image → 確認沒問題後手動打 tag 做正式 release」,那 方案 A(
tag: ci)最符合你的需求。這樣 Docker image 會被標記為1.2.5-ci.3,等到你打了1.2.5tag 後再觸發一次 CI,才會產生真正的1.2.5image。需要我幫你開一個 PR 來修正這個
GitVersion.yml嗎?User: 流程是你说的对的。但是我想这种格式:給帶 metadata 的版號(1.2.5+3)
Assistant:
所以你想要的是:
- 未打 tag 時:
1.2.5+3(Docker tag 會變成1.2.5-3)- 打了 tag 時:乾淨的
1.2.5那就是 方案 B:改用
ContinuousDeliverymode,保持tag: ''不變。mode: ContinuousDelivery tag-prefix: '[vV]?' branches: main: regex: ^main$ tag: '' increment: Patch唯一的改動就是
mode: ContinuousDeployment→mode: ContinuousDelivery。需要我幫你開 PR 嗎?
User: 需要
Assistant:
Let me first check the failing job to understand the current state, then create the PR.
Assistant: We're waiting for your confirmation to proceed with creating the pull request. Please accept or reject the pending tool call to continue.
This pull request was created from Copilot chat.