Hey Everyone,
I am new to plugin creation, and have a need to create a plugin that generates a specific file based on user-input to a remote node containing large strings of data.
I am aware of the current "Execute Shell" build step option and "Execute remote commands via SSH" plugin,
but do not want users to have to input this large string of data themselves into the job config shell execute text field.For now, I would like to create a plugin that can execute shell commands on a remote node, once I have this, I should be able to figure out the rest myself.
I found this code snippet (below) which works fine for executing simple shell commands on local jenkins system.
What I want to do is modify this code snippet to also work when the job is configured to execute on a remote node.
When I configured the job to execute on a remote node, I received the following error (below below)
If executing the commands on the remote node is too hard, is there a way to auto-input that large string of data into the execute shell text box in the jenkins job configuration, as this would work too?
Can anyone assist?
Thanks very much in advance,
~Ravid
[CODE SNIPPET]
List<Cause> buildStepCause = new ArrayList();
buildStepCause.add(new Cause() {
public String getShortDescription() {
return "Build Step started by Hello Builder";
}
});
listener.started(buildStepCause);
ArgumentListBuilder args = new ArgumentListBuilder();
if (launcher.isUnix()) {
args.add("/bin/ls");
args.add("-la");
} else {
args.add("dir"); //Windows
}
String homeDir = System.getProperty("user.home");
args.add(homeDir);
try {
int r;
r = launcher.launch().cmds(args).stdout(listener).join();
if (r != 0) {
listener.finished(Result.FAILURE);
return false;
}
} catch (IOException ioe) {
ioe.printStackTrace(listener.fatalError("Execution" + args + "failed"));
listener.finished(Result.FAILURE);
return false;
} catch (InterruptedException ie) {
ie.printStackTrace(listener.fatalError("Execution" + args + "failed"));
listener.finished(Result.FAILURE);
return false;
}
listener.finished(Result.SUCCESS);[ERROR LOG]
Building remotely on LocalVM in workspace /opt/jenkins/workspace/Test
Build Step started by Hello Builder
FATAL: Execution/bin/ls -la /Users/vid401tfailed
java.io.IOException: Remote call on LocalVM failed
at hudson.remoting.Channel.call(Channel.java:723)
at hudson.Launcher$RemoteLauncher.launch(Launcher.java:862)
at hudson.Launcher$ProcStarter.start(Launcher.java:353)
at hudson.Launcher$ProcStarter.join(Launcher.java:360)
at com.owmessaging.testplugin.HelloWorldBuilder.perform(HelloWorldBuilder.java:90)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:780)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:160)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:565)
at hudson.model.Run.execute(Run.java:1592)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:237)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletException
at hudson.Launcher$LocalLauncher.<init>(Launcher.java:755)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:991)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:965)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:326)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException
at hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch(RemoteClassLoader.java:684)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:299)
at hudson.remoting.Request$2.run(Request.java:326)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)