Specify git commands in Jenkins Git plugin

微笑、不失礼 提交于 2020-01-06 02:15:12

问题


I have written following ant target to fetch code from a GitHub repository.

<target name="fetch" description="Fetching the Source Code">
  <echo message="-------------------------------------------------------------"/>
  <echo message="Fetching Latest from ${build.git.organization}/${build.git.repository} ${build.git.branch}"/>  
  <echo message="-------------------------------------------------------------"/>
  <exec executable="git" dir="${build.source.location}\${build.git.repository}" failonerror="true">
      <arg line="fetch ${build.git.organization}/${build.git.repository} ${build.git.branch}"/>
  </exec>
</target>

The target works fine when I run it from the command prompt. However, when I try to run it from Jenkins, it fails with the following error:

BUILD FAILED C:\Users\PJai12\test\build.xml:66: Execute failed: java.io.IOException: Cannot run program "git": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620) at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58) at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:428) at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:442) at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:629) at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:670) at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:496) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405) at org.apache.tools.ant.Project.executeTarget(Project.java:1376) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1260) at org.apache.tools.ant.Main.runBuild(Main.java:853) at org.apache.tools.ant.Main.startAnt(Main.java:235) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

In order to make sure that the Jenkins is properly configured with git path and ssh credentails, I created anothe job. The job just poll scm from the same repository through Jenkins GitHub plugin. It worked fine.

Here is the GIT configuration in Jenkins: https://imgur.com/a/noFJ9M4


回答1:


The executable should have a complete path of Git executable.

<exec executable="PATH_TO_GIT_EXE" dir="${build.source.location}\${build.git.repository}" failonerror="true">


来源:https://stackoverflow.com/questions/54300414/specify-git-commands-in-jenkins-git-plugin

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