I want to be able to simplify some inline powerscript in an AzureCLI task using a function, similar to the following:
- task: AzureCLI@2
displayName: "My Task"
inputs:
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
Do-Something "hello" "world"
Do-Something "goodbye" "world"
function Do-Something {
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string] $Hello,
[Parameter(Mandatory=$true, Position=1)]
[string] $World
)
Write-Host "$Hello $World"
}
However this fails with the following error:
+ Do-Something "hello" "world"
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (Do-Something:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
##[error]Script failed with exit code: 1
Is this possible? If so, what am I doing wrong?
functionkeyword) before you can call it. Move theDo-Something ...statements below the function definition and it'll work