How to fetch multiple host names from config file management in Jenkins pipeline groovy script
In this tutorial, we are going to learn configuring multiple host names i.e. DEV, QA and PRODUCTION environments in the config file management of the Jenkins and fetch them in the pipeline groovy script using configFile Plugin.
Firstly, In Jenkins dashboard, go to > Manage Jenkins > Under System Configuration > Managed files.
Click on managed files and go to > add a new a config, now select the required extension in my case I have selected properties file and an ID will be generated by Jenkins copy that for future references and click submit button.
Now under Edit Configuration File we have ID and name i.e. specify the name of the properties file, I specified name as ‘target’ (Custom name).
In the content I specified TARGET_NODE=IP ADDRESS (Host name).
Please find below groovy script with maven build steps specified.
#!groovy
node {
stage('configFile Plugin') {
def mycfg_file = '4d281206-c188-4683-9440-f883e6896716'
configFileProvider([configFile(fileId: mycfg_file, variable: 'target.properties')]) {
standardWorkflow \
defaultPhase:"BUILD, PACKAGE ,DEPLOY,SAST",
language:"MAVEN",
compileOptions:"clean compile -Dmaven.test.skip=false",
packagingType:"WAR",
packagingOptions:"clean deploy -Dnodes=${env.TARGET_NODE}",
updatePOM:"false",
publishArtifact:"false"
}
}
}