0

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.