I'm struggling to run the following Jenkins pipeline. I added a UI parameter (TARGET_FILTER).
The idea is:
- if I select tst, it excludes qua, prd; it executes only 1 value (tst1)
- if I select qua, it excludes tst, prd; it executes 2 values (qua1, qua2)
- if I select prd, it excludes tst, qua; it executes 2 values (prd1, prd2)
I can't make it work, the entire matrix is executed and my excludes are ignored.
pipeline {
parameters {
choice(name: 'TARGET_FILTER', choices: ['tst', 'qua', 'prd'], description: 'Run on specific target')
}
agent any
stages {
stage('go') {
matrix {
when { anyOf {
expression { params.TARGET_FILTER == 'tst' }
} }
axes {
axis {
name 'TARGET'
values 'tst', 'qua', 'prd'
}
axis {
name 'REMOTE'
values 'tst1', 'qua1', 'qua2', 'prd1', 'prd2'
}
}
excludes {
exclude {
axis {
name 'TARGET'
values 'tst'
}
axis {
name 'REMOTE'
values 'qua1', 'qua2', 'prd1', 'prd2'
}
}
exclude {
axis {
name 'TARGET'
values 'qua'
}
axis {
name 'REMOTE'
values 'tst1', 'prd1', 'prd2'
}
}
exclude {
axis {
name 'TARGET'
values 'prd'
}
axis {
name 'REMOTE'
values 'tst1', 'qua1', 'qua2'
}
}
}
stages {
stage('Build') {
steps {
echo "${params.TARGET}"
echo "Do Build for ${TARGET} - ${REMOTE}"
}
}
}
}
}
}
}