2016-07-05 72 views
0

我有一個包含我添加到TeamCity中的各種包的項目的Git回購。如何正確觸發TeamCity構建git上的單個包?

回購組織這樣的:

README.md 
packages/ 
packages/buildscript 
packages/packageOne/manifest (and files) 
packages/packageTwo/manifest (and files) 
packages/packageThree/manifest (and files) 

我想配置TeamCity的執行buildscript建立一個特定的包時,它要麼修改或添加到該回購協議。

我已經有了運行buildscript作爲構建步驟的一部分,但我不知道如何確保每個包下載和buildscript跑了每一個。

目前buildscript接收包名稱,做一些工作,然後運行一個NuGet包。

我是在想,我必須寫構建檢測哪些軟件包已經改變步驟正確,然後做每包所需的行動?就像這樣:

  1. 拉包

  2. 軟件包運行buildscript

  3. 推到的NuGet飼料

還是有內置的功能做一些步驟?

編輯:

目前,我有它設置,使後更改了Git的回購做,所有的包都將被重建......這顯然是很麻煩。

似乎我需要爲每個包創建一個構建配置,如果我希望它們單獨觸發。這發生在我

一種解決方案是有一個步驟,它確定了哪些軟件包自上次構建更新,然後執行爲他們每個人的構建腳本。因此,我現在正在尋求建議有效的方法,可能涉及在某些構建步驟腳本中運行Git命令。

回答

1

你有兩個選擇:

  1. 設置爲每個包單獨構建配置,添加一個觸發器,如果​​在包目錄中的文件發生了變化,將只進行構建。
  2. 作爲構建的一部分,得到改變的文件(見TeamCity, how to get names of the files edited單程,或使用TeamCity的API,例如下圖)的列表,閱讀這些變化,只有觸發已更改的包構建。

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 />" } 
     } 
    } 
} 
+0

感謝您的信息!我最終修改了我的構建步驟,如下所示: 'Get-Content「%system.teamcity.build.changedFiles。file%「| Select-String -Pattern」packages/*「|%{($ _ -split」:「)[0]} |%{($ _ -split」/「)[1]} | Sort-Object -Unique | Where-Object {Test-Path $ _ -PathType容器} |%{。\ build $ _}' 關於以下更改: 'packages/packageOne/manifest.nuspec:CHANGED:[hash] 包/ packageTwo /工具/ chocolateyInstall.ps1:CHANGED:[散列] 包/ README.md:CHANGED:[散列] file.txt的:CHANGED:[散列] README.md Otherscript.ps1' packageOne& packageTwo將腳本運行:) –

+0

對SE的第一評論,所以我不知道有關字符限制,有點搞砸了我的意圖評論,但我希望任何人想知道我如何結束去得到這是它的要點。 –

相關問題