失败后自动重新部署 [英] Automatic redeploy after fail

查看:53
本文介绍了失败后自动重新部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VSTS在每次提交到特定分支后自动释放我的应用程序.这些任务基本上是:

I'm using VSTS to automatically release my app after each commit to the specific branch. The tasks are basically:

  1. 重新创建数据库
  2. 如果一切正常->部署API和Web
  3. 如果第二次正常->部署并重新启动一些Windows服务

在第二步期间,有时会由于某些连接或IIS问题而导致部署失败.这不是真的我不想在这里对错误的性质非常具体.发生这种情况时,我要做的就是去 VSTS 并在失败的任务上单击 Redeploy .

During the second step sometimes it happens that deploy fails because of some connection or IIS issue. This is not really a big deal I do not want to be very specific about the error nature here. All I have to do when it happens is to go to the VSTS and click Redeploy on failed task.

但是我想知道是否有一种方法可以使该过程自动化.因此,在部署失败和特定错误的情况下,我想触发重新部署自动.有没有办法在VSTS中做到这一点?有什么想法可以实现吗?

But I was wondering if there is a way to automate that process. So in case of fail deployment and specific error I want to trigger Redeploy automatically. Is there a way to do this in VSTS? Any ideas how can I achieve this?

推荐答案

有两个选项可以帮助您重新部署第二个任务/环境.

There have two options which can helps you redeploy the second task/environment.

如果要重新部署三次,则可以在第二个环境中添加与第二个任务相同的三个任务.对于您添加的三个任务,只需将前一个任务失败设置为运行此任务选项.因此它可以重新部署第二个任务/环境,但不超过三倍.

If you want to reploy three times, you can add the same three tasks as the second task in second environment. For the three tasks you add, set only when a previous task has failed for Run this task option. So it can redeploy the second task/environment not bigger than three times.

在PowerShell任务中,您应该执行以下操作.

In the PowerShell task, you should do below operations.

1.通过其余API :

1.Get the current release log by rest API:

GET https://account.vsrm.visualstudio.com/Git2/_apis/Release/releases/{releaseID}

对于releaseID,您可以通过预定义变量 $(Release.ReleaseId)来获取值.

For the releaseID, you can get the value by predefined variable $(Release.ReleaseId).

2.获取第二个任务状态

在其余的API响应中,您可以通过搜索任务显示名称并获取任务的状态来检查第二项任务.如下例所示,任务显示名称为 PowerShell脚本,并且任务失败( status 值为 failed ).

In the rest API response, you can check your second task by searching the task display name and get the status for the task. As below example, the task display name is PowerShell Script, and the task is failed (status value is 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.如果第二个任务失败,则通过

3.If the second task is failed, then deploy the second environment again by rest API:

PATCH https://account.vsrm.visualstudio.com/{project}/_apis/Release/releases/{releaseID}/environments/{environmentID}?api-version=4.0-preview.4

对于environmentID,您还可以通过预定义的变量 $(Release.EnvironmentId)进入.

For the environmentID, you can also get in by perdefined variable $(Release.EnvironmentId).

这篇关于失败后自动重新部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆