Skip to main content

Command Palette

Search for a command to run...

AzureDevops : Set Ouput Variable in the same job and use it in other tasks

Published
1 min read
AzureDevops : Set Ouput Variable in the same job and use it in other tasks
S

I love learning about technology and sharing that with others

Motivation

while creating a build, in my workplace we usually pull all the latest changes in local and then run few git commands and then change those values in the build pipeline,

Automation:

  1. Use Azure bash task to run the git commands
  2. Store the results in some variables and then use that in other tasks,

How to use bash tasks to store the variable

echo "------------  Output Results ----------------"
echo "build version of the 8 characters:  ${PBuildVersionFirst} "
echo "build version with 4 character    :  ${PBuildVersionSecond} "


# here we are storing variable PBuildVersionFirst in the variable PBuildVersionFirst1 and #then use it other tasks


echo "##vso[task.setvariable variable=PBuildVersionFirst1]${PBuildVersionFirst}"
echo "##vso[task.setvariable variable=PBuildVersionFirst2]${PBuildVersionSecond}"

How to use the above variable in PowerShell Script tasks ?

Write-Host $(PBuildVersionFirst1)
Write-Host $(PBuildVersionFirst2)

How to use the above variable in bash script tasks?

echo  $(PBuildVersionFirst1)
echo  $(PBuildVersionFirst2)

Next Steps :

Use this variable in the Gradle task and then generate the build artifact :)

7 views

More from this blog

H

hashcodehub

271 posts

Consistent, Passionate and Organized :)