Azure devops 有没有办法在Azure DevOps中编写重复任务的脚本?
每次在项目中创建新的GIT存储库时,我们都要执行许多任务,我想知道是否有办法编写脚本(PowerShell或任何其他方法)来完成这些任务。例如,每次创建新回购协议时,我们都会遵循这些步骤Azure devops 有没有办法在Azure DevOps中编写重复任务的脚本?,azure-devops,Azure Devops,每次在项目中创建新的GIT存储库时,我们都要执行许多任务,我想知道是否有办法编写脚本(PowerShell或任何其他方法)来完成这些任务。例如,每次创建新回购协议时,我们都会遵循这些步骤 创建新的GIT回购协议 创建一个生成管道,以便在运行期间进行生成验证 拉取请求 向Master添加分支策略,包括使用上述生成验证生成的步骤 为发布创建生成管道 创建发布管道 有没有办法在Azure DevOps中编写重复任务的脚本 当然可以!正如Daniel在评论中所说,只要使用RESTAPI就可以实现所有这些
- 创建新的GIT回购协议
POST https://dev.azure.com/{org name}/{project name}/_apis/git/import/ImportRepositoryValidations?api-version=5.2-preview.1
请求机构:
{
"gitSource":
{
"url":"${ReposURL}",
"overwrite":false
},
"tfvcSource":null,
"username":"$(username}"/null,
"password":"${pw}"/"${PAT}"/null
}
{
"name":"${ReposName}",
"project":
{
"name":"{project name}",
"id":"{this project id}"
}
}
{
"parameters":
{
"deleteServiceEndpointAfterImportIsDone":true,
"gitSource":
{
"url":"${ReposURL}",
"overwrite":false
},
"tfvcSource":null,
"serviceEndpointId":null
}
}
步骤2:创建新的回购名称
POST https://dev.azure.com/{org name}/{project name}/_apis/git/Repositories?api-version=5.2-preview.1
请求机构:
{
"gitSource":
{
"url":"${ReposURL}",
"overwrite":false
},
"tfvcSource":null,
"username":"$(username}"/null,
"password":"${pw}"/"${PAT}"/null
}
{
"name":"${ReposName}",
"project":
{
"name":"{project name}",
"id":"{this project id}"
}
}
{
"parameters":
{
"deleteServiceEndpointAfterImportIsDone":true,
"gitSource":
{
"url":"${ReposURL}",
"overwrite":false
},
"tfvcSource":null,
"serviceEndpointId":null
}
}
步骤3:导入回购
POST https://dev.azure.com/{org name}/{project name}/_apis/git/repositories/{the new repos name you create just now}/importRequests?api-version=5.2-preview.1
请求机构:
{
"gitSource":
{
"url":"${ReposURL}",
"overwrite":false
},
"tfvcSource":null,
"username":"$(username}"/null,
"password":"${pw}"/"${PAT}"/null
}
{
"name":"${ReposName}",
"project":
{
"name":"{project name}",
"id":"{this project id}"
}
}
{
"parameters":
{
"deleteServiceEndpointAfterImportIsDone":true,
"gitSource":
{
"url":"${ReposURL}",
"overwrite":false
},
"tfvcSource":null,
"serviceEndpointId":null
}
}
在这些脚本中,您可以在Variable选项卡中设置变量,然后使用${}
在脚本中获取它们
- 在拉取请求期间为生成验证创建生成管道
向Master添加分支策略,包括使用上述生成验证生成的步骤 此API仍将记录在文档中:。只需参考它,并确保使用正确的
策略类型
和相应的构建定义ID
- 为发布创建生成管道
创建发布管道 请参阅此文档: 注意:对于一些将被多次使用的参数,您可以将其设置为变量。对于需要从上一个API响应中获取的参数,您可以定义一个变量来获取其值,然后将此变量传递到下一个API中使用。例如:
$resultT= $result.Headers.ETag
Write-Host "##vso[task.setvariable variable=etag;]$resultT"
现在,您可以在下一个API中直接使用
$(etag)
。是。看看RESTAPI文档。嗨,现在情况如何?下面的答案对你有帮助吗?如果是,您可以接受,这样其他SO用户将能够看到解决方案是否有效。如果您仍然面临一些问题,请留下评论,以便我们仍然可以帮助您。