@mawinter69 Hi Markus, may we revisit this code please. It is working fine, but the reporting in Jenkins Pipeline Console output is strange.
For this example code:
pipeline {
agent { label "jenkins-ubuntu22-2" }
stages {
stage('example_2') {
steps {
script {
def my_agent = 'jenkins-ubuntu22-2'
def files_list = ['file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt', 'file6.txt', 'file7.txt', 'file8.txt', 'file9.txt', 'file10.txt']
// Reverse the list so that pop() will pop filenames starting with the first filename in the parameter string.
def files_list_reverse = files_list.reverse()
// Create a map that will contain info for the parallel stages.
def p = [:]
for (file in files_list_reverse) {
echo "Preparing $file"
p[file] = {
node(my_agent) {
def nextFile = files_list_reverse.pop()
sh """
echo $nextFile
"""
}
}
}
// Execute the parallel stages
parallel p
}
}
}
}
}
The image shows stage ‘file2.txt’ selected but the console output is for ‘file9.txt’.
So the mapping between the parallel stages and the console output is incorrect.
Can you comment on what is wrong please?
The stages are executed in parallel. And p is a hash, that means the order in which the parallel stages are started is not guaranteed to be in the order they were added. So it can happen that the file2.txt is started after the one for file9.txt. If execution order is important then parallel is the wrong approach.
Thanks, the execution order is not critical. It just means that the pipeline console is hard to navigate, but we can live with that. Thanks for your answer.
I have evolved the code for my application but the concept is working very well. Instead of the echo I execute an application:
sh """
./myApp $nextFile
"""
At the end of the pipeline myApp will have been executed once for each file in list files.
I want to include in the final email notification the list of files together with an indication of whether or not myApp succeeded (exit code 0) or failed (exit code 1) for each file.
file 1.txt Passed
file 2.txt Failed
etc.
I would be grateful for a hint for how to do this.
Would it be best to do this by somehow providing a post processing section for each parallel stage? I am wondering if that section could add a text entry to a global results list, which could be included in the final email notification.
I would be grateful for a hint as to how to organize the post processing sections.