Hi,
I would like to run a Windows command inside my Jenkins Plugin.
How can I achieve that?
The following code is not working:
@Override
public void perform(Run<?,?> build, FilePath workspace, Launcher launcher, TaskListener listener) {
try {
Launcher.ProcStarter procStarter=launcher.launch().pwd(workspace).cmdAsSingleString("dir " + workspace + " && attrib -R /S");procStarter= procStarter.stdout(listener);
procStarter.join();
} catch (IOException e) {
e.printStackTrace();
listener.getLogger().println("IOException !");
} catch (InterruptedException e) {
e.printStackTrace();
listener.getLogger().println("InterruptedException!");
}
}
I get the following error when I run a Job that uses this plugin:
java.io.IOException: Cannot run program "dir" (in directory "C:\LocalJenkins\plu
gins\michaelPlugin\work\jobs\buildTest\workspace"): CreateProcess error=2, The s
ystem cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.Launcher$ProcStarter.join(Launcher.java:389)
at michaelPlugin.michaelPlugin.HelloWorldBuilder.perform(HelloWorldBuild
er.java:110)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibili
tyLayer.java:75)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBui
ld.java:785)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.j
ava:537)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:408)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
e file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 16 more
Jul 19, 2016 8:51:12 AM hudson.model.Run execute
INFO: buildTest #52 main build action completed: SUCCESS
What should be the correct code to run some Windows commands?
Many thanks