我正在使用VSTS在每次提交到特定分支后自动释放我的应用。任务基本上是:
在第二步中,有时由于某些连接或IIS问题导致部署失败。这不是真的
一个大问题我不想在这里对错误性质做出非常具体的说明。我发生的所有事情就是转到VSTS
并在失败的任务上点击Redeploy
。
但我想知道是否有办法让这个过程自动化。因此,在部署失败和特定错误的情况下,我想触发
自动Redeploy
。有没有办法在VSTS中做到这一点?任何想法我怎样才能做到这一点?
答案 0 :(得分:2)
有两个选项可以帮助您重新部署第二个任务/环境。
如果要重新组合三次,则可以在第二个环境中添加与第二个任务相同的三个任务。对于您添加的三个任务,仅为运行此任务选项设置w 上一个任务失败。因此,它可以重新部署不超过三次的第二个任务/环境。
在PowerShell任务中,您应该执行以下操作。
1.获取当前版本日志rest API:
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部署第二个环境:
PATCH https://account.vsrm.visualstudio.com/{project}/_apis/Release/releases/{releaseID}/environments/{environmentID}?api-version=4.0-preview.4
对于environmentID,您还可以通过perdefined变量$(Release.EnvironmentId)
进入。