Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 995
Dor Shamay Avatar asked Oct 22 '25 05:10

Dor Shamay


1 Answers

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
  variables:
    outputFooStepFoo: $[ dependencies.Job1.outputs['FooStep.foo'] ]
  steps:
  - bash: |
      $WORKDIR/job2script.sh $(outputFooStepFoo)
    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.

like image 132
Ivan Ignatiev Avatar answered Oct 23 '25 21:10

Ivan Ignatiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!