Azure Pipelines : Variable not taking assigned value, 相反解析为 $(variableName)

标签 azure azure-pipelines azure-pipelines-yaml

我正在使用 Azure Pipelines,并遇到使用 ##vso[task.setvariable] 语法设置管道变量的问题。我的目的是根据管道中的环境参数设置变量 kaasServiceConnection 不同的值。但是,当我稍后在管道中引用该变量时,它似乎并未获取指定的值;相反,它似乎解析为 $(kaasServiceConnection)。

这是我的管道中的相关片段:

- script: |
    if [ "$(parameters.environment)" == "dev" ]; then
      echo "##vso[task.setvariable variable=kaasServiceConnection;]SVC-DEV-CONN"
    elif [ "$(parameters.environment)" == "qa" ]; then
      echo "##vso[task.setvariable variable=kaasServiceConnection;]SVC-QA-Conn"
    fi
  displayName: 'getting Service Connection'

- task: HelmDeploy@0
  displayName: 'Helm upgrade'
  inputs:
    connectionType: 'Kubernetes Service Connection'
    kubernetesServiceEndpoint: '$(kaasServiceConnection)'
    ...

最佳答案

我认为这适合您的情况,并且更适合 azure DevOps 管道。

变量部分也接受表达式,请参阅 conditionally-assign-a-variable

parameters:
 - name: environment
   type: string
   values:
    - dev
    - prod
variables:
- ${{ if eq(parameters.environment, 'dev') }}:
    - name: kaasServiceConnection
      value: "SVC-DEV-CONN"
- ${{ if eq(parameters.environment, 'qa') }}:
    - name: kaasServiceConnection
      value: "SVC-QA-CONN"

stages:
  - stage: yourStage
    steps:
      - task: HelmDeploy@0
        displayName: 'Helm upgrade'
        inputs:
          connectionType: 'Kubernetes Service Connection'
          kubernetesServiceEndpoint: $(kaasServiceConnection)

Please adjust the pipeline accordingly.

关于Azure Pipelines : Variable not taking assigned value, 相反解析为 $(variableName),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76917639/

相关文章:

php - 移动地理定位 mysql windows azure

msbuild - 错误 : More than one package matched with specified pattern: D:\a\r1\a\**\*. zip。请限制搜索模式

azure - 有没有办法使用 Azure DevOps 中的资源扩展多个模板?

azure - 为 Azure Function 编译 F# .NET Core 项目

azure - 如何使用应用服务对 Azure 函数应用进行身份验证/授权?

c# - 切换到身份时的 Azure ClaimsIdentity

azure - 配置 Azure Build Pipeline 以运行 .net core 与数据库的自动化集成测试

Azure DevOps - 在 Azure YAML 管道的 React 构建中将文件夹拖放到空

azure-pipelines - Azure Pipelines DownloadPipelineArtifact 未下载项目

azure - SqlAzureDacpacDeployment@1 - Devops 管道中出现错误无法部署包