不希望 Jenkins Slave 克隆存储库?

问题描述 投票:0回答:1

我的系统设置为 Docker Linux PC Master/BeagleBone Linux Slave,通过 USB SSH 连接。

本质上,我正在尝试执行以下操作:

  • 在从 Bitbucket 存储库获取的 master 上编译代码。
  • 获取已编译的二进制文件并将其传输到 BeagleBone(我在 Jenkinsfile 中使用“stash”和“unstash”来执行此操作)
  • 使用 BeagleBone 从设备上的二进制文件来刷新连接到它的另一个设备(从设备,而不是主设备)

当我从 Jenkins 构建时,我的主人克隆存储库,构建代码并存储二进制文件。但是,当我转移到从属设备上的“闪存”阶段时,它尝试克隆存储库(由于凭据问题而失败 - 这是一个单独的问题)。我不希望它这样做 - 相反,我希望它只获取新存储的文件并使用它来刷新附加的硬件,而不是在存储库中查找它。

我似乎找不到阻止这种情况发生的选项。我可以做什么来只使用隐藏的文件?如果无法通过存储来实现,是否可以通过其他方式完成而不需要从站尝试克隆存储库?

这是我的 Jenkinsfile:

pipeline { 
    agent none
    stages {
        stage('Build') {
            agent {
                label 'master'
            }
            steps {
                sh 'cd application/.../example && make'
                stash includes: 'application/.../example/example.bin', name: 'Flash'
            }
        }

        stage('Test of Flash') {
            agent {
                 label 'test_slave'
            }
            steps {
              unstash 'Flash'
              //Flashing step here
              sh 'make check || true'
            }
        }
    }
}

这是控制台日志,从主编译开始:

obtained Jenkinsfile from 913...
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] node
Running on Jenkins in /var/jenkins_home/...
[Pipeline] {
[Pipeline] checkout
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository [email protected]:...

//Later, the file compiles:
Generating binary and Printing size information:...
//Compiles, then:
[Pipeline] stash
Stashed 1 file(s)
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test of Flash)
[Pipeline] node
Running on test_slave in /home/debian/...
[Pipeline] {
[Pipeline] checkout  //And it starts to clone the repo here!
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository [email protected]:...

我不希望它执行上述操作。

linux jenkins bitbucket beagleboneblack jenkins-agent
1个回答
5
投票

显然,同样的问题以不同的形式发布在这里:https://devops.stackexchange.com/questions/650/set-a-jenkins-job-to-not-to-clone-the-repo-in -scm/1074

无论如何,具体做法如下:您需要在第一个代理之后添加一个名为

options { skipDefaultCheckout() }
的选项,这样一般情况下,它就不会轮询 scm(因为检查 git 的命令是 checkout scm. )

然后,在您确实想要检查 git 的阶段,输入

checkout scm
作为步骤。

这是新的 Jenkinsfile:

pipeline { 
    agent none
    options { skipDefaultCheckout() }  //THIS ONE
    stages {
        stage('Build') {
            agent {
                label 'master'
            }
            steps {
                checkout scm  //AND THIS ONE
                sh 'cd application/...
            }
        }
        stage('Test of Flash') {
            agent {
                label 'test_slave'
            }
            steps {
              sh 'cd application/...
              sh 'make check || true'
            }
        }
    }
}

(事实上,存储是不必要的。)

© www.soinside.com 2019 - 2024. All rights reserved.