出乎意料的令牌:“ Condeco”在表达或语句中

发布于 2025-01-24 14:21:02 字数 1691 浏览 0 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈情不如逗狗 2025-01-31 14:21:02

我们尝试了与您使用的相同命令,并获得无效的cmdlt错误,如下所示。

,正如 @ remko 所建议的那样,我们尝试使用相同但没有遇到任何错误。

而不是使用写入主持人”获取变量:“ $(storeAppsetting)尝试使用此信息: - write-host”获取变量:$($ storeaeappsetting) “

输出详细信息: -

​: -

We have tried the same command as you are using and getting the invalid cmdlt error as shown below.

enter image description here

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:-

enter image description here

For more information please refer the below links:-

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文