1

Is it possible to save some values during a parallel execution and use these values during a final step?

In the following example, I would like to know which jenkins slave is used during the parallel execution and use it during the final step.

node {
    stage 'Checkout'
    checkout([...])
    stash includes: '**', name: 'binary'

    stage 'Running simulation'
    parallel (
        "stream 1" : { 
                         node {
                                unstash "binary"
                                sh "echo \"\$(whoami)@\$(hostname):\$PWD\""
                                // How to save the previous result

                                // Run simulation on node first slave
                                ...
                           } 
                       },
        "stream 2" : { 
                         node {             
                                unstash "binary"
                                sh "echo \"\$(whoami)@\$(hostname):\$PWD\""
                                // How to save the previous result

                                // Run simulation on node second slave
                                ...
                           } 
                       }
              )


    stage 'Gathering results files'
    // use the values of the slaves to retrieve some files.

    stage 'Generate report'

}

Thanks for your answer.

Maxime
  • 51
  • 6
  • 1
    Almost duplicate of http://stackoverflow.com/questions/36507410/is-it-possible-to-capture-the-stdout-from-the-sh-dsl-command-in-the-pipeline ? It should indeed be enough to store the sh result in a variable (in a List or a Map if needs be) – sensei Oct 26 '16 at 09:55
  • @sensei I try to use `hostname = sh (returnStdout: true, script: 'hostname')` but `println hostname` returns 0 – Maxime Oct 26 '16 at 12:07

1 Answers1

1

My bad, I was using the 2.3 version of Pipeline Nodes and Processes Plugin. It works fine with the version 2.5

hostname = sh (returnStdout: true, script: 'hostname')
println hostname
Maxime
  • 51
  • 6