This issue making some problems in many pipelines I manage ... and till it's fixed in the upstream I've implemented a custom step dynamicMatrix.
That custom step mimics Jenkins declarative matrix but with better visualization and extra customization options. It makes it easier to run a parallel matrix with different combinations and groups.
Here is an example:
stage('single_matrix') {
steps {
dynamicMatrix([
failFast: false,
axes: [
PLATFORM: ['linux', 'mac', 'windows'],
BROWSER: ['chrome', 'firefox', 'safari']
],
actions: {
stage("${PLATFORM}_${BROWSER}") {
sh 'echo ${PLATFORM} - ${BROWSER}'
sh 'echo ${MATRIX_STAGE_NAME}'
}
}
])
}
}
It also has 2 other varieties to work with different combinations and groups.
If you have different axes combinations but the same stages then dynamicMatrixMultiCombinations could be used for that case.
stage('multi_combinations_matrix') {
steps {
dynamicMatrixMultiCombinations([
failFast: false,
axes: [
[
PLATFORM: ['linux', 'mac', 'windows'],
BROWSER: ['chrome', 'firefox']
],
[
PLATFORM: ['mac', 'windows']
BROWSER: ['safari'],
],
],
actions: {
stage("${PLATFORM}_${BROWSER}") {
sh 'echo ${PLATFORM}, ${BROWSER}'
sh 'echo ${MATRIX_STAGE_NAME}'
}
}
])
}
}
If you have different groups or different stages that should run in parallel at the same time, then dynamicMatrixMultiGroups could be used for that case.
stage('multi_groups_matrix') {
steps {
dynamicMatrixMultiGroups([
[
failFast: false,
axes: [
PLATFORM: ['windows']
BROWSER: ['edge', 'safari'],
],
actions: {
stage("${PLATFORM}_${BROWSER}") {
bat 'echo this is a Windows command'
}
}
],
[
failFast: false,
axes: [
PLATFORM: ['linux', 'mac'],
BROWSER: ['chrome', 'firefox']
],
actions: {
stage("${PLATFORM}_${BROWSER}") {
sh 'echo this is a Unix-like command'
}
}
]
])
}
}
Enjoy 
This issue making some problems in many pipelines I manage ... and till it's fixed in the upstream I've implemented a custom step dynamicMatrix.
That custom step mimics Jenkins declarative matrix but with better visualization and extra customization options. It makes it easier to run a parallel matrix with different combinations and groups.
Here is an example:
It also has 2 other varieties to work with different combinations and groups.
If you have different axes combinations but the same stages then dynamicMatrixMultiCombinations could be used for that case.
If you have different groups or different stages that should run in parallel at the same time, then dynamicMatrixMultiGroups could be used for that case.
Enjoy