Search code examples
jenkinsjenkins-pipelinearchivesymlinkartifacts

Deploy artifacts in lastsuccesful build jenkins pipeline


I have a jenkins (pipeline) build. My lastsuccesful build of my pipeline:

+ ls -ltrah /srv/jenkins/jobs/xx-IB/lastSuccessful/
total 7.5M
-rw-r--r--. 1 jenkins jenkins  442 Dec 19 11:27 3.log
-rw-r--r--. 1 jenkins jenkins   64 Dec 19 11:27 4.log
-rw-r--r--. 1 jenkins jenkins 3.6K Dec 19 11:27 8.log
-rw-r--r--. 1 jenkins jenkins    0 Dec 19 11:27 9.log
-rw-r--r--. 1 jenkins jenkins 4.6K Dec 19 11:27 10.log
-rw-r--r--. 1 jenkins jenkins    0 Dec 19 11:27 11.log

But it does not contain symlinks to my created artifacts. How can I access my created artifacts from my lastsuccesful build so I can access the artifacts from here (symlinks): /srv/jenkins/jobs/jobname/lastSuccessful/?


Solution

  • You can Archive the artifacts in post after every stage

    stage('Build Debug') {
        steps {
            dir('project/embsw') {
                sh 'mingw32-make.exe makefile=Makefile clean'
                sh 'mingw32-make.exe makefile=Makefile debug'
            }
        }
        post {
            always {
                archive "project/embsw/debug/*"
            }
        }
    }
    

    The above code will archive everything which in present inside directory project/embsw/debug/.
    So I would recommend to archive in every stage if you have any artifact to archive and avoid having a separate stage for archiving.
    This is the advantage of using Pipeline, you can archive in every stage not like old Jenkins config method where you archive in the last or post build action.