powershellazure-devopsazure-devops-pipelines

Azure Devops Pipeline - How to pass variable into Powershell function


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 

Solution

  • 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}}"'