How can I copy artifacts from executed jobs with declarative pipeline?

Dmitry

My pipeline script looks like this:

pipeline {
    agent {
        label 'my-pc'
    }

    stages {
        stage ('Build') {
            steps {
                build job: 'myjob', parameters: [string(name: 'BRANCH', value: 'master')]
            }
            post {
                always {
                    sh 'echo TODO: copy artifacts here'
                }
            }
        }

    }
}

I want to copy artifacts generated by myjob. How can I do this?

Jenkins documentation page "Recording tests and artifacts" has an instruction which is not applicable for my pipeline (in my case artifact is generated by a separate job).

Travenin

You can use Copy Artifact plugin and then you can use it with step step, which allows to call builders or post-build actions as in Freestyle jobs. See Pipeline Syntax of your job and consult Snippet Generator. (https://[jenkins-url]/[path-to-your-job]/pipeline-syntax/)

This is how to copy all artifacts from job myjob to current pipeline job workspace:

pipeline {
    agent {
        label 'my-pc'
    }

    stages {
        stage ('Build') {
            steps {
                build job: 'myjob', parameters: [string(name: 'BRANCH', value: 'master')]
            }
            post {
                always {
                    step([
                        $class: 'CopyArtifact',
                        filter: '*',
                        projectName: 'myjob',
                        selector: [
                            $class: 'StatusBuildSelector',
                            stable: false
                        ]])
                }
            }
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I tag a project in git from a jenkins declarative pipeline

How to publish and download artifacts from multiple jobs into one location on pipeline?

How to Copy Artifacts from other Jenkins Job from a Pipeline?

How can I use the Jenkins Copy Artifacts Plugin from within the pipelines (jenkinsfile)?

Jenkins : Copy artifacts from Multibranch pipeline

How to parameterize selector for copy artifacts in Jenkins pipeline

How to restrict parallel jobs to particular slaves in Declarative Pipeline

How to exclude file from archiveArtifact in declarative pipeline?

How can I use Jar produced by mvn package in another Jenkins declarative pipeline stage?

How can I use different private docker agents based on parameter in Jenkins declarative pipeline?

Jenkins pipeline, how can I copy artifact from previous build to current build?

How do I use Docker's --cache-from build flag in a declarative Jenkins pipeline?

Copy artifacts from an upstream multi-branch pipeline

Unable to copy artifacts from one stage to another stage in azure pipeline

How to handle a possible non-existant branch when copying artifacts in a Jenkins declarative pipeline?

How to copy the artifacts from slave to Jenkins workspace?

How to copy artifacts from upstream project in Jenkins?

How to abort a declarative pipeline

gitlab: how can i programatically download the artifacts issued at end of CI pipeline

Can I have an entire declarative pipeline defined and parameterized in a shared library?

Can I wrap a whole stage of a declarative pipeline as groovy library function?

In a declarative jenkins pipeline - can I set the agent label dynamically?

Can I define multiple agent labels in a declarative Jenkins Pipeline?

Can I use a Closure to define a stage in a Jenkins Declarative Pipeline?

how can we configure to pull npm packages from Jfrog artifacts for yaml based azure CI Pipeline?

How to publish Travis CI artifacts to GitHub Release from several jobs

How do I pass variables between stages in a declarative Jenkins pipeline?

Jenkins Declarative Pipeline: How to read choice from input step?

How to retrieve all lines from a text parameter in a Jenkins declarative pipeline?

TOP Ranking

HotTag

Archive