如何在部署作业期间为 XML 转换设置环境名称?
How can I set the EnvironmentName for XML transformation during a deployment job?
好的伙计们,给 Azure 多阶段管道 功能一个机会,但运气不佳 xml 使用部署作业进行转换。
更新:这不是在 Azure DevOps
中使用经典 Deploy/Release UI
到目前为止我做了什么:
- 从构建过程中删除转换。尝试构建一次并在所有地方部署
- 通过删除 csproj 中的节点验证了 web.{stage}.config 文件包含在 webdeploy 包中
- 设置名称为 'Development'
的舞台
管道 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 阶段的转换。
我确实让 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\s\API\obj\Debug\Package\PackageTmp\Web.Release.config -> C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\s\API\obj\Debug\Package\PackageTmp\Web.config
在查看部署日志文件时,我确实看到了以下内容
##[debug]Release.EnvironmentName=undefined
如何正确设置阶段名称以便在部署期间应用转换?
请尝试$(System.StageName)
。
How can I set the EnvironmentName for XML transformation during a deployment job?
这是 known issue 已经报告给产品团队的。
作为解决方法,您可以尝试在阶段级别和作业级别设置变量 Release.EnvironmentName
:
- stage: Development
displayName: 'Development'
dependsOn: Build
condition: succeeded('Build') #add check if artifact is available
variables:
Release.EnvironmentName: Development
jobs:
然后,特定于环境的配置转换被触发。
希望对您有所帮助。
好的伙计们,给 Azure 多阶段管道 功能一个机会,但运气不佳 xml 使用部署作业进行转换。
更新:这不是在 Azure DevOps
中使用经典 Deploy/Release UI到目前为止我做了什么:
- 从构建过程中删除转换。尝试构建一次并在所有地方部署
- 通过删除 csproj 中的节点验证了 web.{stage}.config 文件包含在 webdeploy 包中
- 设置名称为 'Development' 的舞台
管道 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 阶段的转换。
我确实让 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\s\API\obj\Debug\Package\PackageTmp\Web.Release.config -> C:\azagent\A2\_work\_temp\temp_web_package_8799433796999105\Content\D_C\a\s\API\obj\Debug\Package\PackageTmp\Web.config
在查看部署日志文件时,我确实看到了以下内容
##[debug]Release.EnvironmentName=undefined
如何正确设置阶段名称以便在部署期间应用转换?
请尝试$(System.StageName)
。
How can I set the EnvironmentName for XML transformation during a deployment job?
这是 known issue 已经报告给产品团队的。
作为解决方法,您可以尝试在阶段级别和作业级别设置变量 Release.EnvironmentName
:
- stage: Development
displayName: 'Development'
dependsOn: Build
condition: succeeded('Build') #add check if artifact is available
variables:
Release.EnvironmentName: Development
jobs:
然后,特定于环境的配置转换被触发。
希望对您有所帮助。