Get absolute path to workspace directory in Jenkins Pipeline plugin

I’m currently doing some evaluation on the Jenkins Pipeline plugin (formerly know as Workflow plugin).
Reading the documentation I found out that I currently cannot retriev the workspace path using
env.WORKSPACE:

The following variables are currently unavailable inside a workflow script:

  • Add buld and commit hash to manifest
  • How to listen to submodule changes without cloning in Jenkinso
  • How to change home directory of Jenkins?
  • Jenkins slave set-up - Both Master and Slave Nodes are Linux machines
  • Jitterbit project + Git + Continuous integration
  • Running pylint against only changed lines/files with jenkins
  • NODE_LABELS

    WORKSPACE

    SCM-specific variables such as SVN_REVISION

    Is there any other way how to get the absolute path to the current workspace? I need this running some test which in turn gets some parameter (absolute path to some executable file).
    I already tried using new File("").absolutePath() inside a @NonCPS section but looks like the non-CPS stuff gets always executed on the master.

    Does anybody have a clue how to get this path without running some batch script which stores the path into some file which later on can be read in again?

  • Jenkins REST API - using tree to reference specific item in JSON array
  • Jenkins - Unable to git clone from slave node. SSH keys
  • Running Selenium tests in Jenkins
  • How to get rid of dependency errors loading jenkins?
  • Bower - enogit git is not installed or not in the PATH
  • How to attach the build file in jenkins post build email?
  • 3 Solutions collect form web for “Get absolute path to workspace directory in Jenkins Pipeline plugin”

    Since version 2.5 of the Pipeline Nodes and Processes Plugin (a component of the Pipeline plugin, installed by default), the WORKSPACE environment variable is available again. This version was released on 2016-09-23, so it should be available on all up-to-date Jenkins instances.

    Note: this solution works only if the slaves have the same directory structure as the master. pwd() will return the workspace directory on the master due to JENKINS-33511.

    I used to do it using pwd() functionality of pipeline plugin. So, if you need to get a workspace on slave, you may do smth like this:

    node('label'){
        //now you are on slave labeled with 'label'
        def workspace = pwd()
        //${workspace} will now contain an absolute path to job workspace on slave 
    }
    

    Hope it will help.

    When you are using a script, the concept of workspace is meaningless. Your best bet is to use readFile to read the file into a string, then pass that string to your library for processing. The pwd() method can’t help you because it executes on the master, and your files are stored on the node.

    Git Baby is a git and github fan, let's start git clone.