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

查看:37
本文介绍了在 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(Native Method) 在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)

为了确保 Jenkins 正确配置了 git 路径和 ssh 凭据,我创建了另一个作业.该作业只是通过 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天全站免登陆