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

Windows for business Windows Server User experience PowerShell
Community Center Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    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 47,901 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.