gpt4 book ai didi

Azure DevOps如何获取任务中的安全变量值

转载 作者:行者123 更新时间:2023-12-02 06:18:04 26 4
gpt4 key购买 nike

我在管道变量页面上将连接字符串声明为安全,但在管道中我无法获取该值。我已经阅读了文档中的相关页面,但当我想在任务中使用值时,它没有提供示例。 https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#secret-variables

The task where I want to get the value you can see below
- task: AzureWebAppContainer@1
displayName: Deploy to App Service
inputs:
azureSubscription: 'free_subscription(id)'
appName: 'app-service'
containers: 'containerregistry.azurecr.io/something:$(tag)'
**WANT TO USE IT HERE**
appSettings: 'CONNECTION_STRING=$(CONNECTION_STRING)'

$(CONNECTION_STRING) 返回空字符串

编辑

更新了代码,但它无论如何都不起作用...应用设置中的连接字符串仍然为空。

- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: ubuntu-latest
steps:
- bash: echo "##vso[task.setvariable variable=CONNECTION_STRING]$CONNECTION_STRING"
displayName: 'Set variable'
- task: AzureWebAppContainer@1
displayName: Deploy to App Service
inputs:
azureSubscription: 'free_subscription(id)'
appName: 'app-service'
containers: 'appnamecontainerregistry.azurecr.io/repository:$(tag)'
appSettings: |
[
{
"name": "CONNECTION_STRING",
"value": "$(CONNECTION_STRING)",
"slotSetting": false
}
]

最佳答案

在选择 secret 管道变量时,您忽略了这一点: enter image description here

这是referenced here因此,根据您的操作系统是 Linux 还是 Windows,它会是:Linux:$CONNECTION_STRINGWindows:%CONNECTION_STRING%

关于Azure DevOps如何获取任务中的安全变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63907177/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com