出乎意料的令牌:“ Condeco”在表达或语句中
我有一个DevOps释放管道。当我更新我的应用服务时,它会自动删除用户之前添加的任何应用程序配置。因此,我想获取所有应用程序设置并将它们存储到变量中,然后在应用程序Service更新再次将它们添加回应用程序设置之后。
将应用程序设置存储到变量
$webApp = Get-AzureRMWebApp -ResourceGroupName $(Parameter.ResourceGroupName) -Name $(Parameters.AppName)
$appSetting = $webApp.SiteConfig.AppSettings
$hash = @{}
foreach($kvp in $appSetting) {
$hash[$kvp.Name] = $kvp.Value
}
Write-Host ($hash | Out-String)
$jsonObject = [PSCustomObject]$hash
$convertJson = $jsonObject | ConvertTo-JSON -Depth 100 -Compress
Write-Host "JSON : " $convertJson
Write-Host "##vso[task.setvariable variable=storeAppSetting;]$convertJson"
打印JSON值
{"issuer":"Condeco","EnterpriseRedisAccess":"true","RedisConnectionString":"Redis","d":"d","APIBaseURL":"https://abc.azurewebsites.net","secret":"XXXXX=","NotificationPusher":"https://abc.xyz.com/NotificationPusher","audience":"XXXXX","SwaggerTitle":"Condeco","EnterpriseURL":"https://abc.xyz.com/"}
现在我想使用该变量再次设置应用程序设置
Write-Host "Get Variable : " $(storeAppSetting)
错误
2022-04-26T09:03:29.7642657Z ##[error]At D:\a\_temp\302fc4cc-24ff-4ad1-b04e-f4b1331dc00f.ps1:2 char:35
+ Write-Host "Get Json : " {"issuer":"Condeco","EnterpriseRedisAccess": ...
+ ~~~~~~~~~~
Unexpected token ':"Condeco"' in expression or statement.
At D:\a\_temp\302fc4cc-24ff-4ad1-b04e-f4b1331dc00f.ps1:2 char:45
+ Write-Host "Get Json : " {"issuer":"Condeco","EnterpriseRedisAccess": ...
+ ~
Missing argument in parameter list.
I have one DevOps release pipeline. When I update my app service it automatically deletes any app configuration added previously by the user. So I want to get all the app settings and store them into variable then after the app service update again add them back to the app setting.
To store app setting into variable
$webApp = Get-AzureRMWebApp -ResourceGroupName $(Parameter.ResourceGroupName) -Name $(Parameters.AppName)
$appSetting = $webApp.SiteConfig.AppSettings
$hash = @{}
foreach($kvp in $appSetting) {
$hash[$kvp.Name] = $kvp.Value
}
Write-Host ($hash | Out-String)
$jsonObject = [PSCustomObject]$hash
$convertJson = $jsonObject | ConvertTo-JSON -Depth 100 -Compress
Write-Host "JSON : " $convertJson
Write-Host "##vso[task.setvariable variable=storeAppSetting;]$convertJson"
Print JSON value
{"issuer":"Condeco","EnterpriseRedisAccess":"true","RedisConnectionString":"Redis","d":"d","APIBaseURL":"https://abc.azurewebsites.net","secret":"XXXXX=","NotificationPusher":"https://abc.xyz.com/NotificationPusher","audience":"XXXXX","SwaggerTitle":"Condeco","EnterpriseURL":"https://abc.xyz.com/"}
Now I want to use that variable to set the app setting again
Write-Host "Get Variable : " $(storeAppSetting)
Error
2022-04-26T09:03:29.7642657Z ##[error]At D:\a\_temp\302fc4cc-24ff-4ad1-b04e-f4b1331dc00f.ps1:2 char:35
+ Write-Host "Get Json : " {"issuer":"Condeco","EnterpriseRedisAccess": ...
+ ~~~~~~~~~~
Unexpected token ':"Condeco"' in expression or statement.
At D:\a\_temp\302fc4cc-24ff-4ad1-b04e-f4b1331dc00f.ps1:2 char:45
+ Write-Host "Get Json : " {"issuer":"Condeco","EnterpriseRedisAccess": ...
+ ~
Missing argument in parameter list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们尝试了与您使用的相同命令,并获得无效的
cmdlt
错误,如下所示。,正如 @ remko 所建议的那样,我们尝试使用相同但没有遇到任何错误。
“ 而不是使用
写入主持人”获取变量:“ $(storeAppsetting)
尝试使用此信息: -write-host”获取变量:$($ storeaeappsetting) “
”输出详细信息: -
: -
dc | azure应用程序设置任务在Azure Pipeline中抛出无效的JSON错误,当时使用PowerShell
博客|使用PowerShell使用PowerShell < < /em>
We have tried the same command as you are using and getting the invalid
cmdlt
error as shown below.And as suggested by @Remko, We have tried to use the same and not getting any errors.
"Instead of using
Write-Host "Get Variable : " $(storeAppSetting)
try to use this:-Write-Host "Get Variable : $($storeAppSetting)"
"OUTPUT DETAILS FOR REFERENCE:-
For more information please refer the below links:-
DC|Azure app settings task in Azure pipeline throws invalid JSON error when supplying with variable with powershell
BLOG|Update application settings for Azure App Service using PowerShell