简体   繁体   English

Jenkins Poll SCM(Git)在Windows master / Build on Linux slave上

[英]Jenkins Poll SCM (Git) on Windows master / Build on Linux slave

Here is my scenario: 这是我的场景:

  • Using git as my SCM 使用git作为我的SCM
  • Jenkins Job runs on Linux slave Jenkins Job在Linux slave上运行
  • Jenkins master is hosted on Windows Jenkins master托管在Windows上

I have configured two Git installations as indicated in Jenkins path to git Windows master / Linux slave . 我已经配置了两个Git安装,如Jenkins路径中指示的那样, 用于git Windows master / Linux slave Git installations are set up as follows: Git安装设置如下:

  • Name: WindowsGit | 名称: WindowsGit | Path: C:\\Program Files\\Git\\bin\\git.exe 路径: C:\\Program Files\\Git\\bin\\git.exe
  • Name: LinuxGit | 名称: LinuxGit | Path: /usr/local/bin/git 路径: /usr/local/bin/git

Because I need to run the job on linux slave, my job git configuration is pointing to LinuxGit (Git executable option). 因为我需要在linux slave上运行作业,我的作业git配置指向LinuxGit(Git可执行选项)。 Job runs great, no problems. 工作运行良好,没有问题。 However, when I try to use "Poll SCM" option, it breaks. 但是,当我尝试使用“Poll SCM”选项时,它会中断。 I believe the problem here is because Poll SCM runs on the Windows Master and the Git information for this job is pointing to LinuxGit. 我相信这里的问题是因为Poll SCM在Windows Master上运行,而这项工作的Git信息指向LinuxGit。 Git Polling Log shows: Git Polling Log显示:

Caused by: java.io.IOException: Cannot run program "/usr/local/bin/git": CreateProcess error=2, The system cannot find the file specified

In the other hand, if I select WindowsGit, Git Polling Log is fine but job itself will obviously fail because it's running on a Linux Slave. 另一方面,如果我选择WindowsGit,Git Polling Log就可以了,但是作业本身显然会失败,因为它在Linux Slave上运行。

Question: Can anyone think about a way I can select one Git installation for the Source Code Management configuration and another one for the Poll SCM feature? 问题:有人可以考虑一种方法,我可以为源代码管理配置选择一个Git安装,为Poll SCM功能选择另一个吗?

As requested, I'm posting my own answer to the general idea, for mixing Windows/Linux on Master Slaves when working with git. 根据要求,我发布了自己的一般想法的答案,在使用git时在Master Slaves上混合使用Windows / Linux。 This solution will allow even to run the same job on multiple mix of Windows/Linux slaves as well as won't break Master polling scm: 这个解决方案甚至允许在多个Windows / Linux从属组合上运行相同的工作,也不会破坏Master轮询scm:

Whatever you Jenkins Master platform is, configure the default git installation to point to a valid git for that platform. 无论您使用Jenkins Master平台,都要将默认git安装配置为指向该平台的有效git。 For example, c:\\apps\\git\\bin\\git.exe for Windows. 例如,Windows的c:\\apps\\git\\bin\\git.exe and then configure the custom " Tool Locations " for each node. 然后为每个节点配置自定义“ 工具位置 ”。 This way the master will be able to poll git to check for changes and trigger the job on a slave. 通过这种方式,主设备将能够轮询git以检查更改并在从设备上触发作业。 The Slave will then be capable to clone the git code because it has its custom location for (Git) Default . 然后Slave将能够克隆git代码,因为它具有(Git)Default的自定义位置。 Steps to configure properly: 正确配置的步骤:

  1. Manage Jenkins > Manage Nodes 管理Jenkins>管理节点
  2. For each node having git location other than the one provided in the "Git installation", do: 对于具有除“Git安装”中提供的git位置之外的git位置的每个节点,执行:
    1. Open node configuration page (Configure icon) 开放节点配置页面(配置图标)
    2. Check "Tool Locations" if not already checked 如果尚未选中,请选中“工具位置”
    3. Click "Add" 点击“添加”
    4. Select "(Git) Default" on the dropdown 在下拉列表中选择“(Git)Default”
    5. Enter the path to the slave node git installation (eg /usr/local/bin/git ) 输入从节点git安装的路径(例如/usr/local/bin/git
    6. Save
  3. Repeat steps 2.1 to 2.5 for each Linux slave the job may run. 对作业可能运行的每个Linux从站重复步骤2.1到2.5。

Node configuration for the linux slave node should look something like this: linux从属节点的节点配置应如下所示:

从节点配置

I believe the additional "git installations" are more suitable, as @Jayan mentioned, when you need to have multiple git installations or you need to run, for some reason, a specific version of git for select Jenkins jobs. 我相信额外的“git安装”更合适,正如@Jayan所提到的,当你需要多个git安装或者你需要为某些Jenkins作业运行特定版本的git时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM