There are lots of ways to do this. Here are two ways I can think of off the top of my head:

steps {
  println(WORKSPACE)
}

or

steps {
  def foo = sh(script: 'pwd', returnStdout: true)
  println(foo)
}
Answer from jayhendren on serverfault.com
🌐
Jenkins
jenkins.io › doc › pipeline › steps › workflow-basic-steps
Pipeline: Basic Steps
Use a comma separated list to add more than one expression. If blank, treated like **: all files. The current working directory is the base directory for the saved files, which will later be restored in the same relative locations, so if you want to use a subdirectory wrap this in dir.
🌐
GitHub
gist.github.com › KenDUemura › 48856cc1e9cd1aedf041b602ce89bf15
Jenkins Pipeline, Get current Job's Folder Name · GitHub
Jenkins Pipeline, Get current Job's Folder Name. GitHub Gist: instantly share code, notes, and snippets.
🌐
Medium
medium.com › @dipali26N › day-39-creating-directories-in-jenkins-pipelines-278953b74f48
DAY:39 Creating Directories in Jenkins Pipelines | by Dipali Naygaonkar | Medium
July 23, 2025 - Prints the current working directory (should be /tmp/<build_number>). The echo ... > my-temp-dir/test-file.txt line creates a text file inside my-temp-dir. The ls -la my-temp-dir lists the contents so you can confirm the file was created. When you SSH into /tmp/5/my-temp-dir later, you’ll see the test-file.txt. ... If your pipeline uses ws("/tmp/${BUILD_NUMBER}") or any temp path outside the workspace, those files won’t be visible in the Jenkins UI by default.
🌐
Stack Overflow
stackoverflow.com › questions › 58870862 › how-can-i-print-the-current-working-directory-in-a-jenkinsfile-using-powereshell
powershell - How can I print the current working directory in a Jenkinsfile using powereshell - Stack Overflow
Since this syntax returns the output stream, i.e. stream 1 of Powershell output without printing it to the console, you need to store the stdout in a variable and print it explicitly in the Jenkinsfile. currentDir = powershell(returnStdout: true, script: 'Get-Location') println(currentDir)
🌐
Jenkins
issues.jenkins.io › browse › JENKINS-46636
Loading...
What it does is simply create a new folder called "new-dir" in the current working directory and then the pwd prints out the current working directory instead of navigating into the "new-dir".
Find elsewhere
🌐
Baeldung
baeldung.com › home › jenkins › jenkins pipeline – change to another folder
Jenkins Pipeline – Change to Another Folder | Baeldung on Ops
November 6, 2023 - The dir step is a built-in step in Jenkins that allows us to change to a different directory for the duration of a block. This is very useful when we want to run specific commands from a particular directory. Let’s look at the dir step to change our current working directory to a subdirectory “scripts”:
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to change jenkins home directory
How to Change Jenkins Home Directory {Linux or Windows}
October 18, 2022 - 1. To check the default Jenkins Home directory location, use a web browser to open the Jenkins dashboard. In our case, we are browsing to http://localhost:8080/. Note: By default, Jenkins uses the 8080 port.
🌐
LinkedIn
linkedin.com › pulse › we-know-dont-jenkins-workspace-niranjan-gowda
We know but don't know! - Jenkins workspace
September 30, 2022 - Jenkins stores some of the related builds data like the following: The working directory is stored in the directory {JENKINS_HOME}/workspace/.
🌐
Jenkins
jenkins.io › doc › pipeline › steps › pipeline-utility-steps
Pipeline Utility Steps
Find files in the current working directory. The step returns an array of file info objects who's properties you can see in the below example.
Top answer
1 of 2
2

I could not achieve changing the working directory using the suggestion by Vishwas, although I did try creating a Jenkins user inside the container with the same uid as the host. It just didn't work for me. I did however, realize that I didn't actually need to change the directory on the container because the workspace was already in the container.

I'm using the Docker Plugin from CloudBees. After reading their documentation, I realized the workstation folder I thought was on the host machine, was actually in the container. Part of the documentation stated:

The above is a complete Pipeline script. inside will:

  1. Automatically grab an agent and a workspace (no extra node block is required).
  2. Pull the requested image to the Docker server (if not already cached).
  3. Start a container running that image.
  4. Mount the Jenkins workspace as a "volume" inside the container, using the same file path.

After seeing item number four, I ran docker container inspect <containerID> and I saw the workspace /home/jenkins/workspace was actually a volume mount that was mapped to the /home/jenkins/workspace on the Docker host machine as well. Using this as my workspace, I was able to build the various applications within the container and then moved the results to a second volume used for application collection later in the pipeline. It's not an exact answer to my original question, but it works!

2 of 2
1

If your master is running as Jenkins user, you should make a user in the docker image which you use as to create your node and do the key exchange. For example jenkinsuser with same UID needs to exist on both master and node docker container.

🌐
CloudBees
docs.cloudbees.com › knowledge base › how to get a job / folder directory ?
How to get a Job / Folder directory ?
In any case, you can find the item directory of a specific item in the file system under the Item Root Directory at $JENKINS_HOME/jobs/$PATH_TO_JOB/.
🌐
DZone
dzone.com › testing, deployment, and maintenance › deployment › jenkins: changing the jenkins home directory
Steps to Changing Jenkins Home Directory
October 15, 2019 - There is only ever one workspace directory per project, and the disk space it requires tends to be relatively stable. If the Jenkins server default home directory was full or we want to run Jenkins jobs on block volume or specific directory we can do it by following these steps to change to the Jenkins Home Directory.
🌐
Jenkins
jenkins.io › doc › book › managing › system-configuration
Configuring the System
The Jenkins home directory is listed in Manage Jenkins > System under the Home directory heading.