Function call working fine in local but not in Azure powershell task

Jose, Midhun 21 Reputation points
2020-11-11T15:43:03.397+00:00

When I run my belowpowershell script to call afunction its working fine in local powershell

SetVariables -Wslot $slot

function definition like

function SetVariables($Wslot) {
.....}

but while I run the same powershell Script from a powershell task in Azure build pipeline, getting the below error,

**.ps1 : The term 'SetVariables' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

below are the properties of the Azure powershell task

task version 2.*
under advanced -> use powershell core option is enabled

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,087 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue 36,751 Reputation points Microsoft Vendor
    2020-11-12T06:11:13.977+00:00

    Hi,

    Where is the function definition? Is it in the same script where you call it? Try moving the definition to the beginning of the script.

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 46,711 Reputation points
    2020-11-11T19:40:41.993+00:00

    What happens if you change the name of the function SetVariables? Looking at that name, it always seems to be used together with 'task.' I'm guessing that this is something specific to Azure and not to Powershell.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.