从 jenkins 在远程服务器(windows)上运行批处理脚本 [英] Run batch scripts on a remote server (windows) from jenkins

查看:351
本文介绍了从 jenkins 在远程服务器(windows)上运行批处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个持续集成服务器 (Jenkins),它构建我的代码(检查编译错误)并运行测试,然后将文件部署到远程服务器(不是 war 文件,而是实际的文件结构)我做这是一个 Jenkins 插件,它允许我通过 samba 传输文件,它每晚都这样做.

I've got a continuous integration server (Jenkins ) which builds my code (checks for compilation errors) and runs tests and then deploys the files to a remote server (not a war file, but the actual file structure) I do this with a Jenkins plugin which allows me to transfer files via samba, it does this nightly.

现在,我需要做的是在远程服务器上运行 ant 命令.之后我需要在远程服务器上启动应用服务器,应用服务器是通过从命令行运行一个 .bat 文件来启动的.

Now, what I need to do is run an ant command on the remote server. And after that I need to start the application server on the remote server, the application server is started by running a .bat file from the command line.

我对如何实现这一点一无所知,我知道 Jenkins 能够运行批处理命令,但是如何让它们在服务器的上下文中运行,而不是在构建服务器的上下文中运行?

I'm pretty clueless how to accomplish this, I know Jenkins is capable of running batch commands, but how do I make them run in the context of the server and not the context of the build server?

推荐答案

如果 Jenkins 在 Windows 上,远程在 *nix 上,使用 plink.exe(本质上是命令行 PuTTy代码>)

If Jenkins on Windows, remote on *nix, use plink.exe (which is essentially command line PuTTy)

如果 Jenkins 在 Windows 上,远程在 Window 上,使用 psexec.exe

If Jenkins on Windows, remote on Window, use psexec.exe

如果Jenkins在*nix上,远程在*nix上,使用ssh

If Jenkins on *nix, remote on *nix, use ssh

如果 Jenkins 在 *nix 上,在 Windows 上远程,(更新 2015-01)Ansible http://docs.ansible.com/intro_windows.html 支持从 unix/linux 机器调用 Windows 命令,例如 powershell,https://github.com/ansible/ansible-examples/blob/master/windows/run-powershell.yml

If Jenkins on *nix, remote on Windows, (update 2015-01) Ansible http://docs.ansible.com/intro_windows.html has support for calling Windows commands, eg powershell, from a unix/linux machine, https://github.com/ansible/ansible-examples/blob/master/windows/run-powershell.yml

告诉我涉及哪些操作系统(包括 Jenkins 和远程),我会进一步说明.

Tell me what OSes are involved (both on Jenkins and remote), and I will flash this out further.


psexec.exe 列出所有命令行选项.你会想要一些类似的东西:


The download page for psexec.exe lists all command line options. You will want something along the lines of:

psexec \\remotecomputername -u remoteusername -p remotepassword cmd/c <你的命令在这里>
替换为实际命令,就像在命令提示符下执行它们一样.

psexec \\remotecomputername -u remoteusername -p remotepassword cmd /c <your commands here>
Replace <your commands here> with actual commands as you would execute them from command prompt.

请注意,psexec 首先需要安装服务,并且需要提升的命令提示符/管理员远程凭据才能这样做.
此外,您需要运行一次 psexec -accepteula 以接受 EULA 提示.

Note that psexec first needs to install a service, and required elevated command prompt/admin remote credentials to do so.
Also, you need to run psexec -accepteula once to accept the EULA prompt.

这篇关于从 jenkins 在远程服务器(windows)上运行批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆