如何在部署作业期间设置 XML 转换的环境名称?

jdi*_*iaz 3 azure azure-deployment azure-devops

好吧,伙计们,尝试一下 Azure多阶段管道功能,但不太幸运地使用部署作业进行 xml 转换。

更新:这没有使用 Azure DevOps 中的经典部署/发布 UI

到目前为止我所做的:

  1. 从构建过程中删除转换。尝试一次构建并随处部署
  2. 通过删除 csproj 中的节点来验证 web.{stage}.config 文件是否包含在 webdeploy 包中
  3. 设置名为“开发”的舞台

管道yaml

trigger:
  batch: false # If batch set to true, when a pipeline is running, the system waits until the run is completed,
  branches:
    include:
    - staging-devops
  paths:
    include:
    - myProject/*
    - API/*

variables:
  BuildConfiguration: 'Release'
  BuildPlatform: 'Any CPU'
  System.Debug: true

stages:
- stage: Build
  displayName: 'Build project'
  jobs:
  - job:
    displayName: 'Build and package client'
    pool:
      vmImage: 'vs2017-win2016'
      demands:
      - msbuild
      - visualstudio
    steps:
    - task: VSBuild@1
      displayName: 'Visual Studio build'
      inputs:
        solution: 'myProject/myProject.csproj'
        vsVersion: '15.0'
        msbuildArgs: '/p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
        platform: 'AnyCPU'
        configuration: 'Release'
    - task: PublishPipelineArtifact@1
      inputs:
        targetPath: '$(build.artifactstagingdirectory)'
        artifactName: 'myProject-web-client'
  - job:
    displayName: 'Build and package API'
    pool:
      vmImage: 'vs2017-win2016'
      demands:
      - msbuild
      - visualstudio
    steps:
    # add caching of nuget packages
    - task: NuGetToolInstaller@0
      displayName: 'Use NuGet 4.4.1'
      inputs:
        versionSpec: 4.4.1
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: 'API/myAPI.sln'
    - task: VSBuild@1
      displayName: 'Visual Studio build'
      inputs:
        solution: 'API/myAPI.sln'
        vsVersion: '15.0'
        msbuildArgs: '/p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
        platform: '$(BuildPlatform)'
        # configuration: '$(BuildConfiguration)'
    - task: PublishPipelineArtifact@1
      inputs:
        targetPath: '$(build.artifactstagingdirectory)'
        artifactName: 'myProject-api'

- stage: Development
  displayName: 'Development'
  dependsOn: Build
  condition: succeeded('Build') #add check if artifact is available
  jobs:
  - deployment: DeploymyProjectClient
    displayName: 'Deploy web client'
    timeoutInMinutes: 30
    pool:
      vmImage: "windows-latest"
    environment:
      name:  Staging
      resourceType: VirtualMachine
      tags: web
    strategy:
      runOnce:
        deploy:
          steps:
            - task: IISWebAppDeploymentOnMachineGroup@0
              displayName: 'Deploy web application (myProject)'
              inputs:
                webSiteName: myProjectDev
                package: '$(Pipeline.Workspace)/myProject-web-client/**/*.zip'
                removeAdditionalFilesFlag: true
  - deployment: Development
    displayName: 'Development'
    timeoutInMinutes: 30
    pool:
      vmImage: "windows-latest"
    environment:
      name:  Staging
      resourceType: VirtualMachine
      tags: web
    strategy:
      runOnce:
        deploy:
          steps:
          - task: IISWebAppDeploymentOnMachineGroup@0
            displayName: Development
            inputs:
              webSiteName: 'WebAPI-Test'
              package: '$(Pipeline.Workspace)/myProject-api/**/*.zip'
              xmlTransformation: true
Run Code Online (Sandbox Code Playgroud)

我已经尝试了阶段名称、显示名称、部署名称等的变体,但仍然无法启动开发阶段的转换。

我确实让 web.config 和 web.release.config 可以工作,但仅此而已。

2020-05-02T05:26:04.9272125Z ##[debug]adjustedPattern: 'C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\**/*.config'
2020-05-02T05:26:04.9343033Z ##[debug]9 matches
2020-05-02T05:26:04.9345300Z ##[debug]9 final results
2020-05-02T05:26:04.9351908Z ##[debug]Applying XDT Transformation : C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\1\s\API\obj\Debug\Package\PackageTmp\Web.Release.config -> C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\1\s\API\obj\Debug\Package\PackageTmp\Web.config

Run Code Online (Sandbox Code Playgroud)

在查看部署日志文件时,我确实看到以下内容

##[debug]Release.EnvironmentName=undefined
Run Code Online (Sandbox Code Playgroud)

如何正确设置阶段名称以便在部署期间应用转换?

Leo*_*SFT 7

如何在部署作业期间设置 XML 转换的环境名称?

这是已知问题,已报告给产品团队。

Release.EnvironmentName作为解决方法,您可以尝试在阶段级别和作业级别设置变量:

- stage: Development
  displayName: 'Development'
  dependsOn: Build
  condition: succeeded('Build') #add check if artifact is available
  variables:
    Release.EnvironmentName: Development
  jobs:
Run Code Online (Sandbox Code Playgroud)

然后,触发特定于环境的配置转换。

希望这可以帮助。