How to run command in windows batch Command in jenkins

冷暖自知 提交于 2019-12-25 04:06:44

问题


I am trying to run a command in Jenkins under build step of running commands in Execute windows batch command.

I wrote dir to run as a command

and when the job runs in Jenkins which is triggered by a change in content of a file following error is shown

[FSTrigger] Triggered by a change to a file (<a href="triggerCauseAction">log</a>)
Building in workspace C:\Users\Pankaj\.jenkins\jobs\convert File to text form\workspace
FATAL: null
java.util.NoSuchElementException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(Unknown Source)
at java.util.TreeMap$EntryIterator.next(Unknown Source)
at java.util.TreeMap$EntryIterator.next(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.putAll(Unknown Source)
at hudson.EnvVars.<init>(EnvVars.java:82)
at hudson.EnvVars$GetEnvVars.call(EnvVars.java:207)
at hudson.EnvVars$GetEnvVars.call(EnvVars.java:205)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at hudson.EnvVars.getRemote(EnvVars.java:202)
at hudson.model.Computer.getEnvironment(Computer.java:837)
at hudson.model.Run.getEnvironment(Run.java:1883)
at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:836)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:75)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:710)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:480)
at hudson.model.Run.run(Run.java:1434)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:239)

Please see to this issue.


回答1:


I don't think that you need to install Jenkins as a Windows service to execute a batch command as a build step. What might be an issue is that on Windows, commands such as dir are internal to the command interpreter (i.e. cmd.exe). In short, it means that in a Java program you cannot simply run the internal dir command using the java.lang.Runtime.exec("dir") method because there is no such a program as dir.exe (on your PATH). What you should do is execute the command interpreter itself and specify the internal command as a parameter, i.e. java.lang.Runtime.exec("cmd /C dir"). Having that said and being aware that Jenkins is a Java application, it's better to use cmd /C dir instead of just typing dir in Jenkins' job configuration. Internally, Jenkins might use some 3rd pary libraries for executing external processes, such as Apache Commons Exec (see http://commons.apache.org/exec/), which hide the details between internal command(s) and "normal" commands, but from my experience it's not the case for all releases - especially the old ones.




回答2:


Answer to this question: Actually i haven't installed Windows as a service in Jenkins. So for this we need to go to "manage Jenkins" and then click on "windows as a service".I.e Installing Jenkins as a windows service.



来源:https://stackoverflow.com/questions/10697227/how-to-run-command-in-windows-batch-command-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!