Azure Devops Pipeline variables in Powershell I've tried to figure this out and I can't see why my ipaddress is not getting set.
I've checked code samples and they all suggest I am doing everything correct.
ip variable defined here:

This is my powershell script:
# Write your PowerShell commands here.

Write-Host &quot;AGENTIPADDRESS variable is set to ($env:AGENTIPADDRESS)&quot;

$ipaddress = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
Write-Host &quot;ipaddress variable is set to ($ipaddress)&quot;
Write-Host &quot;ip pipeline variable to ($ip)&quot;

Write-Host &quot;##vso[task.setvariable variable=IP;]$ipaddress&quot;
Write-Host &quot;##vso[task.setvariable variable=env:IP;]$ipaddress&quot;
Write-Host &quot;##vso[task.setvariable variable=$env:IP;]$ipaddress&quot;
echo &quot;##vso[task.setvariable variable=IP;]$ipaddress&quot;
Write-Host &quot;##vso[task.setvariable variable=IP;]333&quot;
Write-Host &quot;##vso[task.setvariable variable=IP;]$ipaddress&quot;
echo &quot;##vso[task.setvariable variable=IP]999&quot;
echo &quot;##vso[task.setvariable variable=IP;]888&quot;

Write-Host &quot;##vso[task.setvariable variable=IP;]$ipaddress&quot;
Write-Host &quot;##vso[task.setvariable variable=IP;]$ipaddress&quot;
Write-Host &quot;##vso[task.setvariable variable=IP]114&quot;
Write-Host &quot;##vso[task.setvariable variable=IP;]123&quot;

Write-Host &quot;ip environment variable to ($ip)&quot;
Write-Host &quot;env:IP environment variable to ($env:IP)&quot;

Write-Host &quot;Set environment variable to ($env:AGENTIPADDRESS)&quot;

And here is my output:

Why can't I set &amp; read the ip variable?
The issue is that you can't reference the changed value in the same task.
I created a new Powershell task and just called Write-Host &quot;env:IP environment variable set to ($env:IP)&quot; which output the IP address correctly.