我已在Windows计算机上安装了Azure P2S VPN,我可以手动连接它。我还有一个PowerShell脚本来完成这项工作。脚本如下:
rasphone "Azure-VPN"
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Network Connections')
Sleep 2
$wshell.SendKeys('~')
Sleep 2
$wshell.SendKeys('~')
当我手动连接时,$wshell.SendKeys('~')
将取代按Enter键。
我可以从命令行运行此脚本以成功连接VPN:
> powershell C:\myScript.ps1 True
现在我想在Jenkins管道上运行这个脚本。但这似乎无法实现。
stage('VPN'){
bat "powershell C:\\myScript.ps1"
}
它在Jenkins控制台输出上返回False
。
我也尝试了the accepted answer here,但仍然没有成功(既不能从命令行运行,也不能在Jenkins上运行)
> rasdial Azure-VPN /phonebook:%userprofile%\AppData\Roaming\Microsoft\Network\Connections\Cm\<aLongNumber>\<aLongNumber>.pbk
Remote Access error 623 - The system could not find the phone book entry for this connection.
有什么解决方法吗?我的目的是使用Jenkins管道打开VPN,通过网络发送一些文件,然后关闭它。
发布于 2019-10-31 15:06:17
你可以选择使用Jenkin的Windows插件,通过Jenkins直接在上运行Powershell脚本。你可以从this blog获得更多的参考资料。
或者,参考this SO answer,您可以使用Jenkins调用批处理文件,如下所示:
stage('build') {
dir("build_folder"){
bat "run_build_windows.bat"
}
}
或
stage('build') {
bat "c://some/folder/run_build_windows.bat"
}
https://stackoverflow.com/questions/58623543
复制相似问题