Home > Mobile >  Azure Powershell - load variables from another script file
Azure Powershell - load variables from another script file

Time:03-22

In Azure DevOps, I have an Azure Powershell task to create some resources using ps1 script in repo. This script working fine.

Now I need to split the script and variables into different files. I created files SB-Config.ps1 for variables and ServiceBus.ps1 with main script. Moved all vars into SB-Config.ps1 . Both files are in the same folder and in ServiceBus.ps1 I added:

. .\SB-Config.ps1

But Azure Devops fails with error:

enter image description here

What I'm doing wrong and how to get variables from SB-Config.ps1 script, when running ServiceBus.ps1 file?

CodePudding user response:

I am able to reproduce your situation on my side.

Same issue as yours.

You can run this command to output the location of current work space:

Get-Location

I notice the powershell script file on your side is in the sub folder of Default working directory.

So do you set the work space in the powershell script file you are running first?

Set-Location $env:System_DefaultWorkingDirectory\subfolders

In your situation, I think the issue comes from the current work space is System_DefaultWorkingDirectory , the error output means the script can't get the file you want. This issue only occurs when you select 'file path' to run.

  • Related