来自 GitHub 的 Jenkins FreeStyle 项目给出“致命:不在 git 目录中”错误

Azi*_*iev 6 github jenkins

我已经尝试了三天来寻找解决方案,但没有成功。管道类型工作成功,自由式工作失败。我注意到每次尝试后,在 HEAD 文件 .git 中都写了“ref: refs/heads/master”,甚至我也指出了 */main。

在此输入图像描述

Running as SYSTEM
    Building in workspace C:\Users\aziz\.jenkins\workspace\workflow
    The recommended git tool is: NONE
    using credential 605f1b8b-aff7-457a-8040-edf8d6dae69a
     > C:\Program Files\Git\bin\git.exe rev-parse --resolve-git-dir C:\Users\aziz\.jenkins\workspace\workflow\.git # timeout=10
    Fetching changes from the remote Git repository
     > C:\Program Files\Git\bin\git.exe config remote.origin.url https://github.com/azimkar87/Billing.git # timeout=10
    ERROR: Error fetching remote repo 'origin'
    hudson.plugins.git.GitException: Failed to fetch from https://github.com/azimkar87/Billing.git
        at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1003)
        at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1244)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1308)
        at hudson.scm.SCM.checkout(SCM.java:540)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1217)
        at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:647)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:519)
        at hudson.model.Run.execute(Run.java:1897)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
        at hudson.model.ResourceController.execute(ResourceController.java:101)
        at hudson.model.Executor.run(Executor.java:442)
    Caused by: hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe config remote.origin.url https://github.com/azimkar87/Billing.git" returned status code 128:
    stdout: 
    stderr: fatal: not in a git directory
    
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2601)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2597)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1968)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1980)
        at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setRemoteUrl(CliGitAPIImpl.java:1594)
        at hudson.plugins.git.GitAPI.setRemoteUrl(GitAPI.java:161)
        at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:991)
        ... 11 more
    ERROR: Error fetching remote repo 'origin'
    [Checks API] No suitable checks publisher found.
    Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

Seb*_*ian 5

  1. 检查是否添加了 ssh 密钥。
  2. 执行以下命令,

cd /var/jenkins_home
git config --global --add safe.directory '*'

  1. 使用选项“在构建开始之前删除工作区”删除工作区
  2. 运行 Jenkins 作业


Fra*_*rot 1

也许您遇到这里描述的问题(https://community.jenkins.io/t/upgrading-git-on-jenkins-master-causing-failures-for-multibranch-pipelines/3247)并且升级 git 可以解决问题。