2014-01-08 63 views
1

的自動每週增量有任何提示,如何可以每週增加下方數字的第二部分(「249」)? TeamCity能夠在每次構建構建計數器的數量後增加,迄今爲止非常好。團隊城市 - 內部編號爲

1.0。 %build.counter%

此外,我需要自動增加每週的249。 例如:249> 250; 250> 251; 101> 102; 41> 42; ...

在此先感謝。

回答

6

您可以通過在PowerShell構建步驟中以編程方式重新定義build.number來實現此目的。

  1. 添加一個PowerShell構建步驟爲配置中的第一步。
  2. 設置在構建步驟如下參數:
    • Script源代碼
    • Script execution mode有 「文件」 執行的.ps1腳本參數
    • Script source
Write-Host "##teamcity[buildNumber '1.0.$([Math]::Floor([DateTime]::Now.DayOfYear/7)).%build.counter%']"

所有後續生成步驟應能夠使用新的build.number值。

$([Math]::Floor([DateTime]::Now.DayOfYear/7))是魔法;它會產生一年當前的一週。您需要按摩一下,以符合您現有的編號。

關於重複使用的說明:您需要參數化主要/次要值1.0,以便跨多個項目重複使用此步驟。我會定義一個參數,%major.minor%,並將其值設置爲1.0,然後將PowerShell腳本將是這個(或其他):

Write-Host "##teamcity[buildNumber '%major.minor%.$([Math]::Floor([DateTime]::Now.DayOfYear/7)).%build.counter%']"

編輯:由雅各布提到切換到簡單Write-Host實現。

+0

我希望這樣也能正常工作,但無法使其工作。我決定查看[SemVer Metarunner]的源代碼(https://github.com/JetBrains/meta-runner-power-pack/blob/master/semver-buildnumber/MRPP_SemVer_BuildNumber.xml),並注意到它們使用了不同的語法: 'Write-Host「## teamcity [buildNumber'$ BuildNumber']」' 我切換到該格式並且它工作,所以它可能因TeamCity版本而異。另外請注意,設置buildNumber這似乎不適用於AssemblyInfo,因爲它在構建中很早就做到了。 – Jacob

+0

我正在尋找解決方案來獲取組件中創建的版本號。現在它使用assemblyinfopatcher步驟添加buildnumber,並在我的構建中使用創建的數字更新versionnumber。但正如你所提到的,這個步驟在assemblyinfopatcher步驟之後運行。你有沒有設法解決這個問題? –

+0

那個聰明的「回話給TC」功能的文檔在這裏:https://confluence.jetbrains.com/display/TCD9/Build+Script+Interaction+with+TeamCity –

0

在TeamCity中尋找一種自定義構建號的方法時,偶然發現了這個問題。由@ john-hoerr提供的答案完美工作(謝謝)。

我採取了約翰的答案,並根據我的需要對其進行了修改。這裏是一個PowerShell腳本,將使用所提供的版本號格式從構建配置設置的日期格式(任何性質的)常規選項卡,更新的版本號,從TeamCity的構建計數器:

# The build number format is YYDDD.BB 
# YY is the last two digits of the year 
# DDD is the day number in the year (1-365) 
# BB is the build number of the day for this build type (1-N) 

# Get the build number from TeamCity. This will contain whatever is placed 
# into the build number portion of the build definition 
$TeamCityBuildNumber = "%build.number%" 

# Get the build counter from TeamCity and ensure it's in the format 00 (for sorting). 
# Assumption: there are less than 100 builds a day for this build definition. 
$TeamCityBuildCounter = "%build.counter%".PadLeft(2, "0") 

# The build number really just contains the date portion of the whole build number string. I am tweaking it to also contain a branch name but have removed this from my example code for simplicity purposes. 
$BuildNumber = ([string]::Concat(([DateTime]::Now.Date.Year - 2000),([DateTime]::Now.DayOfYear))) 

# Write the build number to the host, effectively altering the build number 
# within the process space of the build. 
Write-Host "##teamcity[buildNumber '$TeamCityBuildNumber.$BuildNumber.$TeamCityBuildCounter']" 

理想構建計數器在午夜重置爲0,以便當天的第一次構建的構建計數器值爲1.

+0

你如何重置構建計數器爲每晚1? – StupidFox