在部署作业期间,如何设置用于XML转换的EnvironmentName? [英] How can I set the EnvironmentName for XML transformation during a deployment job?

查看:81
本文介绍了在部署作业期间,如何设置用于XML转换的EnvironmentName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,给Azure提供了多阶段管道功能,并且没有太多运气可以通过部署工作来完成xml转换.

Alright folks, giving Azure multi-stage-pipelines feature a go and not having much luck getting xml transformations using a deployment job to work.

更新:这未在Azure DevOps中使用经典的Deploy/Release UI

Update: This is not using the Classic Deploy/Release UI in Azure DevOps

到目前为止我所做的:

  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

我尝试了阶段名称,显示名称,部署名称等的变体,但仍无法启动 Development 阶段的转换.

I've tried variations of the stage name, displayname, deployment name, etc still can't get the transformation for the Development stage to fire.

我确实可以正常使用web.config和web.release.config.

I do get the web.config and web.release.config to work but that is it.

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

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

When reviewing the log file for deployment I do see the following

##[debug]Release.EnvironmentName=undefined

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

How can I set the stage name properly in order for the transformations to be applied during deployment??

推荐答案

如何在部署作业期间为XML转换设置EnvironmentName?

How can I set the EnvironmentName for XML transformation during a deployment job?

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

This is known issue that has already been reported to product team.

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

As workaround, you could try to set the variable Release.EnvironmentName on the stage-level and on the job-level:

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

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

Then, the environment-specific config transformation was triggered.

希望这会有所帮助.

这篇关于在部署作业期间,如何设置用于XML转换的EnvironmentName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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