Jenkins Pipeline Job with file parameter

前端 未结 8 1942
难免孤独
难免孤独 2020-12-01 10:33

I\'m putting together a Jenkins pipeline job which will take a file parameter. I can trigger the job and point it at a file however I can\'t find where the file has ended up

8条回答
  •  独厮守ぢ
    2020-12-01 10:51

    Tried what Christoph suggested and it didnt work for me. Here is what worked for me and the setup which I have, his should help others figure out what to do.

    Problem: I am executing my pipeline on dedicated nodes and use sanitized workspaces. After some research and troubleshooting I found out that by default the file upload only works with Master node. I realized this after digging through the file system and finding the file I am uploading in the workspace on the master

    Solution:

    stage('Upload Key') {
        agent { label 'master' }
        steps {
            script {
                // Uploads file via master node and stases it for other nodes to access
                def inputFile = input message: 'Upload file', parameters: [file(name: "key.p12")]
                new hudson.FilePath(new File("${workspace}/key.p12")).copyFrom(inputFile)
                inputFile.delete()
            }
            stash name: 'key.p12' , includes: "key.p12"
        }
    }
        stage('Register') {
            steps {
                ws (sanitizedWorkspaceName) {
                    echo "Registering"
                    unstash 'key.p12'
                }
            }
        }
    
    1. Execute the suggested file copy solution by Christoph. This stores the file in the job workspace on the master node
    2. Allow the scripts in Manage Jenkins > In Process Script approval
    3. use the stash step to stash the uploaded file
    4. In the target stage "running on a different node" use the unstash

    Hope this helps

提交回复
热议问题