我正在尝试从Jenkins执行批处理文件。我遇到一些错误。我的批处理文件调用了一个shell文件,该文件包含用于卸载应用程序的代码
Windows Power Shell脚本代码:
$uninstallString = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "program name" } | select BundleCachePath
if ($uninstallString -ne $null){Start-Process $uninstallString.BundleCachePath -ArgumentList "-Uninstall -Quiet -Wait"}else{Write-Host "Uninstall string not found!"}
批处理文件包含:
powershell.exe -ExecutionPolicy ByPass -noexit -file G:\Uninstall\uninstall.ps1
好吧,如果我手动运行批处理文件,该应用程序将成功卸载。
在詹金斯,我看到以下错误:
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Uninstall_pro
[Uninstall_ORD] $ cmd /c call C:\Windows\TEMP\jenkins7854020138412075044.bat
C:\Program Files (x86)\Jenkins\workspace\Uninstall_pro>"?G:\Uninstall\uninstall.bat"
The system cannot find the path specified.
C:\Program Files (x86)\Jenkins\workspace\Uninstall_ORD>exit 3
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
答案 0 :(得分:0)
我将使用Jenkins PowerShell Plugin,这样您就可以删除批处理文件,并且仅处理Powershell。
您可以在Powershell步骤中使用PS代码(完全不需要单独的批处理文件和Powershell脚本):
或者您也可以仅删除批处理文件-使用call operator从步骤运行Powershell脚本(如果该脚本来自SCM检出,则非常有用):