Home > Back-end >  Azure release pipeline, passing variable to power-shell script is not giving desired output
Azure release pipeline, passing variable to power-shell script is not giving desired output

Time:07-19

In Azure release pipeline (using GUI) I am using an inline PS script task which checks for Folder names and File extensions. The script works if I provide the folders and extensions values directly into Where-Object cmdlet, e.g.

Get-ChildItem -Path $path | `
      Where-Object { ($_.Name -in "ConsoleApps","WebDeployParameters") -or ($_.Extension -in ".xml",".config",".asax")} 

But it does not work if I create and pass the Variables: enter image description here

into where-object cmdlet:

$path = "$($env:DropLocation)\$($env:CurrentRelease)\"

$Names = Get-ChildItem -Path $path | `
      Where-Object { ($_.Name -in $env:FoldersName) -or ($_.Extension -in $env:FileExtensions)} 
#| Remove-Item -Force -ErrorAction SilentlyContinue

write-host $Names

Could someone point out, what might be going wrong here? Because the same code works if I run it on my local machine:

$FileExtensions = ".xml",".config",".asax"
$FoldersName = "ConsoleApps","WebDeployParameters"

Get-ChildItem -Path $path | `
      Where-Object { ($_.Name -in $FoldersName) -or ($_.Extension -in $FileExtensions)} 

Attached is an image of the pipeline: enter image description here

CodePudding user response:

When you pass a pipeline variable into the script the syntax is $(variable_name).

Instead of $env:variable_name

Here is an example I use to pass pipeline variables into my scripts: enter image description here

Here is the Microsoft documentation on setting variables in scripts.

  • Related