用于 QnA 机器人的 Azure DevOps 管道

Azure DevOps Pipeline for QnA Bot

我正在尝试为这个示例聊天机器人获取构建和发布管道 -> https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/49.qnamaker-all-features

我已经拥有所有基础设施资源。我计划稍后将其自动化。但目前我只需要部署代码。我可以得到一些帮助吗?

Azure 项目有代码签入的 Repo。

构建管道需要是什么样子?

  1. 我想我需要对包进行 npm 安装
  2. 使用 az bot prepare-deploy --code-dir "." 生成 web.config。 --lang Javascript
  3. 生成一个 zip 文件。

发布管道需要是什么样的?

  1. 我想我需要 运行 az webapp deployment source config-zip --resource-group "" --name "" --src ""

这是我的进度:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js 10.x'

- script: |
    npm install
  displayName: 'Install all modules'

感谢任何帮助!

提前致谢, 杰克.

更新:这是我的最终 yaml

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
     npm install
  displayName: 'npm install and build'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.SourcesDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: myTestBot'
  inputs:
    ConnectedServiceName: 'Release-Service-Connection'  
    azureSubscription: 'subscriptionName'
    WebAppName: 'BotName'
    ResourceGroupName: 'rgName'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    WebConfigParameters: '-Handler iisnode -NodeStartFile index.js -appType node' 

不需要使用 az bot 生成 web.config。 Azure 应用服务部署任务可以自动生成 web.config。您可以查看以下示例。

trigger:
- main
pool:
  vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
     npm install
  displayName: 'npm install and build'

  #generate zip package using archivefile task.
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'Build.SourcesDirectory'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
  
  #publish artifacts to azure devops server to be used in Release pipeline.
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

请查看示例 Build, test, and deploy JavaScript and Node.js apps 了解更多信息。

在创建发布管道之前。您需要创建一个 azure Resource Manager service connection to connect your Azure subscription to Azure devops. See 作为示例。

然后您可以在发布管道中创建 release pipeline, Add the artifacts published by above build pipeline as the pipeline Artifacts resource. And add stages. Using Azure App Service deploy 任务。

您可以将 Azure App Service 部署任务配置为 generate web.config. Also see here 以获取更多信息。

您还可以查看 this blog 中的示例。

实际上,您可以直接在构建管道中部署 Azure 应用服务,而无需创建发布管道。

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'samples/javascript_nodejs/49.qnamaker-all-features'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
  
- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: leviwebApp'
  inputs:
    azureSubscription: 'azure Resource Manager service connection'
    WebAppName: leviwebApp
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    WebConfigParameters: '-Handler iisnode -NodeStartFile index.js -appType node'

以上方法使用 build/release 管道和部署任务是部署到 Azure 应用程序服务的一般方法。

但是,您也可以在构建管道中的 azure cli 任务中编写 az cli commnads 以部署到 azure 应用程序服务。请参阅以下示例:

 ....
- script: |
    cd samples/javascript_nodejs/49.qnamaker-all-features
    npm install
    
  displayName: 'npm install and build'

- task: AzureCLI@2
  inputs:
    azureSubscription: 'azure Resource Manager service connection'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: 'az bot prepare-deploy --code-dir "." --lang Javascript'
   
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'Build.SourcesDirectory'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
- task: AzureCLI@2
  inputs:
    azureSubscription: 'azure Resource Manager service connection'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: 'az webapp deployment source config-zip --resource-group "<resource-group-name>" --name "<name-of-web-app>" --src "<project-zip-path>"'