指定 Git 工具在多操作系统从属 Jenkins 环境中用于声明式管道 [英] Specify Git Tool to use in Multi-OS Slave Jenkins Environment for Declarative Pipeline

查看:44
本文介绍了指定 Git 工具在多操作系统从属 Jenkins 环境中用于声明式管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Jenkins 还很陌生,但我正在尝试建立一个多操作系统从属环境.Jenkins Master 在 Windows Server 2019 上,我有一个单独的 Windows Server 2019 slave (Laconia) 和一个 Ubuntu 20.04 slave (Java8Europa) 都通过 SSH 成功连接.我还在这两个实例上配置了 Git,并在全局工具配置中创建了两个 Git 工具位置,如下所示,并确认它们在单个机器上工作.

我遇到的问题是,即使我将各个节点设置为使用正确的 Git 工具,如下所示,如果我尝试执行一个简单的声明性管道作业,它也只会使用位于顶部的 Git 实例上面的列表 (WindowsGit).我的声明性管道从一个正确执行的 Windows 脚本开始,但是当它尝试在 Linux 机器上执行 Linux shell 脚本时,它在尝试使用 WindowsGit 时失败.

我将在下面包含控制台日志输出,但无论如何我可以通过 Jenkinsfile 强制每个代理使用哪个 git 工具?我确实读到有一些工具位置被代理忽略,并且有一些文章表明 Git 是其中之一,事实上,如果我将 Git 安装的顺序切换为将 LinuxGit 放在顶部,管道无法运行似乎支持这些文章的 Windows 脚本.我还有什么办法可以解决这个问题?

[Pipeline] withEnv[管道] {[管道] 蝙蝠管理员@LACONIA C:\Jenkins\WorkingRepo\workspace\ReidacusOrg_siplogscanner_main@2>hello.bat管理员@LACONIA C:\Jenkins\WorkingRepo\workspace\ReidacusOrg_siplogscanner_main@2>echo这来自Windows脚本"这是来自 Windows 脚本"[管道] }[管道]//withEnv[管道] }[管道]//节点[管道] }[管道]//阶段[管道]阶段[管道] {(打个招呼)[管道]节点在/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main 中的 Java8(Europa) 上运行[管道] {[管道] 结帐使用凭证 GitHubAPIAccess克隆远程 Git 存储库使用已配置的 refspecs 进行克隆并且不带标签错误:克隆远程 repo 'origin' 时出错hudson.plugins.git.GitException: 无法初始化/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:997)在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:752)在 org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)在 org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:154)在 hudson.remoting.UserRequest.perform(UserRequest.java:211)在 hudson.remoting.UserRequest.perform(UserRequest.java:54)在 hudson.remoting.Request$2.run(Request.java:376)在 hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)在 java.util.concurrent.FutureTask.run(FutureTask.java:266)在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)在 java.lang.Thread.run(Thread.java:748)抑制:hudson.remoting.Channel$CallSiteStackTrace:远程调用 Java8(欧洲)在 hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1800)在 hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)在 hudson.remoting.Channel.call(Channel.java:1001)在 org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)在 jdk.internal.reflect.GeneratedMethodAccessor882.invoke(未知来源)在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.base/java.lang.reflect.Method.invoke(Method.java:566)在 org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)在 com.sun.proxy.$Proxy96.execute(来源不明)在 hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1221)在 hudson.plugins.git.GitSCM.checkout(GitSCM.java:1299)在 org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)在 org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)在 org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)在 org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)在 java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)在 java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)在 java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)在 java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)在 java.base/java.lang.Thread.run(Thread.java:834)引起:hudson.plugins.git.GitException:执行 git 命令时出错:C:\Git\bin\git.exe"init/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2457)在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2380)在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2376)在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1923)在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:995)……还有 11 个引起:java.io.IOException:无法运行程序C:\Git\bin\git.exe"(在目录/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main"中):错误=2,没有那个文件或目录在 java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)在 hudson.Proc$LocalProc.(Proc.java:252)在 hudson.Proc$LocalProc.(Proc.java:221)在 hudson.Launcher$LocalLauncher.launch(Launcher.java:996)在 hudson.Launcher$ProcStarter.start(Launcher.java:508)在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2443)……还有 15 个引起:java.io.IOException: error=2, No such file or directory在 java.lang.UNIXProcess.forkAndExec(本机方法)在 java.lang.UNIXProcess.(UNIXProcess.java:247)在 java.lang.ProcessImpl.start(ProcessImpl.java:134)在 java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)……还有 20 个[管道] }[管道]//节点[管道] }[管道]//阶段[管道]阶段[管道] {(说再见)舞台Say Bye"由于较早的失败而跳过[管道] }[管道]//阶段[管道] }[管道]//withEnv[管道] }[管道]//节点[管道] 管道结束克隆仓库 https://github.com/reidacus/siplogscanner.gitC:\Git\bin\git.exe"init/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main #超时=10GitHub 已收到此提交的构建结果的通知错误:克隆远程 repo 'origin' 时出错**完成:失败

提前致谢.

解决方案

不要使用指定 2 个 git 配置的方法.否则,你必须改变每一份工作.只需进行一项配置并在代理/节点级别覆盖工具位置.仅在变体重要的地方指定不同的工具.在您的

节点配置

工具选择器旨在选择各种工具(jdk ver、openjdk 与 oraclejdk 等).您可以在节点级别覆盖工具位置.我的完整示例是 JDK,因为版本很重要,但 win/linux 位置也不同.Git 就是 git.

I'm fairly new to Jenkins but I'm trying to set up a Multi OS Slave environment. Jenkins Master is on Windows Server 2019, and I have a separate Windows Server 2019 slave (Laconia) and an Ubuntu 20.04 slave (Java8Europa) both successfully connected via SSH. I've also configured Git on both instances and I have created two Git tool locations in the global tools config as shown below and confirmed that these work on the individual machines.

The problem I have is that even if I set the individual nodes to use the correct Git tool as shown below, if I try to execute a simple declarative pipeline job, it will only ever use the Git instance which is at the top of the list above (WindowsGit). My declarative pipeline starts with a Windows Script which executes correctly but then when it tries to execute the Linux shell script on the Linux box, it fails as it attempts to use WindowsGit.

I'll include the console log output below, but is there anyway how I can force via the Jenkinsfile which git tool should be used per agent? I did read that there are some tool locations which are ignored by the agents and there are some articles which suggest Git is one of these and the fact that if I switch the order of the Git installations to have the LinuxGit at the top, the pipeline fails to run the Windows script which would seem to support those articles. Any other way I can get around this?

[Pipeline] withEnv
[Pipeline] {
[Pipeline] bat
administrator@LACONIA C:\Jenkins\WorkingRepo\workspace\ReidacusOrg_siplogscanner_main@2>hello.bat
administrator@LACONIA C:\Jenkins\WorkingRepo\workspace\ReidacusOrg_siplogscanner_main@2>echo "This   is coming from a Windows Script" 
"This is coming from a Windows Script"
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Say Hello)
[Pipeline] node
Running on Java8(Europa) in /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main
[Pipeline] {
[Pipeline] checkout
using credential GitHubAPIAccess
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:997)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:752)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:154)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:376)
at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to Java8(Europa)
    at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1800)
    at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
    at hudson.remoting.Channel.call(Channel.java:1001)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
    at jdk.internal.reflect.GeneratedMethodAccessor882.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
    at com.sun.proxy.$Proxy96.execute(Unknown Source)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1221)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1299)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: hudson.plugins.git.GitException: Error performing git command: "C:\Git\bin\git.exe" init /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2457)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2380)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2376)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1923)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:995)
... 11 more
Caused by: java.io.IOException: Cannot run program ""C:\Git\bin\git.exe"" (in directory "/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
at hudson.Launcher$ProcStarter.start(Launcher.java:508)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2443)
... 15 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 20 more
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Say Bye)
Stage "Say Bye" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Cloning repository https://github.com/reidacus/siplogscanner.git 
"C:\Git\bin\git.exe" init /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main # 
timeout=10
GitHub has been notified of this commit’s build result
ERROR: Error cloning remote repo 'origin'**
Finished: FAILURE

Thanks in advance.

解决方案

Do not use the approach of specifying 2 git configurations. Otherwise, you have to change every job. Just have one configuration and override the tool location at the agent/ node level. Only specify different tools where the variant matters. In your pipeline you'd reference :

tools {
    jdk 'jdk1.8' 
}

Global configuration

Node Configuration

The Tools selector is intended to choose flavors of tools (jdk ver, openjdk vs oraclejdk, etc.). You override the tool location at the node level. My complete example was JDK, since versions matter, but also win/linux location differ. Git is just git.

这篇关于指定 Git 工具在多操作系统从属 Jenkins 环境中用于声明式管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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