I have Jenkins CICD pipeline and I need to read a config file which has key value pairs of Project that needs to be build with the tag number.
I need to read though this file and execute Jenkins pipeline steps in Loop.
Currently my Jenkins CICD pipeline works for single build. I have issues when trying to read a config file and loop though the steps.
Below is a sample of the code i am trying to achieve:
pipeline{
agent any
environment {
buildApp = "$ApplicationToBuild"
cloudEnvironment = "$ENV"
TIMESTAMP = new java.text.SimpleDateFormat('yyyyMMddHHmmss').format(new Date())
WORKSPACE="${env.WORKSPACE}"
}
stages {
stage ('Validation step for deployment') {
steps {
script {
sh 'line_count=$( wc -l applicationSettings.config )'
echo 'line count is $line_count'
for (int lines = 0; lines < ${line_count}; lines++) {
gitAppRepo=""
gitAppTag=""
gitAppRepo=$(echo $lines | sed 's/=.*//')
echo "gitAppRepo is $gitAppRepo"
gitAppTag=$(grep "^$gitAppRepo=" ./applicationSettings.config |cut -d= -f2)
echo "gitAppTag is $gitAppTag"
}
}
}
}
}
post {
always {
echo 'One way or another, I have finished'
}
}
}
I using the line count and looping though the config file to get the app to deploy and the tag. The actual deployment would be called in another jenkins file which contains all the steps.
Below error is encountered in the above loop. Is there any eligent method to loop though in groovy?
java.lang.NoSuchMethodError: No such DSL method '$' found among steps
And how do we call another JenkinsFile in the same project. Below is my file structure. I need to call the Jenkins_files_main in Jenkins_files.
Jenkins_files
README.md
applicationSettings.config
Jenkins_files_main