Reputation: 2292
I am trying a pipeline script in which I need to open a file and change some text in . So my script goes like this :import java.io.File
node {
stage('File settings') {
dir ('gitfile') {
dir('config') {
sh 'dir'
sh 'pwd > outFile'
curPath = readFile 'outFile'
echo "The current date is ${curPath}"
def file = new File("${curPath}/"+"const.js")
def lines = file.readLines()
println "${file} has ${lines.size()} lines of text"
println "Here is the first line: ${lines[0]}"
println "Here is the last line: ${lines[lines.size()-1]}"
}
}
}
}
But I get error like :
java.io.FileNotFoundException: /var/lib/jenkins/workspace/Daily/smoke/config
/const.js (No such file or directory)
But the file is present in that location. Please let me know why this error happens.
Upvotes: 0
Views: 2252
Reputation: 1805
You should use the readFile() and writeFile() Jenkins pipeline steps to manipulate file contents on the workspace directory. See https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/
Upvotes: 3