jenkins pipeline对groovy脚本的限制

在jenkins的pipeline中, 写groovy脚本的时候有一些限制.

比如new File()是不行的, 会报错"No such file or directory", 其原因可能是沙盒机制的影响. 

读文件和写文件都要通过pipeline的指令来进行, 详见: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/

例如, 下列代码读取dockerfile, 修改之后再写回去.

            def dockerFile = readFile "dockerfile"
            println("the original docker file:" + dockerFile)
            dockerFile = dockerFile.replaceFirst("FROM abc.0.1", "FROM abc:0.2")
            writeFile file: "dockerfile", text: dockerFile
            println("changed file:" + readFile(file: "dockerfile"))

 

猜你喜欢

转载自rickgong.iteye.com/blog/2405940