Jenkins Pipeline 无法初始化仓库(Windows 控制器,Mac 代理)

huangapple go评论101阅读模式
英文:

Jenkins Pipeline couldn't init the repo (Windows controller, Mac agent)

问题

I'm here to provide you with the translated content. Here is the translation of the provided text:

我有一台运行Windows的Jenkins控制机器和一台运行MacOS的代理机器。两台机器都安装了git。
如果我在我的Mac终端中键入`where git`,我会得到这个输出:`/usr/bin/git`。

**我的目标是:** 我试图将'team-ci'存储库检出到Pipeline项目的工作空间中。

问题在于,如果我使用以下方式进行操作
```java
git branch: 'main',
        credentialsId: "defaultssh",
        url: "git@global.com:team/team-ci.git"

, 那么它会尝试使用Windows可执行文件来检出'main'分支,因此,我选择了checkout方法。

这是“全局工具配置”中的“Git安装”是什么样子的:

Jenkins Pipeline 无法初始化仓库(Windows 控制器,Mac 代理)

我编写了这个流水线代码:

pipeline {
    agent {
        label 'mac1'
    }
    stages {
        stage('执行') {
            steps {
                script {
                    def branch = '*/main'
                    def credentialsId = 'defaultssh'
                    def projectUrl = "git@global.company.gitlab.com:team/team-ci.git"
                    def gitTool = isUnix() ? 'git_mac' : 'git_win'
                    echo "gitTool: " + gitTool
                    checkout([$class: 'GitSCM', branches: [[name: branch]],
                                gitTool: gitTool, 
                                userRemoteConfigs: [[credentialsId: credentialsId, url: projectUrl]]
                            ])
                }
            }
        }
    }
}

当我尝试运行此Pipeline项目时,在控制台中输出以下异常信息:

13:14:19  gitTool: git_mac
13:14:19  [Pipeline] checkout
13:14:19  推荐的git工具是:无
13:14:19  使用凭据defaultssh
13:14:19  克隆远程Git存储库时出错
13:14:19  错误:无法初始化/Library/Automation/jenkins/workspace/mac_pipeline_project的远程存储库
13:14:19  由于:无法执行git命令:/usr/bin/git init /Library/Automation/jenkins/workspace/mac_pipeline_project
13:14:19  由于:java.io.IOException:无法运行程序“/Library/Automation/jenkins/workspace/”(位于“/Library/Automation/jenkins/workspace/mac_pipeline_project”):错误=13,权限被拒绝
13:35:19  由于:java.io.IOException:错误=13,权限被拒绝
13:35:20  克隆远程Git存储库时出错

我应该怎么做才能成功克隆'team-ci'项目?


If you need any further assistance, feel free to ask.

<details>
<summary>英文:</summary>

I have a Jenkins controller machine that runs Windows and an agent machine that runs on MacOS. Both machines have git installed.
If I type `where git` in my Mac&#39;s terminal, I get this output: `/usr/bin/git`.

**My goal is:** I&#39;m trying to check out the &#39;team-ci&#39; repo into the workspace of the Pipeline Project. 

The issue is that if I do it using
```java
git branch: &#39;main&#39;,
        credentialsId: &quot;defaultssh&quot;,
        url: &quot;git@global.com:team/team-ci.git&quot;

, then it tries to check out the 'main' branch using the Windows executable, so instead, I opted out for the checkout method.

Here's what the "Git installations" in "Global Tool Configuration" look like:

Jenkins Pipeline 无法初始化仓库(Windows 控制器,Mac 代理)

I wrote this pipeline code:

pipeline {
    agent {
        label &#39;mac1&#39;
    }
    stages {
        stage(&#39;Execute&#39;) {
            steps {
                script {
                    def branch = &#39;*/main&#39;
                    def credentialsId = &#39;defaultssh&#39;
                    def projectUrl = &quot;git@global.company.gitlab.com:team/team-ci.git&quot;
                    def gitTool = isUnix() ? &#39;git_mac&#39; : &#39;git_win&#39;
                    echo &quot;gitTool: &quot; + gitTool
                    checkout([$class: &#39;GitSCM&#39;, branches: [[name: branch]],
                                gitTool: gitTool, 
                                userRemoteConfigs: [[credentialsId: credentialsId, url: projectUrl]]
                            ])
                }
            }
        }
    }
}

When I try to run this Pipeline Project, it outputs these exceptions in the console:

13:14:19  gitTool: git_mac
13:14:19  [Pipeline] checkout
13:14:19  The recommended git tool is: NONE
13:14:19  using credential defaultssh
13:14:19  Cloning the remote Git repository
13:14:19  ERROR: Error cloning remote repo &#39;origin&#39;
13:14:19  hudson.plugins.git.GitException: Could not init /Library/Automation/jenkins/workspace/mac_pipeline_project
13:14:19  Caused by: hudson.plugins.git.GitException: Error performing git command: /usr/bin/git init /Library/Automation/jenkins/workspace/mac_pipeline_project
13:14:19  Caused by: java.io.IOException: Cannot run program &quot;/Library/Automation/jenkins/workspace/&quot; (in directory &quot;/Library/Automation/jenkins/workspace/mac_pipeline_project&quot;): error=13, Permission denied
13:35:19  Caused by: java.io.IOException: error=13, Permission denied
13:35:20  ERROR: Error cloning remote repo &#39;origin&#39;

What can I do to successfully clone the 'team-ci' project?

答案1

得分: 1

我必须前往“仪表板/管理 Jenkins/节点/mac1”,并将“工具位置”值从“/Library/Automation/jenkins/workspace/”更改为“(Git) git_mac” 工具下的“/usr/bin/git”。

英文:

I had to go to the Dashboard/Manage Jenkins/Nodes/mac1 and change the "Tool locations" value from "/Library/Automation/jenkins/workspace/" to "/usr/bin/git" under the "(Git) git_mac" tool.

huangapple
  • 本文由 发表于 2023年6月8日 01:50:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定