Type: Bug
Enter Task Name: AzureCLI@2
https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureCLIV2
Server - Azure Pipelines
Agent - Hosted
I'm trying to use the AzureCLI@2 task on a hosted vs2017-win2016 agent to call a PowerShell script via a path, not inline, but I'm having a problem with it honoring the script's default parameter values.
I think a small example illustrates the problem best.
Given the script test.ps1
param(
[Parameter(Mandatory = $false)][String]$resourceGroupName = "test-rg",
[Parameter(Mandatory = $false)][String]$location = "centralus"
)
Write-Output "`nPSBoundParameters.Count"
$PSBoundParameters.Count | Format-Table
Write-Output "`nPSBoundParameters"
$PSBoundParameters | Format-Table
Write-Host "`nresourceGroupName..."
Write-Host $resourceGroupName | Format-Table
Write-Host "Parameters: location..."
Write-Host $location | Format-Table
and the azure-pipeline.yml
trigger: none
variables:
subscription: 'yourSubscriptionHere'
stages:
- stage: infrastructure
jobs:
- job: build_infrastructure
pool:
vmImage: 'vs2017-win2016'
steps:
- task: AzureCLI@2
displayName: 'Azure CLI script with arguments'
inputs:
azureSubscription: $(subscription)
scriptType: 'ps'
scriptLocation: scriptPath
scriptPath: ./deploy.ps1
scriptArguments: '-resourceGroupName test-rg -location centralus'
- task: AzureCLI@2
displayName: 'Azure CLI script without arguments'
inputs:
azureSubscription: $(subscription)
scriptType: 'ps'
scriptLocation: scriptPath
scriptPath: ./deploy.ps1
I would expect both tasks to output the same thing. Something like...
PSBoundParameters.Count
2
PSBoundParameters
Key Value
--- -----
resourceGroupName test-rg
location centralus
resourceGroupName...
test-rg
Parameters: location...
centralus
But I only get that output on the task when I explicitly supply it with parameters from the pipeline yaml. If I omit them and try let the script use it's defaults I get the following output
PSBoundParameters.Count
1
PSBoundParameters
Key Value
--- -----
resourceGroupName null
resourceGroupName...
null
Parameters: location...
centralus
Which is weird because 1) PSBoundParameters only seems aware of one parameter and 2) that's the parameter that's null and the other prints fine. I also noticed this behavior is completely dependent on the order in which you specify the parameters.
I have tried both script types ps & pscore
I have also tried this same problem with a normal PowerShell task, things behave as expected here.
@jalajmsft Can you take a look at this ?
@winstonhenke Thanks for reporting this issue ! We have identified a bug and will be rolling out the fix soon. The issue is when arguments is not passed, the script gets called with arguments value as null which is why first parameter will be affected and assigned value null.
While the fix gets rolled out, you can unblock yourself by modifying the script and setting the default value for first parameter explicitly when argument is null.
@winstonhenke The fix will be available with version 2.0.2 within few days. Please feel to reopen this issue if problem persists.