Read file from Jenkins workspace with System groovy script
groovy, jenkins
Solution
Each build has a workspace, so you need to find the desired project first. (The terms "job" and "project" are used rather interchangeable in Jenkins - also in the API.)
After that, you can either cross your fingers and just call `getWorkspace()`, which is deprecated (see JavaDoc for details).
Or you can find a specific build (e.g. the last), which can give you the workspace used for that specific build via the `getWorkspace()` method as it is defined in the `AbstractBuild` class.
Example code:
Jenkins.instance.getJob('<job-name>').lastBuild.workspace;
Problem
I have a question very similar to this: Reading file from Workspace in Jenkins with Groovy script However I need to read the file from a System Groovy script so the solution of using Text-finder or the Groovy PostBuild plugin will not work. How can I get the workspace path from a system groovy script? I have tried the following: ``` System.getenv('WORKSPACE') System.getProperty("WORKSPACE") build.buildVariableResolver.resolve("WORKSPACE") ``` Thanks!