1

I have Yaml pipeline with powershell task:

       - task: PowerShell@2
        inputs:
          targetType: filePath
          filePath: $(System.DefaultWorkingDirectory)\folder\script.ps1
          arguments: > 
            -SP_TenantId "$(SP_TenantId)"
            -ProjectName "${{parameters.ProjectName}}"

The script.ps1 has a PS Function which starts with mandatory parameters from Yaml arguments

    param (
    [Parameter(Mandatory = $true)][string]$SP_TenantId,
    [Parameter(Mandatory = $true)][string]$ProjectName,

)

After running the pipeline I've got an error telling that env are missing:

Get-GraphToken : Cannot process command because of one or more missing mandatory parameters: SP_TenantId 
Mski
  • 13
  • 1
  • 3

2 Answers2

1

Azure Devops Pipeline - How to pass variable into Powershell function

You could try to remove the second comma in the script.ps1:

param (
[Parameter(Mandatory = $true)][string]$SP_TenantId,
[Parameter(Mandatory = $true)][string]$ProjectName

)

I test it, it works fine on my side. Please check it.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
0

when I compare your snippet with a pipeline of mine, I've recognized some differences according to providing the arguments: can you try it that way?

inputs:
  targetType: filePath
  filePath: $(System.DefaultWorkingDirectory)\folder\script.ps1
  arguments: '-SP_TenantId:"$(SP_TenantId)" -ProjectName:"${{parameters.ProjectName}}"'
bianconero
  • 215
  • 1
  • 12