Pipeline - Using java.io.File in a Pipeline description

Issue

Within a Pipeline description, I need to work with files, to store a value, read its content or validate that the file exists. However, using java.io.File is not working or not permitted inside the sandbox. How can I achieve those tasks?

Environment

  • Jenkins
  • CloudBees Jenkins Enterprise
  • Pipeline Plugin

Resolution

Using java.io.File inside a Pipeline description cannot work as the Pipeline it self is executed on the Master when you want to write/read/test a file on the slave, where the build is done.

So, Pipeline plugins bring some steps in order to provide those features:

  • readFile to read the content of a file in the workspace
  • writeFile to write to a file in the workspace
  • fileExists to test if a file does or not exist in the workspace
  • touch to 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.

References

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.