[英]Azure CLI creating a new branch from a task
I'm tring to automate task and branch creation on Azure boards- but am stuggling to programtically create a branch, once the task is created.我正在尝试在 Azure 板上自动创建任务和分支 - 但是一旦创建任务,我就会努力以编程方式创建分支。 I'm using the Azure/Azure Devops extensions in PowerShell, but can't see anything in the docs that would replicate the 'create branch' link pictured below:
我在 PowerShell 中使用 Azure/Azure Devops 扩展,但在文档中看不到任何可以复制下图所示的“创建分支”链接的内容:
Any help appreciated任何帮助表示赞赏
To programmatically create a branch, here are two methods:要以编程方式创建分支,这里有两种方法:
Az CLI: run Az CLI:运行
az repos ref create --name refs/heads/{branch name} --object-id {Id of the object to create the reference from} --organization https://dev.azure.com/{org name} --project {project name} --repository {repos name}
Rest API: Rest API:
Get the repository ID in project setting >> your repo or use REST API Repositories - List and use REST API Refs - List with filter=<BranchName>
to get the oldObjectId
for your specific branch: Get the repository ID in project setting >> your repo or use REST API Repositories - List and use REST API Refs - List with
filter=<BranchName>
to get the oldObjectId
for your specific branch:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?filter=heads/master&api-version=5.1
Use the Initial commit (Create a new branch) to create a branch from a specific branch with the following Request Body.使用初始提交(创建新分支)从具有以下请求正文的特定分支创建分支。
{ "refUpdates": [ { "name": "refs/heads/{DefineNewBranchName}", "oldObjectId": "{oldObjectId}" } ], "commits": [ { "comment": "Initial commit.", "changes": [ { "changeType": "add", "item": { "path": "/readme.md" }, "newContent": { "content": "My first file,": "contentType" "rawtext" } } ] } ] }
Next, you could link the work item with the existing Branch by using the Rest API: Work Items - Update .接下来,您可以使用 Rest API: Work Items - Update将工作项与现有分支链接。
PATCH https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?api-version=5.1
Request Body:请求正文:
[ { "op": "add", "path": "/relations/-", "value": { "rel": "ArtifactLink", "url": "vstfs:///Git/Ref/{ProjectID}/{RepoId}/GB{BranchName}", "attributes": { "name": "Branch", "comment": "test link branch" } } } ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.