Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change nodes between pipeline stages

In my pipeline, I am changing from my master to a slave node in one of my stages:

pipeline {
  agent any
  stages {
    stage('Install Deps...') {
      steps {
        echo 'Do something here'
      }
    }
    stage('Build') {
      steps {
        echo 'Build stuff here...'
        stash includes: 'dist/**/*', name: 'builtSources'
        node('Protractor') {
          dir('/some-dir/deploy') {
            unstash 'builtSources'
          }
        }
      }
    }
    stage('Tests') {
      steps {
        parallel (
          "Chrome": {
            echo 'Chrome testing here...'
          }
        )
      }
    }
  }
}

I can see from the console output on Jenkins it correctly says 'running on master' at the start of the first stage, and changes to 'running on Protractor' in my second stage. When the third 'Tests' stage starts, I dont see the node change back to master in the console output, is that expected behaviour?

Should stages run on the master unless explicitly told otherwise with a node() block?

like image 255
mindparse Avatar asked Dec 19 '22 08:12

mindparse


1 Answers

you have a nested node. This should be equivalent to:

node {
    //run stuff on any node
    node('agent'){
        //run stuff on agent; other node is still busy
    }
    //return to original node; no message since it is still open
}
//outside of all nodes
like image 73
erbarr Avatar answered Dec 26 '22 11:12

erbarr