Setting OS variable in Azure DevOps pipeline doesn't work

322 Views Asked by At

In YAML pipeline I'm attempting to set OS variable on Linux Agent so Cypress can look it up:

  - script: export CYPRESS_key=ala
    displayName: "Set key"

  - script: echo $(CYPRESS_key)
    displayName: "Print key"

unfortunately the OS variable is never set. The output is:

/home/vsts/work/_temp/321aacd-cadd-4a16-a4d1-db7927deacde.sh: line 1: CYPRESS_key: command not found
2

There are 2 best solutions below

0
Facty On

$(command) and ${variable} you are using wrong brackets

- script: export CYPRESS_key=ala
  displayName: "Set key"

- script: echo ${CYPRESS_key}
  displayName: "Print key"

- script: echo $(cat /etc/os-release)
  displayName: "Print file content"
1
Daniel Mann On

Environment variables in Linux are accessed as $ENVIRONMENT_VARIABLE_NAME, not $(ENVIRONMENT_VARIABLE_NAME).