1

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://i.sstatic.net/rSd67.jpg

2
  • First, you cannot modify git commands flow much without forking plugin you're using. Second, git-scm.com/book/en/v2/Git-Internals-The-Refspec. You might achieve that with more complicated setup (i.e. using scripted pipelines or external scripts to call git subcommands) to alter basic Jenkins job routine Commented Jan 22, 2019 at 2:39
  • Updated my question. Commented Jan 22, 2019 at 3:22

1 Answer 1

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">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.