code-maven.com icon indicating copy to clipboard operation
code-maven.com copied to clipboard

readfile-writefile.txt in Jenkins

Open vinodkumar4b9 opened this issue 4 years ago • 4 comments

Hi Gabor,

Regarding the Jenkins readfile and writefile , I have a doubt here as By using the script we were able to read the data from a text file and able to print the same , But How can we Pass the values in for Loop and print them in a for loop , I have tried different values but those are printing the values all at a time not according to the loop.

Any suggestions on this is highly appreciated.

vinodkumar4b9 avatar Feb 02 '21 06:02 vinodkumar4b9

Show me the code you wrote so far.

szabgab avatar Feb 02 '21 07:02 szabgab

Hi @szabgab ,

I am trying some thing like this

pipeline { agent any stages { stage('Example') { steps { echo 'Hello World'

            script {
                def browsers =   readFile(file: 'repos.txt') 
                def lines = browsers.readLines()
                
                for (int i = 0; i < lines.size(); ++i) {
                    
                    echo "${lines}"
                }
            }
        }
    }
}

}

I am getting different outputs and as per screen shots attached here , But my main requirement is to get one line at a time in for loop so that I can run required commands over there

Basically In the repos.txt file we have list of repos and i will am getting values from file as per your code , But I wanted to print them in a for loop one by one ,Actually my main requirement was like this

I want to read repo details from that text file and wanted to pass them in for loop and wanted to clone different repos at a time and then need too run checkmarx scan using jenkins pipeline , this is what I am trying to achieve .

image image

vinodkumar4b9 avatar Feb 02 '21 07:02 vinodkumar4b9

Hi @szabgab ,

Any comments on this ??

vinodkumar4b9 avatar Feb 10 '21 17:02 vinodkumar4b9

Hi @szabgab ,

Any comments on this ??

vinodkumar4b9 avatar Mar 05 '21 08:03 vinodkumar4b9