How to use output variable of Deploy to Kubernetes task in Azure pipeline (VSTS)

3/11/2019

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?

-- HowsTheJosh
azure-devops
azure-pipelines
azure-pipelines-release-pipeline
kubernetes

1 Answer

3/11/2019

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://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch

-- Remco Brilstra
Source: StackOverflow