Home > front end >  Set environment variable in unix machine using bash script via YAML steps
Set environment variable in unix machine using bash script via YAML steps

Time:08-03

I need to set the below environment variable to a Unix machine through bash script as an inline script in the YAML file

My env variables are

cache=30
delay=10
url={"https.8shd3dad#d/[email protected]"}

I have tried the below steps in YAML for setting the same, but couldn't see the environment variable and its value at my runtime

  - task: Bash@3
    inputs:
       targetType: 'inline'
       script: export cache=30
               export url={"https.8shd3dad#d/[email protected]"}
               export Delay=10
    env:
       cache : $(30)

Can anyone help me in fixing this issue? since I am new to YAML and bash.

CodePudding user response:

After each export command, you also need to set the variable in the variable service to be able to expose it as an environment variable.

- task: Bash@3
inputs:
   targetType: 'inline'
   script: |
           export cache=30
           echo "##vso[task.setvariable variable=cache;]${cache}"
           export url={"https.8shd3dad#d/[email protected]"}
           echo "##vso[task.setvariable variable=url;]${url}"
           export Delay=10
           echo "##vso[task.setvariable variable=Delay;]${Delay}"
env:
   cache : $(30)
  • Related