简体   繁体   中英

Can't access directories from my linux server on Jenkins

I have Jenkins installed on my linux server, if I create a random directory in my Jenkins workspace from my pipeline script:

sh 'mkdir test'

And then I connect to my server via PuTTY and go to my jenkins workspace location and check what's in there I can see the "test" directory I created from my jenkins pipeline build:

user@ci:/var/lib/jenkins/workspace$ cd build_test
user@ci:/var/lib/jenkins/workspace/build_test$ ls
test

The problem is when I am in Jenkins writing shell command to navigate in my server and check the files with "ls" I don't see anything, for exemple if I run these commands:

cd /
ls

I get nothing on the console after running my Jenkins build, but I get this result running this on PuTTY:

bin   data  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
boot  dev   home  lib64  media       opt  root  sbin  sys  usr

the only directory I have visibility on is the one in my Jenkins workspace (/var/lib/jenkins/workspace/build_test) where I can see my "test" directory whether from Jenkins or PuTTY.

I am pretty new to Jenkins, so what should I do to have access to all the directories of my server from Jenkins?

Thanks for helping.

I'm going to take a guess here. I figure that the problem here isn't that Jenkins isn't able to see the rest of your filesystem. Rather, it is the way in which Jenkins works where each command runs separately in the workspace.

So if you ran cd / this would take you to / for this command only . Once you run ls , it will revert back to your Jenkins workspace and run ls there.

To fix this, you can either run both in the same line cd / && ls or use dir :

dir('/') {
    sh('ls')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM