0
votes

Can you not call a script from within a script in an Azure PowerShell task?

Background -

I have a an Azure Repo with two scripts in it (let's call them script0 and script1). There's no build going on so there's no build pipeline. There's just a release pipeline. The artifact it is picking up from is Azure Repository Git. I have just one task in the (release) pipeline and it's the Azure PowerShell task.

In script0, which is the main script, I have a for loop, which requires me to run the script1 (apart from the various other things that goes on in the loop).

For the life of me, I am unable to figure out how I can achieve that. Worst of it, it works locally. Also, everything else works in the loop. I have tried tons of things to fix it, but I will start with just this for now: The error I am being thrown when I run

$TeamFoundationCollectionUri$TeamProject/testscript.ps1 $stage $FunctionHosts[$i] (($hashtable | select -First 6).Key[$i]) $ResourceGroupName $location $functionApps $AdminClientSecret $VaultName $JsonFile

(Now, mind you - that is part of script0 - the main script).

Here's the error:

enter image description here

The blurred area is script0 and testscript.ps1 is script1

I have tried almost everything

  1. Using the Call operator &
  2. Using \, /, //
  3. Invoke-Expression -Command "<code here>"
  4. Invoke-Command
  5. Also tried powershell.exe -Command <code here>

As you can tell, none of these have worked.

1

1 Answers

1
votes

I got this working by using the Call operator (&) before the path where the script resides. So, I did this:

& $(System.ArtifactsDirectory)\$(System.TeamProject)\testscript.ps1 <pass the params here>

and it worked.