有没有办法在使用Azure DevOps发布流程中的WinRM - IIS Web App Deployment任务部署应用程序到本地IIS服务器时更新web.config文件。
以下是问题陈述:
- 我有一个Asp.net应用程序存在源代码管理(AzureDevops Repositories)中
我想更新Web.config文件以进行数据库连接、外部第三方URL等操作
我想使用
WinRM - IIS Web App Deployment
任务执行相同的操作
我知道理论上可以使用AzureDevops Marketplace中的其他任务,如Update Config
任务来完成此操作。
首先,我想检查这是否可行
我们是否可以使用WinRM - IIS Web App Deployment
任务中提供的Web Deploy Parameter File
和Override Parameters
选项来实现它。
任务日志如下:
2019-07-24T14:08:09.5094037Z ##[debug]PowerShellHandler.Execute - AddParameter(WebDeployParamFile=E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml)
2019-07-24T14:08:09.5098039Z ##[debug]PowerShellHandler.Execute - AddParameter(OverRideParams=name="SampleWebAppDb-Web.config Connection String",value="new connectionstring"
2019-07-24T14:08:09.5100161Z name="TargetValueChange",value="Value is Changed")
2019-07-24T14:08:09.7289513Z ##[debug]Loading module from path 'E:\NewAgent\_work\_tasks\IISWebAppDeploy_50acc50f-7d15-470b-83c1-578b3f3eeba2\1.4.6\DeploymentSDK\InvokeRemoteDeployment.ps1'.
2019-07-24T14:08:09.7352020Z ##[debug]Dot-sourcing the script file 'E:\NewAgent\_work\_tasks\IISWebAppDeploy_50acc50f-7d15-470b-83c1-578b3f3eeba2\1.4.6\DeploymentSDK\InvokeRemoteDeployment.ps1'.
2019-07-24T14:08:09.7560871Z ##[debug]Entering script DeployIISWebApp.ps1
2019-07-24T14:08:09.7695237Z ##[debug]machinesList = localhost
2019-07-24T14:08:09.7696254Z ##[debug]adminUserName = desktop-0dnhide\hp
2019-07-24T14:08:09.7698716Z ##[debug]winrmProtocol = Http
2019-07-24T14:08:09.7699874Z ##[debug]testCertificate = true
2019-07-24T14:08:09.7702175Z ##[debug]webDeployPackage = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip
2019-07-24T14:08:09.7702410Z ##[debug]webDeployParamFile = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml
2019-07-24T14:08:09.7703755Z ##[debug]overRideParams = name="SampleWebAppDb-Web.config Connection String",value="new connectionstring"
2019-07-24T14:08:09.7703971Z name="TargetValueChange",value="Value is Changed"
2019-07-24T14:08:09.7705526Z ##[debug]websiteName = MainApp/APP1
2019-07-24T14:08:09.7706521Z ##[debug]removeAdditionalFiles = false
2019-07-24T14:08:09.7708165Z ##[debug]excludeFilesFromAppData = false
2019-07-24T14:08:09.7708778Z ##[debug]takeAppOffline = false
2019-07-24T14:08:09.7710018Z ##[debug]additionalArguments =
2019-07-24T14:08:09.7710541Z ##[debug]deployInParallel = true
2019-07-24T14:08:09.7761001Z ##[debug]Triming inputs for excess spaces, double quotes
2019-07-24T14:08:09.8269846Z ##[debug]Executing main function in MsDeployOnTargetMachines : Execute-Main -WebDeployPackage "E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip" -WebDeployParamFile "E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml" -OverRideParams "name=`"SampleWebAppDb-Web.config Connection String`",value=`"new connectionstring`"
2019-07-24T14:08:09.8270269Z name=`"TargetValueChange`",value=`"Value is Changed`"" -WebsiteName "MainApp/APP1" -RemoveAdditionalFiles false -ExcludeFilesFromAppData false -TakeAppOffline false -AdditionalArguments ""
2019-07-24T14:08:09.8566125Z Starting deployment of IIS Web Deploy Package : E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip
2019-07-24T14:08:09.8566522Z
2019-07-24T14:08:09.8566618Z
2019-07-24T14:08:09.8721777Z ##[debug]Entered Invoke-RemoteDeployment function
2019-07-24T14:08:09.8722346Z ##[debug]machinesList = localhost
2019-07-24T14:08:09.8723967Z ##[debug]adminUserName = desktop-0dnhide\hp
2019-07-24T14:08:09.8725568Z ##[debug]protocol = Http
2019-07-24T14:08:09.8769871Z ##[debug]Creating credentials object for connecting to remote host
2019-07-24T14:08:09.8918408Z ##[debug]Tokenizing machine name and port, to create dictonary
2019-07-24T14:08:09.9235805Z ##[debug]Splitting machine name and port into tokens
2019-07-24T14:08:10.0182997Z ##[debug]Using skipCA = True
2019-07-24T14:08:10.0194123Z ##[debug]Using useHttp = True
2019-07-24T14:08:10.0216648Z Performing deployment in parallel on all the machines.
2019-07-24T14:08:10.0217058Z
2019-07-24T14:08:10.0217233Z
2019-07-24T14:08:10.0309977Z Deployment started for machine: localhost with port 5985.
2019-07-24T14:08:10.0316467Z
2019-07-24T14:08:10.0317179Z
2019-07-24T14:08:10.2247380Z ##[debug]Exporting function 'New-PSWorkflowSession'.
2019-07-24T14:08:10.2250179Z ##[debug]Exporting alias 'nwsn'.
2019-07-24T14:08:30.8101839Z ##[debug]Processed: ##vso[task.setprogress value=-1;]
2019-07-24T14:08:30.8185994Z Deployment status for machine localhost : Passed
2019-07-24T14:08:30.8186905Z
2019-07-24T14:08:30.8187252Z
2019-07-24T14:08:30.8221717Z
2019-07-24T14:08:30.8223208Z Deployment started on target machine...
2019-07-24T14:08:30.8223964Z
2019-07-24T14:08:30.8225201Z Entering script MsDeployOnTargetMachines.ps1
2019-07-24T14:08:30.8226227Z
2019-07-24T14:08:30.8226516Z Entering Execute-Main function
2019-07-24T14:08:30.8226760Z
2019-07-24T14:08:30.8226994Z WebDeployPackage = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip
2019-07-24T14:08:30.8227565Z
2019-07-24T14:08:30.8228092Z WebDeployParamFile = E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml
2019-07-24T14:08:30.8228215Z
2019-07-24T14:08:30.8228421Z OverRideParams = name="SampleWebAppDb-Web.config Connection String",value="new connectionstring"
2019-07-24T14:08:30.8228607Z name="TargetValueChange",value="Value is Changed"
2019-07-24T14:08:30.8232239Z
2019-07-24T14:08:30.8232354Z ##[command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msDeploy.exe" -verb:getParameters -source:package='E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip'
2019-07-24T14:08:30.8233350Z
2019-07-24T14:08:30.8233526Z MsDeploy command line arguments: -verb:sync -source:package="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip" -dest:auto -setParamFile="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml" -setParam:name="SampleWebAppDb-Web.config Connection String",value="new connectionstring" -setParam:name="TargetValueChange",value="Value is Changed" -setParam:name="IIS Web Application Name",value="MainApp/APP1" -enableRule:DoNotDeleteRule -retryAttempts:3 -retryInterval:3000
2019-07-24T14:08:30.8233600Z
2019-07-24T14:08:30.8233781Z Deploying website. Running command: "C:\Program Files\IIS\Microsoft Web Deploy V3\msDeploy.exe" -verb:sync -source:package="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.zip" -dest:auto -setParamFile="E:\NewAgent\_work\r2\a/POC-ASP.NET-CI Build/drop/SampleWebApp.SetParameters.xml" -setParam:name="SampleWebAppDb-Web.config Connection String",value="new connectionstring" -setParam:name="TargetValueChange",value="Value is Changed" -setParam:name="IIS Web Application Name",value="MainApp/APP1" -enableRule:DoNotDeleteRule -retryAttempts:3 -retryInterval:3000
name="TargetValueChange",value="xxx"
吗?另外,你可以指定默认值<parameter name="email" description="description" defaultValue="default value">
。 - starian chen-MSFTSampleWebAppDb
的值,但不能更改TargetValueChange
的值。在Web.config文件中,它使用<appSettings> <add key="TargetValueChange" value="NotChanged" /> </appSettings>
进行配置,而SampleWebAppDb是使用<connectionStrings> <add name ="SampleWebAppDb" connectionString ="SomeConection"/> </connectionStrings>
进行配置的。一个按名称配置,另一个按键配置,这会导致问题吗? - E_FreeLancer<?xml version="1.0" encoding="utf-8" ?> <parameters> <parameter name="TargetValueChange" description="description" value="default-value" defaultValue="default-value"> <parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='TargetValueChange']/@value" /> </parameter> </parameters>
- starian chen-MSFT