azure 管道变量来保存 DBT 核心宏的返回值

问题描述 投票:0回答:1

我通过 yml 文件创建了 azure pipeline(CI),该文件以给定的顺序执行 DBT 核心模型/宏。

我想声明一个变量来保存 DBT MACRO 返回的值

到目前为止我已经尝试过:

 variables:
  dbtMacroOutput: '' 

- script: |
    echo $(Build.Reason)
    pip install --upgrade pip
    pip install dbt-snowflake --user
    dbt run-operation myDbtMacro
    $dbtMacroOutput := $(dbt run-operation myDbtMacro)  # Capture the actual output
    Write-Host "##vso[task.setvariable variable=dbtMacroResult]$dbtMacroOutput"
    echo "The dbt macro result is $(dbtMacroOutput)"
  displayName: Use dbtMacroOutput dbtMacroOutput: ''  # Initialize with an empty string

但是在执行时,我没有收到任何消息:= command not found 谁能建议是否可以实现

azure-devops azure-pipelines dbt
1个回答
0
投票

您的代码中似乎存在一些问题:

  • :=
    语法无效 - 使用
    =
    运算符为变量赋值。
  • 您应该使用
    pwsh
    PowerShell@2
    任务来运行 Powershell 命令,而不是
    script
  • 变量
    dbtMacroOutput
    正在顶部声明,但您试图在任务中设置变量
    dbtMacroResult
  • 您不能在定义管道变量的同一步骤中使用管道变量
示例

下面的示例展示了如何在同一作业中设置和使用

管道变量

为了简单起见,我删除了

dbt

 相关命令 - 您应该很容易将其适应您的场景:

trigger: none pool: vmImage: 'ubuntu-latest' jobs: - job: A displayName: 'Set pipeline variable' steps: - checkout: none - pwsh: | # set other commands here $dbtMacroOutput="value1" # replace with output of dbt command Write-Host "##vso[task.setvariable variable=dbtMacroResult]$dbtMacroOutput" displayName: Set pipeline variable dbtMacroResult name: setVariableStep - pwsh: | Write-Host "The dbt macro result is $(dbtMacroResult)" displayName: Use pipeline variable dbtMacroResult
请注意,如果您想让某个变量可用于将来的作业,则必须使用 

isOutput=true

 将其标记为输出变量。

请参阅

设置多作业输出变量使用任务中的输出变量了解更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.