3

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.

Mhyland
  • 250
  • 1
  • 4
  • 14

2 Answers2

5

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.

vijay v
  • 1,888
  • 1
  • 12
  • 19
  • Will it work if the job that the artifacts are coming from is not finished running? the files would be coming from a still-running upstream job. – Mhyland Apr 08 '20 at 15:10
  • Yes you can. I'm using my.mobile to update the comment, so couldn't add more info. In your case I'd do the same as given in https://stackoverflow.com/a/45301462 – vijay v Apr 08 '20 at 16:01
0

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.