1

I have a pipeline task which is as follow:

- task: PowerShell@2
displayName: 'Script1'      
inputs:
  filePath: '$(System.DefaultWorkingDirectory)/Terraform/helloworld1.ps1'

And it run a helloworld1.ps1 , but the helloworld1.ps1 script call another script. here's the code of helloworld1:

Write-Host 'Hello from 1st File.'

. ./helloworld2.ps1

And the helloworld2.ps1 scripts contains this one line only:

Write-Host 'Hello from 2nd File.'

BUT, when when pipelines triggers, its run the script1 and print its first line and then failed on 2nd line throwing the error:

 | The term './helloworld2.ps1' is not recognized as a name of a
 | cmdlet, function, script file, or executable program. Check
 | the spelling of the name, or if a path was included, verify
 | that the path is correct and try again.
5
  • Is the path correct for helloworld2.ps1 ? Where is the script located? Try also powershell.exe .\helloworld2.ps1 Commented May 31, 2022 at 7:35
  • Does it work if you change ./helloworld2.ps1 to $PSScriptRoot/helloworld2.ps1 ? Commented May 31, 2022 at 7:39
  • @GeralexGR the path is correct because when i run the script locally on powershell it worked perfetly. also the helloworld2.ps1 is in the same directory. Commented May 31, 2022 at 7:53
  • @YanSklyarenko, I've just tried it... it throw this error | $PSScriptRoot/helloworld2.ps1 | ~ | You must provide a value expression following the '/' operator Commented May 31, 2022 at 7:55
  • @YanSklyarenko kindly have a look at this one too... Now I'm facing error on calling functions. from another script. stackoverflow.com/questions/72446559/… Commented May 31, 2022 at 12:55

1 Answer 1

1

Got the answer of my own question. After using PSScriptRoot, the issue is resolved! so the correct helloworld1.ps1 is as follow:

 Write-Host 'Hello from 1st File.'

 & "$PSScriptRoot/helloworld2.ps1"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.