Within a Jenkinsfile, I am running regression tests in pytest and using the --junitxml flag to produce test output. Each regression test runs in its own stage and captures an .xml file with the test output, I then stash these xml files (as each stage runs on a different agent). After all the regression tests have been run, the stashed files are then recovered for reporting once all tests are done.
Please see below:
stage ('Regression 01') {
agent {
label 'rhel1'
}
steps {
sh "cd /directory1/appServer && /home/appServer/py/venvs/*/bin/python -m " +
"pytest -m fast test-dir/regression_test.py -c conf.cfg --junitxml /share/01.xml"
stash includes: '01.xml', name: 'test01'
}
}
stage ('Regression 02') {
agent {
label 'rhel2'
}
steps {
sh "cd /directory1/appServer && /home/appServer/py/venvs/*/bin/python -m " +
"pytest -m fast test-dir/regression_test.py -c conf.cfg --junitxml /share/1.xml"
stash includes: '02.xml', name: 'test02'
}
}
post {
always {
unstash 'test01'
unstash 'test02'
junit "*.xml"
...
}
}
I have a total of 10 regression tests running which each stash a unique .xml file, I am also looking to add more, therefore hardcoding the XML test names is not feasible.
How can I create some sort of automation or logic within my Jenkinsfile that will do the XML naming, stashing and unstashing?