我通过 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 谁能建议是否可以实现
您的代码中似乎存在一些问题:
:=
语法无效 - 使用=
运算符为变量赋值。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
将其标记为输出变量。请参阅