简体   繁体   中英

PowerShell script called from within the Jenkins PowerShell build step hangs indefinitely

I have a Jenkins (1.493) project that uses the Jenkins PowerShell build step to execute a PowerShell script. Inside that script I want to invoke another script that is stored inside a file. I have now reduced it to the following:

Script inside Jenkins PowerShell build step:
& "\\\\stemmer.local\\sidevelopment\\cvdev\\devbase\\jenkins\\PowerShell\\Test.ps1"

Content of Test.ps1:
write-host 'Hello world!'

Whenever this Jenkins project executes, the PowerShell build step hangs indefinitely.

Things I have tried/verified so far:

  • Adding some output before the invocation of Test.ps1 shows me that the Jenkins PowerShell script is being execute normally up to the point where Test.ps1 is called.
  • The file Test.ps1 exists and is reachable from the build slave that executes the script. If I alter the file's name, I get the expected error message from PowerShell...
  • Exchanging the " for ' in the 1st script does not change anything. Also, using dot-sourcing rather than & does not help.
  • The file Test.ps1 can be executed properly from the powershell itself using the same command line that is being used in the Jenkins PowerShell script.
  • The execution policy for PowerShell has been set to unrestricted on my development host as well as on the Jenkins build slave.
  • I've tried replacing the PowerShell build step with a Windows batch command build step that looks like this:
    powershell.exe -InputFormat None -File "\\\\stemmer.local\\sidevelopment\\cvdev\\devbase\\jenkins\\PowerShell\\Test.ps1"
    and played around a little with the parameters of powershell.exe, but the results were - in those cases that were syntactically and otherwise correct as far as I can tell - always the same.

I only found few references to problems that sounded similar, but none of the approaches mentioned elsewhere did help me fix this. I am absolutely puzzled, and wondering whether someone encountered this issue before (and maybe even got a scenario like the one I have in mind running).

Thanks a lot for any input!

Volker

have you tried to set execution policy to bypass ?

Copy the script file locally, then invoke it from within the Jenkins PowerShell plugin - that way it works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM