$PWD and $WORKSPACE are different in Jenkins
Asked Answered
P

1

6

My job has a build step Build - Execute shell, I only put these two command in:

echo $WORKSPACE
echo $PWD

And the output really confused me:

+ echo /home/jenkins/workspace/tradefed/test_deployment
/home/jenkins/workspace/tradefed/test_deployment
+ echo /media/d/workspace/tradefed/test_deployment
/media/d/workspace/tradefed/test_deployment

Why the value of $WORKSPACE and $PWD are different ?

Update 2019/03/18:

As @PavelAnikhouski mentioned, $WORKSPACE is set relatively to your $JENKINS_HOME, $PWD is OS environment variable, refers to current working directory in file system, so they should not be the same.

But I am still confused about $WORKSPACE, why Jenkins has $WORKSPACE, but execute shell in another working directory ?

Privy answered 15/3, 2019 at 8:3 Comment(6)
Why they should be the same? One variable is "The absolute path of the directory assigned to the build as a workspace", second one is the your Linux OS working directoryKnar
Would you mind explaining more detail ? What's the difference between the workspace of build and my Linux working directory ?Privy
You can see the list of Jenkins env variables at your_server_address/env-vars.html They are managed by Jenkins service itself. $WORKSPACE is set relatively to your $JENKINS_HOME (where Jenkins is installed) $PWD is OS environment variable, refers to current working directory in file system. I would not expect these values to be the sameKnar
@PavelAnikhouski I see, thank you. But I am still confused about $WORKSPACE. Why Jenkins needs $WORKSPACE, but execute shell in another working directory ?Privy
Actually they are the same for me, at least initially. I would expect the shell to start out in the project's workspace directory. You may change that by doing a cd /some/other/place but it makes sense as a default. Is there something else in your script that is changing which directory you're in?Laveen
@Laveen I didn't do anything in the script except echo. I have some settings in Source Code Management - Git and Gerrit Tigger, but I didn't specify any path or change directory.Privy
V
1

Note that part of the paths have the same subpath

/home/jenkins/workspace/tradefed/test_deployment
     /media/d/workspace/tradefed/test_deployment

You likely use a symbolic or hard link, or shell path alias, where both map to the same - with the jenkins system user home directory being /home/jenkins/ and /media/d/ at the same time, equivalently, targeting the same.

This may be because your administration off-loaded (mounted) the jenkins home directory to a different storage. After all, contrary to the system whose storage requirements and use remain relatively constant, Jenkins produces build workspaces and has varying or changing storage space needs. It may also be an effort to differentiate the type of storage being used, where the system is mostly read, not written to, while the jenkins folder has regular writes and reads through build runs.

/home/ is usually the system user's home directory. /home/jenkins is likely linked ("aliased") to the physical storage /media/d/ - likely a separate partition labeled d.

You can find out more on the system, as a system or root user, if you have access, or ask your administration that maintains this.

Vibrate answered 25/5 at 5:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.