欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Jenkins执行批处理文件、powershell失败

程序员文章站 2022-04-30 15:16:54
...

Jenkins执行批处理文件、powershell失败
报错信息如下:

[test.91huayi.com] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\2\jenkins4014820078164762375.ps1'"
The system cannot find the file specified
FATAL: 命令执行失败
java.io.IOException: CreateProcess error=2, 系统找不到指定的文件
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 192.168.1.52/192.168.1.52:58104
		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
		at hudson.remoting.Channel.call(Channel.java:955)
		at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1059)
		at hudson.Launcher$ProcStarter.start(Launcher.java:455)
		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)
		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
		at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
		at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
		at hudson.model.Build$BuildExecution.build(Build.java:206)
		at hudson.model.Build$BuildExecution.doRun(Build.java:163)
		at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
		at hudson.model.Run.execute(Run.java:1810)
		at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
		at hudson.model.ResourceController.execute(ResourceController.java:97)
		at hudson.model.Executor.run(Executor.java:429)
Caused: java.io.IOException: Cannot run program "powershell.exe" (in directory "D:\jenkins\workspace\test.91huayi.com"): CreateProcess error=2, 系统找不到指定的文件。
	at java.lang.ProcessBuilder.start(Unknown Source)
	at hudson.Proc$LocalProc.<init>(Proc.java:249)
	at hudson.Proc$LocalProc.<init>(Proc.java:218)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:936)
	at hudson.Launcher$ProcStarter.start(Launcher.java:455)
	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1313)
	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1266)
	at hudson.remoting.UserRequest.perform(UserRequest.java:212)
	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
	at hudson.remoting.Request$2.run(Request.java:369)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93)
	at java.lang.Thread.run(Unknown Source)
	

解决办法:
环境变量PATH路径中,缺少没有执行poweshell的路径。”%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\,”

Jenkins执行批处理文件、powershell失败
参考链接:

https://www.cnblogs.com/shenh/p/7771090.html
https://*.com/questions/15135771/hudson-on-windows-error-java-io-ioexception-cannot-run-program-sh