![](/img/trans.png)
[英]How to Check-in a file in BitBucket Repository with TFS CI Build Definition?
[英]Azure DevOps pipeline task to update a file and check-in TFS
我正在使用 Azure Dev OPS 來觸發構建和部署。 我在 GIT 分支中有角度代碼,構建將從中觸發,並且基於構建#我需要更新 TFS 中的文件並簽入相同的文件。
我添加了 PowerShell 任務以從 GIT 分支讀取 build#。 但我不知道在 TFS 分支中更新文件和簽入文件的進一步步驟。
請建議 PowerShell 命令以實現上述任務。
用於更新文件和簽入 TFS 的 Azure DevOps 管道任務
您可以調用 REST API 推送 - 創建以更新文件並使用 powershell 腳本在 TFS 分支中簽入相同的文件。
轉到代理階段並選擇允許腳本訪問 OAuth 令牌。 請參閱使用 OAuth 令牌訪問 REST API :
在構建管道中添加一個 PowerShell 任務,以獲取要更新文件並簽入的分支上的最新提交:
GET https://{instance}/{collection}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=5.0&branch={BranchName}&$top=1
通過 REST API 更新文件並在 TFS 分支中簽入相同文件:
POST https://{instance}/{collection}/{project}/_apis/git/repositories/{repositoryId}/pushes?api-version=5.0
正文(應用程序/json):
{
"refUpdates": [
{
"name": "refs/heads/$(BranchName)",
"oldObjectId": "[step 2 commit ID]"
}
],
"commits": [
{
"comment": "Added a few more items to the task list.",
"changes": [
{
"changeType": "edit",
"item": {
"path": "/tasks.md"
},
"newContent": {
"content": "# Tasks\n\n* Item 1\n* Item 2\n* Item 3\n* Item 4\n\nIf you need to add more, update this file and add them!",
"contentType": "rawtext"
}
}
]
}
]
}
作為測試結果:
筆記:
repositoryId
。希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.