'Jenkins: unable to access the artifacts on the initial run

My setup: main node runs on Linux and an agent on Windows. I want to compile a library on an agent, archive those artifacts and copy them on the main node to create a release togather with the Linux compiled binaries.

This is my Jenkinsfile:

pipeline {
    agent none
    stages {
        stage('Build-Windows') {
            agent {
                dockerfile {
                    filename 'docker/Dockerfile-Windows'
                    label 'windows'
                }
            }
            steps {
                bat "tools/ci/build.bat"
                archiveArtifacts artifacts: 'build_32/bin/mylib.dll'
            }
        }
    }
    post {
        success {
            node('linux') {
                copyArtifacts filter: 'build_32/bin/mylib.dll', flatten: true, projectName: '${JOB_NAME}', target: 'Win32'
            }
        }
    }
}

My problem is, when I run this project for the first time, I get the following error

Unable to find project for artifact copy: mylib

But when I comment the copyArtifacts block and rerun the project, it is successful and I have artifacts vivible in the project overview. After this I can reenable the copyArtifacts and then the artifacts will be copied as expected.

How to configure the pipeline so it can access the artifacts on the initial run?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source