问题描述
我有很多带有各种变量的bash脚本,这些脚本通过管道传递到各种脚本中.
我一直在想是否可以提取由Azure Pipeline激活的bash脚本的输出,使其成为其余Pipeline运行时的管道变量?
示例: foo = $(date +%Y%m%d_%H%M%S)
输出:20200219_143400,我想获取输出以供以后在管道上使用.
取决于您如何设计管道,可以使用 Azure管道变量:
- 在同一工作内:
-作业:Job1脚步:-重击:|$ WORKDIR/foo.sh回声"## vso [task.setvariable variable = foo] $ foo"名称:FooStep-重击:|$ WORKDIR/nextscript.sh $(FooStep.foo)名称:NextScript#...
- 不同的工作:
-作业:Job1脚步:-重击:|$ WORKDIR/foo.shecho"## vso [task.setvariable variable = foo; isOutput = true] $ foo"名称:FooStep-工作:Job2DependOn:Job1脚步:-重击:|$ WORKDIR/job2script.sh $ [依靠.Job1.outputs['FooStep.foo']]名称:Job2ScriptStep#...
因此,您需要使用 ## vso [task.setvariable]
打印到管道控制台",所有需要保存到输出的变量,然后将它们作为脚本参数值传递./p>
I have plenty of bash scripts with various variables that being piped into various scripts.
I've been wondering if I can extract an output of bash script that is activated by Azure Pipeline to be a pipeline variable for the rest of the Pipeline runtime?
Example:foo=$(date + %Y%m%d_%H%M%S)
output: 20200219_143400, I'd like to get the output for later use on the pipeline.
Depends on how you design your pipeline you can use Azure Pipeline variables:
- Inside the same Job:
- job: Job1
steps:
- bash: |
$WORKDIR/foo.sh
echo "##vso[task.setvariable variable=foo]$foo"
name: FooStep
- bash: |
$WORKDIR/nextscript.sh $(FooStep.foo)
name: NextScript
# ...
- Different jobs:
- job: Job1
steps:
- bash: |
$WORKDIR/foo.sh
echo "##vso[task.setvariable variable=foo;isOutput=true]$foo"
name: FooStep
- job: Job2
dependsOn: Job1
steps:
- bash: |
$WORKDIR/job2script.sh $[ dependencies.Job1.outputs['FooStep.foo'] ]
name: Job2ScriptStep
# ...
So, you need to "print to pipeline console" with ##vso[task.setvariable]
all variables you need to save to output, and after to pass them as scripts arguments values.
这篇关于有没有一种方法可以在Azure Pipeline中提取bash脚本的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!