繁体   English   中英

指定 Git 工具在多操作系统从站 Jenkins 环境中用于声明性管道

[英]Specify Git Tool to use in Multi-OS Slave Jenkins Environment for Declarative Pipeline

我对 Jenkins 相当陌生,但我正在尝试设置一个多操作系统从属环境。 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. 我还在两个实例上配置了 Git 并且我在全局工具配置中创建了两个 Git 工具位置,如下所示,并确认这些工具可以在各个机器上工作。

Git 工具位置

我遇到的问题是,即使我将各个节点设置为使用正确的 Git 工具,如下所示,如果我尝试执行一个简单的声明性管道作业,它也只会使用列表顶部的 Git 实例以上(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.

Java8Europa 工具位置

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

[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

提前致谢。

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

tools {
    jdk 'jdk1.8' 
}

全局配置全局工具配置

节点配置代理配置

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

暂无
暂无

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

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