I want to fetch data from my sql Table and use them as a choice parameters in Jenkins
+----+
| ID |
+----+
| 11 |
| 23 |
| 45 |
| 72 |
| 5 |
| 16 |
| 71 |
| 18 |
+----+
I want to use these IDs as a choice parameter in Jenkins in order to build using one of these ID i.e. build with parameters using these ID numbers as Parameter
I simply want a drop down with these ID numbers as the choices before I build and the selected choice can be used as parameter to the script in the build step.
What would be the way of achieving this? Please help
You can achieve this using Extended Choice Parameters in combination with a properties file.
key=value1,value2,value3,...
, e.g., key=11,23,45,72,5,16,71,18
./var/lib/jenkins/userContent/build.properties
. You need to write an automation script/create another job to update this file at regular intervals.TABLE_VALUE
.,
./var/lib/jenkins/userContent/build.properties
.key
as the Property Key.TABLE_VALUE
in your pipeline.Pipeline Code
You can achieve the same in your pipeline by placing this block at the top:
properties([
parameters([
extendedChoice(
name: 'TABLE_VALUE',
description: '',
type: 'PT_SINGLE_SELECT',
multiSelectDelimiter: ',',
propertyFile: '/var/lib/jenkins/userContent/build.properties',
propertyKey: 'key',
quoteValue: false
)
])
])
See the source code for all possible parameters and PT constants for all possible values of type.
Job Configuration
Build Parameters