在Jenkins Git插件中指定git命令 [英] Specify git commands in Jenkins Git plugin

查看:622
本文介绍了在Jenkins Git插件中指定git命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下ant目标,以便从GitHub存储库中获取代码.

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>

在命令提示符下运行目标时,目标运行正常.但是,当我尝试从Jenkins运行它时,它失败并显示以下错误:

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:

构建失败C:\ Users \ PJai12 \ test \ build.xml:66:执行失败: java.io.IOException:无法运行程序"git":CreateProcess错误= 2, 系统找不到在以下位置指定的文件 java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)在 java.lang.Runtime.exec(Runtime.java:620)在 org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58) 在org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:428)处 org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:442)在 org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:629) 在org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:670) 在org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:496) 在 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)在 org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 在org.apache.tools.ant.Task.perform(Task.java:348)处 org.apache.tools.ant.Target.execute(Target.java:435)在 org.apache.tools.ant.Target.performTasks(Target.java:456)在 org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405) 在org.apache.tools.ant.Project.executeTarget(Project.java:1376)处 org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 在org.apache.tools.ant.Project.executeTargets(Project.java:1260)处 org.apache.tools.ant.Main.runBuild(Main.java:853)在 org.apache.tools.ant.Main.startAnt(Main.java:235)在 org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)在 org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

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)

为了确保使用git path和ssh credentails正确配置了Jenkins,我创建了anothe作业.这项工作只需通过Jenkins GitHub插件从同一存储库中轮询scm.工作正常.

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.

这是詹金斯(Jenkins)中的GIT配置: https://imgur.com/a/noFJ9M4

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

推荐答案

可执行文件应具有Git可执行文件的完整路径.

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">

这篇关于在Jenkins Git插件中指定git命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆