0
votes

I have an Azure DevOps online and want to set Buildnumber as ImageTag variable, to use it later as Image tag for docker image. To do so, I created empty variable ImageTag on the variables tab:

var

And add PS script:

Write-Host "Buildnumber is $(Build.BuildNumber)"
$ImageTagVar = "$(Build.BuildNumber)"

Write-Host "##vso[task.setvariable variable=ImageTag;]$ImageTagVar"

Write-Host "Set environment variable to $env:ImageTag"
Write-Host "Set environment variable1 to $ImageTag"

enter image description here

The problem is that content from $(Build.BuildNumber) does not pass to variable ImageTag:

log

Can anyone hint me, what am I doing wrong in Azure DevOps?

3

3 Answers

1
votes

You will see it on next steps of your build pipeline:

  1. Steps in build definition:

Step 1

enter image description here

Step 2

enter image description here

  1. Build results

Step 1

enter image description here

Step 2

enter image description here

1
votes

If you just want to tag the docker image with buildNumber, you do not need to define the ImageTag variable. You can directly use $(Build.BuildNumber) in the docker build task.

enter image description here

If you have to define the ImageTag variable, you can directly assign $(Build.BuildNumber) to it.

enter image description here

-1
votes

We cant use these variable for release pipeline ..Is there any way to configure build.buildNumber across release and build pipeline ??