0

I have an Azure DevOps release pipeline that I am experimenting with. The first task in the release pipeline is an AZ Powershell task. This task has a Powershell Script file. The below is the content of the file -

[CmdletBinding()]
param (
   $MyVar
)
$MyVar = "My Value"
Write-Host '##vso[task.setvariable variable=NewVar;]$MyVar'

The second task in the pipeline again is an AZ Powershell task with a Powershell script with the below content -

[CmdletBinding()]
param (
   $MyNewVar
)

$MyNewVar = "$(NewVar)"
Write-Host $MyNewVar

I run the simple release pipeline and I receive the below error

Cannot validate argument on parameter 'NewVar'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

Please note that the same works fine when running the same Powershell code Inline in each of the AZ Powershell tasks.

Any help would be highly appreciated.

1
  • Please note that I do not want to use Inline Powershell. It has to be a .ps1 file located in my DevOps repository. Commented Oct 8, 2021 at 16:02

2 Answers 2

1

I added a new argument as below in the second task -

-$MyNewVar "$(NewVar)"

This as well didn't work successfully but then in the first task, I changed the last line containing single quotes to double, i.e.

Write-Host '##vso[task.setvariable variable=NewVar;]$MyVar' 

changes to

Write-Host "##vso[task.setvariable variable=NewVar;]$MyVar"

This finally resolved the issue.

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

Comments

0

If you don't use inline script you can't use the syntax $MyNewVar = "$(NewVar)", the $() syntax it's for Azure DevOps tasks, PS not recognize it.

You should use the environment variable syntax:

$MyNewVar = "$env:NewVar"

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.