简体   繁体   English

如何将文件传递给 Jenkins 中的下游作业

[英]How to Pass Files to downstream Job in Jenkins

I am trying to pass a zip file of a build down to another job that runs the end to end tests.我正在尝试将构建的 zip 文件传递给另一个运行端到端测试的作业。 It would usually use the build artifacts from the main job, but I want to add the end to end tests as part of the build pipeline.它通常会使用主要作业中的构建工件,但我想将端到端测试添加为构建管道的一部分。 I tried using the file parameter in Jenkins but the file never showed up and I believe there's some outstanding issues preventing it from working.我尝试在 Jenkins 中使用文件参数,但该文件从未出现过,我相信有一些突出的问题阻止它工作。 Is there a way I can pass the files to a downstream job via stashing/file parameter.有没有办法可以通过 stash/file 参数将文件传递给下游作业。 or could do I have to do something like create a downstream job that does the build and then take the artifacts and use it in a master job that also runs the end to end tests too?或者我是否必须做一些事情,比如创建一个执行构建的下游作业,然后获取工件并将其用于也运行端到端测试的主作业?

This is how I tried the file parameter这就是我尝试文件参数的方式

parameters {
    file name:"buildFiles.zip", description: 'Zip file containing Build Files'
}

Note: I am using a Jenkinsfile for the jobs.注意:我正在使用 Jenkinsfile 来完成这些工作。

UPDATE: The way I ended up solving the issue was to push the finished builds to a proget universal package repo and then let the downstream job pull from that.更新:我最终解决问题的方法是将完成的构建推送到 proget 通用 package 存储库,然后让下游工作从中拉出。

Jenkins COPY ARTIFACT PLUGIN helps copy artifacts from specific projects to the project you want. Jenkins COPY ARTIFACT PLUGIN有助于将工件从特定项目复制到您想要的项目。 The link given has details how it can be done.给出的链接详细说明了如何完成。 This SO thread Build selector for Copy Artifact also explains the same on how it is done.这个 SO thread Build selector for Copy Artifact也解释了它是如何完成的。

This approach assumes you have the file in the current job's workspace.此方法假定您在当前作业的工作区中有该文件。

pipeline
{
    agent any
    stages {
        stage('Pass file type param to build job') {
            steps {
                script {
                    def propertiesFilePath = "${env.WORKSPACE}/sample.properties"
                    build job: 'other-project',
                            parameters: [[$class: "FileParameterValue", name: "propertiesFile", file: new FileParameterValue.FileItemImpl(new File(propertiesFilePath))]]

                }
            }
        }
    }
}

Here the name of the downstream/child job is 'other-project' and the name of the file type parameter in this downstream/child job is 'propertiesFile'.此处下游/子作业的名称为“other-project”,该下游/子作业中的文件类型参数名称为“propertiesFile”。 The type FileParameterValue.FileItemImpl is defined in the class FileParameterValue and is internally used in jenkins to handle FileItem, also adding serialization support to the same. FileParameterValue.FileItemImpl 类型在 class FileParameterValue 中定义,并在 jenkins 内部用于处理 FileItem,还为其添加了序列化支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM