简体   繁体   中英

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. 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. Is there a way I can pass the files to a downstream job via stashing/file parameter. 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.

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.

Jenkins COPY ARTIFACT PLUGIN helps copy artifacts from specific projects to the project you want. 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.

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'. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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