有两个选项可以帮助您重新部署第二个任务/环境。
选项1:添加与第二个任务相同的任务,并在上一个任务失败时执行以下任务
如果要重新部署三次,可以在第二个环境中添加与第二个任务相同的三个任务。对于您添加的三个任务,仅设置 w当之前的任务失败时 for 运行这个任务选项。因此它可以重新部署第二个任务/环境不超过三倍。
选项 2:在第二个环境中的第二个任务之后添加 PowerShell 任务,如果第二个任务失败,则重新部署第二个环境
在PowerShell任务中,您应该执行以下操作。
1.获取当前发布日志rest API https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases#get-a-release:
GET https://account.vsrm.visualstudio.com/Git2/_apis/Release/releases/{releaseID}
对于releaseID,可以通过预定义变量获取值$(Release.ReleaseId)
.
2.获取第二个任务状态
在其余 API 响应中,您可以通过搜索任务来检查您的第二个任务显示名称并得到status
为了任务。如下例,任务显示名称为PowerShell Script
,任务失败(status
值为failed
).
{
"id": 5,
"timelineRecordId": "ae95a8be-6259-466d-ba8d-93711a922237",
"name": "PowerShell Script",
"dateStarted": "2017-10-03T02:43:25.757Z",
"dateEnded": "2017-10-03T02:43:29.073Z",
"startTime": "2017-10-03T02:43:25.757Z",
"finishTime": "2017-10-03T02:43:29.073Z",
"status": "failed",
"rank": 4,
"issues": [
{
"issueType": "Error",
"message": "agit : The term 'agit' is not recognized as the name of a cmdlet, function, script file, or operable program. Check \r\nthe spelling of the name, or if a path was included, verify that the path is correct and try again.\r\nAt D:\\a\\_temp\\0a858f5c-894b-4944-bed4-54b3cbed48bc.ps1:1 char:1\r\n+ agit\r\n+ ~~~~\r\n + CategoryInfo : ObjectNotFound: (agit:String) [], CommandNotFoundException\r\n + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n"
},
{
"issueType": "Error",
"message": "Process completed with exit code 0 and had 1 error(s) written to the error stream."
}
],
"task": {
"id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1",
"name": "PowerShell",
"version": "1.2.3"
},
"agentName": "Hosted Agent",
"logUrl": "https://account.vsrm.visualstudio.com/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/Release/releases/300/environments/374/tasks/5/logs?releaseDeployPhaseId=344"
}
3.如果第二个任务失败,则通过以下方式重新部署第二个环境rest API https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases#update-release-environment:
PATCH https://account.vsrm.visualstudio.com/{project}/_apis/Release/releases/{releaseID}/environments/{environmentID}?api-version=4.0-preview.4
对于环境IF,也可以通过预定义变量进入$(Release.EnvironmentId)
.