[英]How to properly trigger TeamCity to build for a single package on git?
我有一個項目的Git存儲庫,其中包含我已添加到TeamCity的各種軟件包。
回購的組織方式如下:
README.md
packages/
packages/buildscript
packages/packageOne/manifest (and files)
packages/packageTwo/manifest (and files)
packages/packageThree/manifest (and files)
我想配置TeamCity來執行構建腳本,以在修改或添加到倉庫中時構建特定的程序包。
作為構建步驟的一部分,我已經運行了構建腳本,但是我不知道如何確保下載了每個軟件包並為每個構建了構建腳本。
當前,構建腳本采用包名稱,進行一些工作,然后運行NuGet包。
我是否正確地認為必須編寫構建步驟來檢測哪些軟件包已更改,然后對每個軟件包執行必要的操作? 像這樣:
拉包
在包上運行buildscript
推送至NuGet提要
還是有內置功能可以執行某些步驟?
編輯:
目前,我已經進行了設置,以便在對Git存儲庫進行更改之后,可以重新構建所有軟件包……這顯然很麻煩。
如果希望它們分別觸發,似乎需要為每個軟件包創建一個構建配置。
我想到的一個解決方案是第一步,確定自上次構建以來已更新了哪些軟件包,然后針對每個軟件包執行構建腳本。 因此,我現在正在尋求有關有效方法的建議,可能涉及在某些構建步驟腳本中運行Git命令。
您有兩種選擇:
Powershell可以獲取更改的文件並提交日志。 只是我的設置的副本粘貼。 這些功能要求您傳入服務器Url,用戶名,密碼和內部版本ID,所有這些都可以在TeamCity的運行時獲得。
# Gets the change log for the specified build ID
function TeamCity-GetChangeLog($serverUrl, $username, $password, $buildId){
$buildUrl = "$serverUrl/httpAuth/app/rest/changes?build=id:$($buildId)"
$authToken = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($username + ":" + $password))
# Get all the changes
$request = [System.Net.WebRequest]::Create($buildUrl)
$request.Headers.Add("AUTHORIZATION", "$authToken");
$xml = [xml](new-object System.IO.StreamReader $request.GetResponse().GetResponseStream()).ReadToEnd()
# Get all commit messages for each of them
$changelog = Microsoft.PowerShell.Utility\Select-Xml $xml -XPath `
"/changes/change" | Foreach {
TeamCity-GetCommitMessage $serverUrl $username $password $_.Node.id
}
return $changelog
}
# Get the commit messages, and files changed for the specified change id
# Ignores empty lines, lines containing "#ignore", "merge branch"" or "TeamCity"
Function TeamCity-GetCommitMessage($serverUrl, $username, $password, $changeId)
{
$getFilesChanged = $false;
$request = [System.Net.WebRequest]::Create("$serverUrl/httpAuth/app/rest/changes/id:$changeId")
$authToken = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($username + ":" + $password))
$request.Headers.Add("AUTHORIZATION", "$authToken");
$xml = [xml](new-object System.IO.StreamReader $request.GetResponse().GetResponseStream()).ReadToEnd()
Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/change" |
where { ($_.Node["comment"].InnerText.Length -ne 0) `
-and (-Not $_.Node["comment"].InnerText.Contains('#ignore')) `
-and (-Not $_.Node["comment"].InnerText.StartsWith("Merge branch")) `
-and (-Not $_.Node["comment"].InnerText.StartsWith("TeamCity change"))} |
foreach {
$getFilesChanged = $true;
"<br /><strong>$($_.Node["user"].name.Trim() + " on " + ([System.DateTime]::ParseExact($_.Node.Attributes["date"].Value, "yyyyMMddTHHmmsszzzz", [System.Globalization.CultureInfo]::InvariantCulture)))</strong><br /><br />"
"$($_.Node["comment"].InnerText.Trim().Replace("`n", "`n<br />"))"
}
if ($getFilesChanged) {
"<br /><br /><strong>Files Changed</strong><br /><br />"
Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/change/files" |
where { ($_.Node["file"].Length -ne 0)} |
foreach { Select-Xml $_.Node -XPath 'file' |
foreach { "$($_.Node.Attributes["file"].Value)<br />" }
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.