简体   繁体   English

使用 azure cli 任务更新 web 配置文件

[英]updating web config file using azure cli task

I am trying to update my web config file using the azure powershell task in azure build pipeline.我正在尝试使用 azure powershell 任务在 ZCF04A02E37B774C5971C 管道中更新我的 web 配置文件。 the following is the script i use.以下是我使用的脚本。

$storageConectionString="DefaultEndpointsProtocol=https;AccountName="+$storageAccountName+";AccountKey="+$value+";EndpointSuffix=core.windows.net" 
$sqlConnectionString ="server=tcp:"+$sqlServerName+";database="+$databasename+";UID=AnyString;Authentication=Active Directory Interactive" 

#file path in azure repo
$configFilePath = "$visualStudioFolder/NRMAPP//NRMAPP/NRMAPP/Web.config"

$myXML = [Xml] (Get-Content $configFilePath)

$sqlConnectionObj = $myXML.configuration.connectionStrings.add
$sqlConnectionObj.connectionString = $sqlConnectionString

write-output $sqlConnectionObj



$storageConnectionObj = $myXML.configuration.appSettings.add | where {$_.Key -eq "StorageConnectionString" }
$storageConnectionObj.value = $storageConectionString

write-output $storageConnectionObj

$myXML.Save($configFilePath)

The build pipeline runs successfully but not making the changes to the config file in azure repo.构建管道成功运行,但未对 azure 存储库中的配置文件进行更改。 Any help is appreciated thanks in advance.提前感谢任何帮助。

  • The build pipeline runs successfully but not making the changes to the config file in azure repo.构建管道成功运行,但未对 azure 存储库中的配置文件进行更改。

The code changes made in the pipeline cannot be reflected in the azure repo.管道中所做的代码更改无法反映在 azure 存储库中。 Because the pipelines always clone your repo to the local default working folder on the agent machine.因为管道总是将您的存储库克隆到代理机器上的本地默认工作文件夹。 And all the changes are done with the local files cloned from your azure repo on the agent machine.并且所有更改都是使用从代理机器上的 azure 存储库克隆的本地文件完成的。

If you want to push the changes to your azure repo.如果您想将更改推送到 azure 存储库。 You may have to use another scrip task to run the git commands.您可能必须使用另一个脚本任务来运行 git 命令。 Please check out below scripts:请查看以下脚本:

- powershell: | 
        git config --global user.email "your@email.com"
        git config --global user.name "yourUsername"

        #git add filename.ext
        git add .
        git commit -m "message" 

        git push https://$(System.AccessToken)@dev.azure.com/yourOrg/yourProj/_git/repoName HEAD:master -q
  • There are also extension tasks available in the marketplace that you can use directly to update your web config.市场上还有可用的扩展任务,您可以直接使用它们来更新您的 web 配置。 For example Magic Chunks task .例如Magic Chunks 任务 You can check out the example in this thread .您可以查看此线程中的示例。

There's no need to write this yourself.这个没必要自己写。 The app service deployment task supports deployment-time XML configuration transform via parameters.xml to define transforms and setparameters.xml to define values. 应用服务部署任务通过parameters.xml支持部署时 XML 配置转换。xml 定义转换和设置参数setparameters.xml定义值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Azure Web角色上更新aspnet.config - Updating aspnet.config on Azure Web Role Web配置文件到Azure门户 - Web Config file to Azure Portal 无法使用 Azure Cli az webapp config backup create 备份功能/Web 应用程序 - Unable to backup Function/Web App using Azure Cli az webapp config backup create 在Azure App Service部署任务期间锁定了web.config文件 - web.config file locked during Azure App Service Deploy task 使用 CLI 上传 Azure 中的文件 - Uploading File in Azure using CLI 使用CLI的Azure批处理任务的容器任务设置 - Container task settings for azure batch task Using CLI Azure staticwebapp 不允许在终端中使用 Azure CLI 添加带有“&”值的配置 - Azure staticwebapp not allowing to add config with "&" in value using Azure CLI in terminal 在发布管道中使用 Azure CLI 任务中的秘密变量 - Using secret variable in Azure CLI task in release pipeline 有没有办法使用 azure CLI 获取特定任务 ID 的标签? - is there a way to get tags for a specific task ID using the azure CLI? 使用Azure CLI将gitlab工件部署到Microsoft Azure Web应用程序 - Deploy gitlab artifact to microsoft azure web app using azure cli
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM