I have a simple input file with two words in each line and parsing in Jenkinsfile (groovy), but seeing a issue,
pipeline {
agent any
stages {
stage('Test-1') {
steps {
echo 'Building..'
script {
for (x in 1..5) {
println x //0,1,2,3,4,5
}
}
}
}
stage('Test-2 ') {
steps {
script {
File file = new File("my_file.txt")
def line, noOfLines = 0;
file.withReader { reader ->
while ((line = reader.readLine()) != null) {
println "${line}"
noOfLines++
}
}
}
}
}
stage('Test-3') {
steps {
script {
def whole_file_data = readFile(file: 'my_file.txt')
whole_file_data.eachLine { String line ->
def (p1, p2) = line.tokenize()
println("line:${line}")
println("p1:${p1} & p2:${p2}")
}
}
}
}
}
}
The Test-1 works fine for testing, The Test-2 gives me error as
Scripts not permitted to use new java.io.File java.lang.String. Administrators can decide whether to approve or reject this signature.
The Test-3 stage prints ONLY FIRST Line and gives Warning as,
[Pipeline] readFile
expected to call java.lang.String.eachLine but wound up catching org.jenkinsci.plugins.workflow.cps.CpsClosure2.call; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
line:1111 one
[Pipeline] echo
My Jenkins version is Jenkins 2.249.1 What is causing issue? p1:1111 & p2:One