0

我有一个 Jenkins 大师,有两个构建代理,其中一个是 Windows 机器,另一个是 Mac。以下 Jenkinsfile 尝试从Github Enterprise服务器签出 git 存储库。

properties([
    parameters([
        string(
            name: 'GIT_URL',
            defaultValue: params.GIT_URL?:'https://github.com/',
            description: 'URL to clone the Git repo.'
        ),
        string(
            name: params.GIT_SELECTOR?:'GIT_SELECTOR',
            defaultValue: params.GIT_SELECTOR?:'refs/heads/master',
            description: 'Branch, tag or commit.'
        ),
        [
            $class: 'CredentialsParameterDefinition',
            name: 'GIT_CREDENTIALS',
            credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
            defaultValue: params.GIT_CREDENTIALS?:'',
            description: 'User and password to clone the Git repository',
            required: true
        ]
    ])
])

node('build'){

    stage('Clean'){
        cleanDir()
        sh('''
            pwd
            ls -la
        ''')
    }

    stage('Identify host'){
        def host = command("hostname")
        def hostOS = isUnix()?'mac':'win'
        currentBuild.description = " ${hostOS}-host"
    }

    stage('Check out'){
        checkout([
            $class: 'GitSCM',
            branches: [
                [name: params.GIT_SELECTOR]
            ],
            extensions: [
                [
                    $class: 'RelativeTargetDirectory',
                    relativeTargetDir: 'app'
                ]
            ],
            userRemoteConfigs: [
                [
                    credentialsId: params.GIT_CREDENTIALS,
                    url: GIT_URL
                ]
            ]
        ])
    }
}

当构建进入 Windows 框时它会成功,但它最近开始在 Mac 上无缘无故地失败。我得到的错误是:

Cloning the remote Git repository
Cloning repository https://github.acme.com/Acme/foo-project.git
 > git init /Jenkins/workspace/.tests/test-checkout/app # timeout=10
Fetching upstream changes from https://github.acme.com/Acme/foo-project.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials my-git-credentials
 > git fetch --tags --progress https://github.acme.com/Acme/foo-project.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress https://github.acme.com/Acme/foo-project.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Your account is suspended. Please check with your installation administrator.
fatal: unable to access 'https://github.acme.com/Acme/foo-project.git/': The requested URL returned error: 403

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1877)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1596)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:348)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:545)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
    at hudson.remoting.UserRequest.perform(UserRequest.java:153)
    at hudson.remoting.UserRequest.perform(UserRequest.java:50)
    at hudson.remoting.Request$2.run(Request.java:332)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at hudson.remoting.Engine$1$1.run(Engine.java:85)
    at java.lang.Thread.run(Thread.java:745)
    at ......remote call to Channel to /208.83.1.25(Native Method)
    at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1545)
    at hudson.remoting.UserResponse.retrieve(UserRequest.java:253)
    at hudson.remoting.Channel.call(Channel.java:830)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
    at sun.reflect.GeneratedMethodAccessor1126.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
    at com.sun.proxy.$Proxy75.execute(Unknown Source)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1067)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1107)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:83)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:73)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
    at hudson.security.ACL.impersonate(ACL.java:260)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

请注意有关消息GitExceptiongit fetch错误的信息status code 128The requested URL returned error: 403。当然,因为它确实可以在 Windows 机器上运行,所以我知道它绝对不是凭据。这可能是什么原因?我应该看什么?

编辑:我尝试从两个从属设备上使用 Github API,curl -X GET https://github.acme.com/api/v3/user -H 'Authorization: token *****...****'在 Windows 机器上运行良好,在 Mac 上我得到:

{
    "message": "Must authenticate to access this API.",
    "documentation_url": "https://developer.github.com/enterprise/2.11/v3"
}
4

2 回答 2

1

您可以尝试以下几件事:

  • 您的 GitHub 企业实例将具有详细说明身份验证失败的日志。询问您的管理员,因为他们可能会立即得到答案。

  • 如果您有权对您的用户执行此操作,请尝试使用基本身份验证(例如https://github.acme.com/api/v3/user)从问题框中点击 GitHub REST API 的经过身份验证的端点 - 如果这也因 403 失败,您应该获得一些有关其原因的信息响应正文和标头。

于 2018-04-07T08:29:50.970 回答
0

经过多次故障排除后,我们发现解决此问题的唯一方法是硬重启 Mac 构建代理。弹回盒子后,发送给它的所有作业都可以再次访问 Git 服务器。

我一直无法找到发生这种情况的原因,所以这是迄今为止最好的答案。如果有人对可能导致这种行为的原因有任何建议,我倾向于将其标记为答案而不是这个。

于 2018-08-07T10:39:39.943 回答