4

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 ?

Corey
  • 1,217
  • 3
  • 22
  • 39
  • 1
    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 directory – Pavel Anikhouski Mar 15 '19 at 08:47
  • Would you mind explaining more detail ? What's the difference between `the workspace of build` and `my Linux working directory` ? – Corey Mar 15 '19 at 09:02
  • 2
    You can see the list of Jenkins env variables at http://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 same – Pavel Anikhouski Mar 15 '19 at 09:19
  • @PavelAnikhouski I see, thank you. But I am still confused about `$WORKSPACE`. Why Jenkins needs `$WORKSPACE`, but execute shell in another working directory ? – Corey Mar 18 '19 at 00:58
  • 1
    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? – d512 Mar 20 '19 at 21:13
  • @d512 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. – Corey Mar 21 '19 at 00:36

0 Answers0