我有一個CI構建定義(TFS 2013),由提交到幾個分支(它是一個git存儲庫)觸發。我想在構建過程中使用分支名稱將結果複製到正確的位置。我怎樣才能做到這一點?在TFS內部獲得git分支名稱
1
A
回答
3
使自己的CodeActivity就像這個...
您需要的IBuildDetail BuildDetail爲InArgument。
string branch = null;
string commit;
var environmentVariable = BuildDetail.Get(context);
if (environmentVariable != null && !BuildSourceVersion.TryParseGit(environmentVariable.SourceGetVersion, out branch, out commit))
{
var defaultSourceProvider = environmentVariable.BuildDefinition.GetDefaultSourceProvider();
if (BuildSourceProviders.IsGit(defaultSourceProvider.Name))
{
branch = BuildSourceProviders.GetProperty(defaultSourceProvider.Fields, BuildSourceProviders.GitProperties.DefaultBranch);
}
}
if (string.IsNullOrEmpty(branch))
{
throw new Exception("Could not find Branch");
}
Branch.Set(context, branch.Substring(branch.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase) + 1));
1
有整個構建過程中.git
文件夾訪問,這樣我就可以考慮使用PowerShell中的文件.git/HEAD
。可能只有提交hash(detached HEAD機制),然後需要一些更多的git調用來找出我真正的位置。總而言之,其他答案可能更清潔。
+0
嗨Lukáš,你是否設法從.git/HEAD中找到分支名稱?如果創建自己的CodeActivity,我更喜歡這個解決方案。謝謝。 – Chatumbabub
+1
你好,你可以使用'git branch --all --contains'獲取當前提交的所有分支名稱,這對於你的用例來說已經足夠了。 –
相關問題
- 1. 在TFS中使用git分支名稱
- 2. 無法在bash中獲得正確的git分支名稱
- 3. 重命名TFS 2010分支,使得在相同的名稱
- 4. Git Bash,獲取本地分支名稱
- 5. IntelliJ和Git分支名稱
- 6. git和分支名稱
- 7. 如何獲得給定shasum的git分支名稱?
- 8. 獲取TFS觸發構建Git分支
- 9. 在git中切換分支名稱
- 10. 創建別名的Git分支名稱
- 11. TFS Git分支文檔
- 12. 通過分支名稱\ id與git api獲取git提交
- 13. 如何讓git分支名稱成爲SonarQube項目名稱的一部分?
- 14. 用git tfs合併兩個TFS分支
- 15. git - 用部分分支名稱擴展commit hook
- 16. 如何獲得在GIT中創建標籤的特定分支的名稱
- 17. Git的 - 刪除遠程分支,在該分支名稱空間
- 18. 在構建過程中獲取git分支名稱
- 19. 在git中獲取父原始分支的名稱?
- 20. 在Jenkins Jenkinsfile中獲取git分支名稱
- 21. 如何在Mac OSX上獲取分支名稱的Git完成?
- 22. 的Git分支/標籤名稱^ {}
- 23. posh-git顯示長分支名稱
- 24. git post hook中的分支名稱
- 25. Jenkins - 管道訪問git分支名稱
- 26. 重用的Git分支名稱
- 27. git diff分支 - 名稱狀態--ignore
- 28. 提示中的Git分支名稱
- 29. Git teamcity中的短分支名稱
- 30. 開關分支的部分名稱
感謝您的回答!我想這會起作用。最後,我選擇了腳本,但如果我們決定更多地使用TFS基礎架構,我將會很快使用您的解決方案。 –
這很好。在F#中,我使用了'let _,branch,commit = BuildSourceVersion.TryParseGit x.SourceGetVersion'。作爲SourceLink.Tfs中的擴展添加。 https://github.com/ctaggart/SourceLink/commit/058e071583578d22bcb2e0a87ede4c7b382b4279 –
你打開'GitTemplate.xaml'並添加一個代碼活動,只是在這裏代碼這個代碼? –