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

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.
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?

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

Related

Passing variables between release pipelines in azure (trigger azure pipeline extension)

I have a requirement to pass data between 2 release pipelines (to trigger 2nd pipeline on completion of 1st pipeline).
Can we pass variables dynamically between azure RELEASE pipelines using trigger an Azure DevOps pipeline extension?
I tried this blog but unable to find/understand if we can use "output variables" to pass data between azure release pipelines.
https://msftplayground.com/2019/02/trigger-a-pipeline-from-an-azure-devops-pipeline/
Thank you in advance!
Output variables are created by the pipeline and referenced by the other tasks in the pipeline, it means they are dynamic and refers to the result of a particular task.
These cannot be defined statically.
After running the task in the pipeline, output variables value can be known.
There are two different ways to create output variables :
By building support for the variable in the task itself
Setting the value ad-hoc in a script
Below example is defining a task with the name SomeTask that natively creates an output variable called out.
In a task within that same job, you can reference that variable using $(SomeTask.out).
steps:
- task: MyTask#1
name: SomeTask
- script: echo $(SomeTask.out)
For the detailed information regarding how to create output variables and pass between the pipelines, please refer azure devops output variables.

Azure Devops CLI Task - show output

I am using the Azure CLI task Version 2. The only problem, i need some output so that it´s showed as part of the pipeline run. The task however wraps all inline scripts in a script file so that i can´t see the output. How can I achieve that?
Thank you. It works now, you are right, I used the Bash#3 task instead. I use the output from the AzCLI task to define a pipeline variable and the bash task to print it.
service=$(kubectl get service --namespace $(aks-namespace) -o jsonpath='{.items[0].status.loadBalancer.ingress[0]}')
echo "##vso[task.setvariable variable=serviceip]$service"

$(Build.BuildId) not replacing in terraform tf file in Azure build pipeline

I am using terraform files with the .net core 2.1 project. I am trying to put a revision number in one of the terraform file and the revision number would be replace with the Build.BuildId of Azure pipeline.
Build.BuildId is predefined variable in Azure pipeline.
I tried a lot but It is not working.
According to the Terraform documentation, we have to create environment variables named TF_VAR_x for Terraform to automatically pick them up.
Another option is to pass the variable value in to the Terraform script by specifying -var 'BuildId=$(Build.BuildId)' on the command line

How to update a pipeline variable after the task is succeeded, through `output variable` section or some other method in Azure devops

I want to update a pipeline variable once my task is finished. Can I do it through output variable section provided in azure DevOps?
The main objective is to let downstream tasks know that the list of specific previous tasks have succeeded, which I can check by adding custom conditions.
If your tasks are in an agent job, there is no need to use the output variable section, just add a Powershell task after the successful task, you can overwrite/update the value of the variables by using the logging command to set the variables again in Azure Devops pipeline.
Write-Host "##vso[task.setvariable variable={variableName}]{updateValue}"
To set a variable from a script, you use the task.setvariable logging command. This doesn't update the environment variables, but it does make the new variable available to downstream steps within the same job. In addition ,here is a reference.

"az pipelines run variables" not working the way i expected

i have a branch in git with a .yaml build file which has a script to simply print out the value of the variable declared in the .yaml
if i run the command: az pipelines run --id 999 --variables "myvar=myvar" I expected the variable to change as I am injecting it. it doesnt.
am i misunderstanding what this switch does? if so, what is it supposed to do and/or how can i achieve my goal?
i tried
i tried
i dont understand these SO "quality standards" <= (this line allowed me to save the post)
For az pipelines variable ,there are four commands
az pipelines variable create Add a variable to a pipeline.
az pipelines variable delete Delete a variable from pipeline.
az pipelines variable list List the variables in a pipeline.
az pipelines variable updateUpdate a variable in a pipeline.
You should use az pipelines variable update command to update a variable in a pipeline.
Command sample:
az pipelines variable update --name