0

I'm building my Continuous Delivery System with Jenkins. To avoid spending a lot of money I set up my jenkins to spawn a new EC2 m4.large instance when a new push is made to Bitbucket. In this way I only pay when I work.

The problem now is that my artifacts stay in the slave and when the instance is terminated I can no longer access my files.

To archive the artifacts I set up my pipeline in this way:

pipeline {
agent {
  node {
    label 'jenkins-slave-spawn'
  }
}
stages {
    stage('prepare') {
        steps {
            sh 'npm install'
            sh 'npm update'
            dir ('./scripts/Web') {
              sh 'bower install'
              sh 'bower update'
            }
            dir ('./scripts/App') {
              sh 'bower install'
              sh 'bower update'
            }
            dir ('./scripts/Site'){
              sh 'bower install'
              sh 'bower update'
            }
            dir ('./scripts/Assistance'){
              sh 'bower install'
              sh 'bower update'
            }
        }
    }
    stage('build') {
        steps {
            sh 'grunt build-beta'
        }
    }
    stage('archive') {
        steps {
            archiveArtifacts artifacts: '**/builds/*', onlyIfSuccessful: true
        }
    }
}

}

But it doesn't seems to work since I cannot see my files anywhere.

Matteo Cardellini
  • 876
  • 2
  • 17
  • 41
  • Are you sure there are files in the directory from your globbing pattern? I.e., if you do an `ls` before the archiving, what does it show? – Rik Apr 22 '17 at 15:21

1 Answers1

2

I found a way using stash and unstash and switching nodes

 pipeline {
agent {
  node {
    label 'jenkins-slave-spawn'
  }
}
stages {
    stage('prepare') {
        steps {
            sh 'npm install'
            sh 'npm update'
            dir ('./scripts/Web') {
              sh 'bower install'
              sh 'bower update'
            }
            dir ('./scripts/App') {
              sh 'bower install'
              sh 'bower update'
            }
            dir ('./scripts/Site'){
              sh 'bower install'
              sh 'bower update'
            }
            dir ('./scripts/Assistance'){
              sh 'bower install'
              sh 'bower update'
            }
        }
    }
    stage('build') {
        steps {
            sh 'grunt build-beta'
        }
    }
    stage('deploy') {
        steps {
            echo 'here will use pm2 to start node app'
        }
    }
    stage('archive') {
        steps {
          stash includes: 'builds/**', name: 'slave-artifacts'
          node('master'){
              unstash 'slave-artifacts'
          }
        }
    }
}
}
Matteo Cardellini
  • 876
  • 2
  • 17
  • 41