4

I am new to VSTS and Azure Kubernetes. I am building a VSTS CD pipeline. I have added a Deploy to Kubernetes task in my pipeline. I am executing the get command and trying to store the output in the output variables (which is available at the bottom of the Deploy to kubernetes task). I have set the variable name.

VSTS output variable

I am trying to fetch the value of the above output variable. I have used command line task to set a value to the variable as mentioned below

echo '##vso[task.setvariable variable=myStatusVar;isSecret=false;]$(myvar)'

where myvar is the variable, which is set in the Deploy to kubernetes task as output variable.

After that in another command line task, I am trying to access the myStatusVar variable value, but when I execute the release pipeline, it shows the message:

myvar command not found

Can anyone let me know, how to use the output variable of the Deploy to kuberentes task of VSTS pipeline?

Josh Gust
  • 4,102
  • 25
  • 41
HowsTheJosh
  • 85
  • 2
  • 6
  • looks to me like the output is actually stored in myvar.KubectlOutput, plus the ##vso part looks more like powershell than bash. – Markus Dresch Mar 11 '19 at 10:15
  • nah, the `##vso` part is a special vsts token, so it doesnt matter where you use it – 4c74356b41 Mar 11 '19 at 10:26
  • @MarkusDresch You are right, it stored in the myvar.KubectlOutput, but how to access this value? It's a bash script. I had also tried with the command line task but still not working. – HowsTheJosh Mar 11 '19 at 10:44

1 Answers1

5

As stated in the comments your variable is 'exposed' as 'myvar.KubectlOutput'

the way you are able to use it in scripts differs based on type of scripting you are doing:

  • Batch script: %MYVAR_KUBECTLOUTPUT%
  • PowerShell script: $env:MYVAR_KUBECTLOUTPUT
  • Bash script: $MYVAR_KUBECTLOUTPUT
  • Azure Devops 'designer view': $(myvar.KubectlOutput)

For more details on this see the documentation on using variables in Azure DevOps: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch

Remco Brilstra
  • 798
  • 5
  • 13
  • 2
    Keep in mind that MYVAR_KUBECTLOUTPUT has to be upper-case. I ignored the case (and didn't read the doc carefully) and spent 20 minutes scratching my head! – Kayes Dec 19 '19 at 06:31