Jenkins插件,如何在远程节点上执行系统命令? [英] Jenkins plugin, how to execute system command on remote node?

查看:249
本文介绍了Jenkins插件,如何在远程节点上执行系统命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司的Jenkins具有主节点和两个从节点.我正在为此写插件.插件要做的一件事是从svn中检出一些文件.无法从插件中提取此操作. 为此,我从插件的Java代码执行控制台命令"svn checkout".问题在于,svn中的文件被检出到主节点,而不是从节点. 如何使文件检出到从站?

Our company's Jenkins has master and two slave nodes. I am writing plugin for it. One of the things for plugin to do is to checkout some files from svn. This action cannot be extracted from plugin. To do this I execute console command "svn checkout" from java code of my plugin. The problem is that files from svn are checked out to master, rather than to slave nodes. How can I make files be checked out to slave?

推荐答案

首先,您拥有以下对象,通常作为perform方法的参数接收:

First you have these objects, usually received as parameters for perform method:

Launcher launcher;
AbstractBuild<?, ?> build;
BuildListener listener;

然后,您已经创建了参数并将其添加到argumentsListBuilder中,也许是这样的:

Then you have created and added arguments to an argumentListBuilder, maybe something like:

ArgumentListBuilder command = new ArgumentListBuilder();
command.addTokenized("xcopy /?");

然后,执行以下操作:

ProcStarter ps = launcher.new ProcStarter();
ps = ps.cmds(command).stdout(listener);
ps = ps.pwd(build.getWorkspace()).envs(build.getEnvironment(listener));
Proc proc = launcher.launch(ps);
int retcode = proc.join();

ProcStarter将在launcher实例指定的节点上运行命令.但是在使用之前,请至少先浏览一下以上所有类的javadocs,这不是从工作代码中直接复制粘贴的内容.

ProcStarter will run the command at the node specified by the launcher instance. But please at least glance over the javadocs of all above classes before using, above is not direct copy-paste from working code.

这篇关于Jenkins插件,如何在远程节点上执行系统命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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