您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure DevOps 持续部署Continuous Deployment with Azure DevOps

本文介绍如何为自定义命令应用程序设置持续部署。In this article, you learn how to set up continuous deployment for your Custom Commands applications. 将向你提供支持 CI/CD 工作流的脚本。The scripts to support the CI/CD workflow are provided to you.

先决条件Prerequisite

  • 用于开发的自定义命令应用程序 (DEV)A Custom Commands application for development (DEV)
  • 用于生产的自定义命令应用程序 (PROD)A Custom Commands application for production (PROD)
  • 注册 Azure PipelinesSign up for Azure Pipelines

导出/导入/发布Export/Import/Publish

脚本托管在认知服务语音助理 - 自定义命令The scripts are hosted at Cognitive Services Voice Assistant - Custom Commands. 将 bash 目录中的脚本克隆到存储库中。Clone the scripts in the bash directory to your repository. 确保保持同一路径。Make sure you maintain the same path.

设置管道Set up a pipeline

  1. 转到“Azure DevOps - Pipelines”,然后单击“New Pipeline”Go to Azure DevOps - Pipelines and click "New Pipeline"

  2. 在“Connect”部分中,选择这些脚本所在的存储库的位置In Connect section, select the location of your repository where these scripts are located

  3. 在“Select”部分中,选择你的存储库In Select section, select your repository

  4. 在“Configure”部分中,选择“Starter pipeline”In Configure section, select "Starter pipeline"

  5. 接下来,你将获得一个带有 YAML 文件的编辑器,请用此脚本替换“steps”部分。Next you'll get an editor with a YAML file, replace the "steps" section with this script.

    steps:
    - task: Bash@3
      displayName: 'Export source app'
      inputs:
        targetType: filePath
        filePath: ./bash/export.sh
        arguments: '-r westus2 -s $(SubscriptionKey) -c $(Culture) -a $(SourceAppId) -f ExportedDialogModel.json'
        workingDirectory: bash
        failOnStderr: true
    
    - task: Bash@3
      displayName: 'Import to target app'
      inputs:
        targetType: filePath
        filePath: ./bash/import.sh
        arguments: '-r westus2 -s $(SubscriptionKey) -c $(Culture) -a $(TargetAppId) -f ExportedDialogModel.json'
        workingDirectory: bash
        failOnStderr: true
    
    - task: Bash@3
      displayName: 'Train and Publish target app'
      inputs:
        targetType: filePath
        filePath: './bash/train-and-publish.sh'
        arguments: '-r westus2 -s $(SubscriptionKey) -c $(Culture) -a $(TargetAppId)'
        workingDirectory: bash
        failOnStderr: true
    
  6. 请注意,这些脚本假定你使用的是区域 westus2,如果不是这样,请相应地更新任务的参数Note that these scripts assume that you are using the region westus2, if that's not the case update the arguments of the tasks accordingly

    突出显示参数中的区域值的屏幕截图。Screenshot that highlights the region value in the arguments.

  7. 在“Save and run”按钮中,打开下拉菜单,然后单击“Save”In the "Save and run" button, open the dropdown and click "Save"

将管道挂接到应用程序Hook up the pipeline with your application

  1. 导航到管道的主页。Navigate to the main page of the pipeline.

  2. 在右上角下拉列表中,选择“Edit pipeline”。In the top-right corner dropdown, select Edit pipeline. 将显示 YAML 编辑器。It gets you to a YAML editor.

  3. 在“Run”按钮旁的右上角,选择“Variables”。In the top-right corner next to "Run" button, select Variables. 单击“New variable”。Click New variable.

  4. 添加这些变量:Add these variables:

    变量Variable 说明Description
    SourceAppIdSourceAppId 开发应用程序的 IDID of the DEV application
    TargetAppIdTargetAppId PROD 应用程序的 IDID of the PROD application
    SubscriptionKeySubscriptionKey 用于这两个应用程序的订阅密钥Subscription key used for both applications
    环境Culture 应用程序环境(即 en-us)Culture of the applications (i.e. en-us)

    “发送活动”有效负载Send Activity payload

  5. 单击“Run”,然后单击正在运行的“作业”。Click "Run" and then click in the "Job" running.

    应会看到正在运行的任务列表,包括:“Export source app”、“Import to target app”和“Train and Publish target app”You should see a list of tasks running that contains: "Export source app", "Import to target app" & "Train and Publish target app"

从源代码进行部署Deploy from source code

如果要将应用程序的定义保留在存储库中,我们会提供源代码中用于部署的脚本。In case you want to keep the definition of your application in a repository, we provide the scripts for deployments from source code. 由于脚本在 bash 中,因此,如果你使用的是 Windows,则需要安装 Linux 子系统Since the scripts are in bash, If you are using Windows you'll need to install the Linux subsystem.

脚本托管在认知服务语音助理 - 自定义命令The scripts are hosted at Cognitive Services Voice Assistant - Custom Commands. 将 bash 目录中的脚本克隆到存储库中。Clone the scripts in the bash directory to your repository. 确保保持同一路径。Make sure you maintain the same path.

准备存储库Prepare your repository

  1. 为应用程序创建一个目录,本示例将创建一个名为“apps”的目录。Create a directory for your application, in our example create one called "apps".

  2. 更新以下 bash 脚本的参数,并运行。Update the arguments of the bash script below, and run. 它会将应用程序的对话框模型导入文件 myapp.jsonIt will import the dialog model of your application to the file myapp.json

    bash/export.sh -r <region> -s <subscriptionkey> -c en-us -a <appid> -f apps/myapp.json
    
    参数Arguments 说明Description
    regionregion 应用程序的区域,即 westus2。region of the application, i.e. westus2.
    subscriptionkeysubscriptionkey 语音资源的订阅密钥。subscription key of your speech resource.
    appidappid 要导出的自定义命令的应用程序 ID。the Custom Commands' application ID you want to export.
  3. 将这些更改推送到存储库。Push these changes to your repository.

设置管道Set up a pipeline

  1. 转到“Azure DevOps - Pipelines”,然后单击“New Pipeline”Go to Azure DevOps - Pipelines and click "New Pipeline"

  2. 在“Connect”部分中,选择这些脚本所在的存储库的位置In Connect section, select the location of your repository where these scripts are located

  3. 在“Select”部分中,选择你的存储库In Select section, select your repository

  4. 在“Configure”部分中,选择“Starter pipeline”In Configure section, select "Starter pipeline"

  5. 接下来,你将获得一个带有 YAML 文件的编辑器,请用此脚本替换“steps”部分。Next you'll get an editor with a YAML file, replace the "steps" section with this script.

    steps:
    - task: Bash@3
      displayName: 'Import app'
      inputs:
        targetType: filePath
        filePath: ./bash/import.sh
        arguments: '-r westus2 -s $(SubscriptionKey) -c $(Culture) -a $(TargetAppId) -f ../apps/myapp.json'
        workingDirectory: bash
        failOnStderr: true
    
    - task: Bash@3
      displayName: 'Train and Publish app'
      inputs:
        targetType: filePath
        filePath: './bash/train-and-publish.sh'
        arguments: '-r westus2 -s $(SubscriptionKey) -c $(Culture) -a $(TargetAppId)'
        workingDirectory: bash
        failOnStderr: true
    

    备注

    这些脚本假定你使用的是区域 westus2,如果不是这样,请相应地更新任务的参数these scripts assume that you are using the region westus2, if that's not the case update the arguments of the tasks accordingly

  6. 在“Save and run”按钮中,打开下拉菜单,然后单击“Save”In the "Save and run" button, open the dropdown and click "Save"

将管道挂接到目标应用程序Hook up the pipeline with your target applications

  1. 导航到管道的主页。Navigate to the main page of the pipeline.

  2. 在右上角下拉列表中,选择“Edit pipeline”。In the top-right corner dropdown, select Edit pipeline. 将显示 YAML 编辑器。It gets you to a YAML editor.

  3. 在“Run”按钮旁的右上角,选择“Variables”。In the top-right corner next to "Run" button, select Variables. 单击“New variable”。Click New variable.

  4. 添加这些变量:Add these variables:

    变量Variable 说明Description
    TargetAppIdTargetAppId PROD 应用程序的 IDID of the PROD application
    SubscriptionKeySubscriptionKey 用于这两个应用程序的订阅密钥Subscription key used for both applications
    环境Culture 应用程序环境(即 en-us)Culture of the applications (i.e. en-us)
  5. 单击“Run”,然后单击正在运行的“作业”。Click "Run" and then click in the "Job" running. 应会看到正在运行的任务列表,包括:“Import app”和“Train and Publish app”You should see a list of tasks running that contains: "Import app" & "Train and Publish app"

后续步骤Next steps