【问题标题】:Copying files between jenkins slaves In pipeline在詹金斯奴隶之间复制文件在管道中
【发布时间】:2020-05-05 02:37:34
【问题描述】:

我们的目标是用多个代理划分我们的管道。

我们有一个叫 slave1 的奴隶,它的唯一目的是在 git 上结帐, 并构建可执行文件。

最终当 slave1 完成时,我们想将它的输出传递给 slave2, 它的唯一目的是测试 slave1 的可执行文件。

请注意,这里的想法不是拆分工作,而是实现 同一管道中的文件。

这是一个更有意义的Jenkinsfile 示例:

pipeline
{
    agent
    {
        label 'slave1'
    }
    stages
    {
        stage("Initialize & Build")
        {
            steps
            {
                script
                {
                    println("Im starting the pipeline with slave1!")

                    // Builds Files
                    // ....

                    // Has many files that needs to pass to slave2
                }
            }
        }
        stage("Execute & Test")
        {
            agent
            {
                label 'slave2'
            }
            steps
            {
                script
                {
                    println("Im in the new slave - slave2!")

                    // How does this slave get the files?
                }
            }
        }
    }
}

如何在代理之间传递这些文件?

我阅读了有关工件的信息,但它的目标似乎是从作业中返回对象,这不一定是需要的。

【问题讨论】:

    标签: jenkins jenkins-pipeline jenkins-groovy


    【解决方案1】:

    如果您的两个代理都在 linux 服务器上,您可以简单地将代理 1 的构建输出 scp 到代理 2。 此外,首先您需要在这 2 个代理之间建立无密码 SSH 连接。

    这是一个例子。

    pipeline
    {
        agent
        {
            label 'slave1'
        }
        stages
        {
            stage("Initialize & Build")
            {
                steps
                {
                    script
                    {
                        println("Im starting the pipeline with slave1!")
    
                        // Builds Files
                        // ....
     // option 1: copy files in the workspace of agent 2.
                        scp $WORKSPACE/build_output/* <user>@agent2:/home/<user>/workspace/<job_name>/
    // option 2: copy files to any known location of agent 2
                         scp $WORKSPACE/build_output/* <user>@agent2:/<destination_path>
    
    
    
                    }
                }
            }
            stage("Execute & Test")
            {
                agent
                {
                    label 'slave2'
                }
                steps
                {
                    script
                    {
                        println("Im in the new slave - slave2!")
    
                        //option 1
                             dir($WORKSPACE) {
                                   // Test execution steps
                       }
                         // option 2
                              dir(<destination_path>) {
                                  // Test execution steps
                       }
                    }
                }
            }
        }
    }
    

    【讨论】:

    • 这不是一个好主意,因为它不可扩展。此更改的全部目的是在代理之间进行划分,以使管道的某些部分独立 =) 但感谢您的想法!
    • 您可以尝试的另一个选项是有一个公共位置,例如两个代理都可以访问并在那里转储构建输出的安装位置。只是一个想法!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 2018-08-02
    相关资源
    最近更新 更多