Is there a way of extract output of bash script in Azure Pipeline

穿精又带淫゛_ 提交于 2020-06-29 04:20:16

问题


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.


回答1:


Depends on how you design your pipeline you can use Azure Pipeline variables:

  1. 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

# ...
  1. 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.



来源:https://stackoverflow.com/questions/60300578/is-there-a-way-of-extract-output-of-bash-script-in-azure-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!