File not found in jenkins pipeline script

I'm not really sure how or why it works, but I found this https://stackoverflow.com/a/38679858/985291 and managed to solve the issue by using the readFile step https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace mentioned.

so basically, changing

 new File(env.SERVICE_VERSIONS_FILE).each { line ->

to

 readFile(env.SERVICE_VERSIONS_FILE).split("\n").each { line ->

and it works.

EDIT As @zett42 mentions in their comment, this is apparently by design, and you should just use the build in steps (readFile,writeFile) when dealing with files. (https://issues.jenkins-ci.org/browse/JENKINS-37577?focusedCommentId=267445&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-267445)