Within a Pipeline definition (
Jenkinsfile), I need to work with files, to store a value, read its content or validate that the file exists.
java.io.File is not working or not permitted inside the _ groovy sandbox_.
How can I achieve those tasks?
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
- CloudBees CI (CloudBees Core) on traditional platforms - Client controller
- CloudBees Jenkins Enterprise - Managed controller
- CloudBees Jenkins Platform - Client controller
- CloudBees Jenkins Distribution
- Jenkins LTS
java.io.File inside a Pipeline description cannot work as the Pipeline it self is executed on the controller when you want to write/read/test a file on the agent, where the build is done.
So, Pipeline plugins bring some steps in order to provide those features:
readFileto read the content of a file in the workspace
writeFileto write to a file in the workspace
fileExiststo test if a file does or not exist in the workspace
touchto create an empty file (from
pipeline-utility-steps-plugin) in the workspace
You can details on the exact syntax for those step using the snipper generator when creating a plain Pipeline job.