【问题标题】:Jenkins git checkout on agent not workingJenkins git checkout 代理不工作
【发布时间】:2020-05-22 10:36:07
【问题描述】:

我的 github 存储库中的 Jenkins 文件用于 Jenkins 主/从环境。 我需要在远程 Jenkins 从服务器上执行测试命令。 在我的声明式管道中,代理的调用方式如下:

stage("Testautomation") {
  agent { label 'test-device' }
    steps {
        bat '''
        @ECHO ON
        ECHO %WORKSPACE%
        ... '''
    }
}

在 Jenkins 甚至可以执行远程命令之前,它就开始从版本控制中检出。 Jenkins Master 上的结帐没有问题并且工作正常。但是在这个 Jenkins Slave 上,我总是收到这个错误消息。

using credential github-enterprise:...
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://...git # timeout=10
Fetching upstream changes from https://...git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials GitHub Enterprise Access Token
 > git fetch --tags --force --progress --depth=1 -- https://...git +refs/heads/development:refs/remotes/origin/development # timeout=120
Checking out Revision ... (development)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f ...
Could not checkout ...

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    默认情况下,声明式管道对每个代理执行 SCM 签出。检查 Jenkins slave 上是否安装了 Git。

    相反,如果您希望代码在 master 而不是在代理上签出,请禁用 options 指令中的默认签出并在阶段内使用 scm checkout 步骤。

    pipeline {
        agent { label 'master' }
        options {
            skipDefaultCheckout(true)
        }
        stages {
            stage('Build') {
                steps {
                    checkout scm
                    // do other stuff on master
                }
            }
            stage("Testautomation") {
                agent { label 'test-device' }
                steps {
                    bat '''
                        @ECHO ON
                        ECHO %WORKSPACE%
                    '''
                }
            }
        }
    }
    

    您可以按照此答案https://stackoverflow.com/a/42293620/8895640 中的描述进一步自定义结帐行为。

    【讨论】:

    • 如果我禁用默认的 scm 签出,是一个阶段的变化检测,例如when { expression { return hasChanges('test/') } } 还在工作吗?
    • 是的,应该不会有影响。
    猜你喜欢
    • 2013-07-12
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 2018-04-17
    相关资源
    最近更新 更多