Leon
Leon

Reputation: 11

Jenkinsfile ,by using sh, says No such file or directory, but it exists

I'm studying jenkins, trying to package a maven project to a war, then move it to a previously started tomcat webapps directory(/opt/tomcat/latest/webpass), but it reports 'No such file or directory'.

Already find out what causes this, but don't know why. Jenkins don't use the same filesystem as original?

Here is my troubleshooting:

1、I create a directory in my linux server under / as temp20190808.

2、then in jenkins file add sh 'ls / -l', there is no temp20190808,also the description of each file in ls form show differenly compare with original(there are details under).

3、using jenkins file, i create a file under / as jenkinstmp2019, then ls / -l, it's there, but after rm the code of creating jenkinstmp2019, then rebuild, ls / -l, jenkinstmp2019 no longer there, so the jenkins file system is a onetime job?

Here are code elaboration on point 1,2:

in my linux server, using ls / -l, there is a tmp20190808 i just created.

total 24
lrwxrwxrwx.   1 root root    7 Jun 19 16:53 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Aug  1 04:55 boot
drwxr-xr-x.  17 root root 2860 Aug  7 02:48 dev
drwxr-xr-x.  86 root root 8192 Aug  7 20:52 etc
drwxr-xr-x.   4 root root   46 Jul 12 08:12 home
lrwxrwxrwx.   1 root root    7 Jun 19 16:53 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Jun 19 16:53 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Apr 11  2018 media
drwxr-xr-x.   2 root root    6 Apr 11  2018 mnt
drwxr-xr-x.   5 root root   53 Jul 23 08:11 opt
dr-xr-xr-x. 101 root root    0 Aug  7 02:47 proc
dr-xr-x---.   7 root root  215 Aug  6 02:53 root
drwxr-xr-x.  28 root root  920 Aug  8 02:03 run
lrwxrwxrwx.   1 root root    8 Jun 19 16:53 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Apr 11  2018 srv
dr-xr-xr-x.  13 root root    0 Aug  7 02:47 sys
drwxr-xr-x.   2 root root    6 Aug  8 01:50 temp1
drwxrwxrwt.  20 root root 4096 Aug  8 02:23 tmp
drwxr-xr-x.   2 root root   22 Aug  8 01:39 tmp20190808
drwxr-xr-x.  13 root root  155 Jun 19 16:53 usr
drwxr-xr-x.  20 root root 4096 Jul 12 07:36 var

in jenkins.

total 8448
drwxr-xr-x.   1 root root      19 Jun  9  2016 bin
drwxr-xr-x.   2 root root       6 May 30  2016 boot
-rw-------.   1 root root 8646656 Jun  9  2016 core
drwxr-xr-x.   5 root root     360 Aug  8 01:58 dev
drwxr-xr-x.   1 root root      66 Aug  8 01:58 etc
drwxr-xr-x.   2 root root       6 May 30  2016 home
drwxr-xr-x.   1 root root      45 Jun  9  2016 lib
drwxr-xr-x.   2 root root      34 Jun  8  2016 lib64
drwxr-xr-x.   2 root root       6 Jun  8  2016 media
drwxr-xr-x.   2 root root       6 Jun  8  2016 mnt
drwxr-xr-x.   2 root root       6 Jun  8  2016 opt
dr-xr-xr-x. 123 root root       0 Aug  8 01:58 proc
drwx------.   1 root root      33 Aug  8 01:58 root
drwxr-xr-x.   3 root root      30 Jun  8  2016 run
drwxr-xr-x.   2 root root    4096 Jun  8  2016 sbin
drwxr-xr-x.   2 root root       6 Jun  8  2016 srv
dr-xr-xr-x.  13 root root       0 Aug  7 02:47 sys
drwxrwxrwt.   1 root root      29 Jun  9  2016 tmp
drwxr-xr-x.   1 root root      30 Jun 10  2016 usr
drwxr-xr-x.   1 root root      41 Jun  9  2016 var

As you can see, it's like two totally different linux server, but it's the same one. So i'm wondering whether jenkins create a temp virtual file server to execute it's job, so can't access to original file except it's own directory.

Upvotes: 1

Views: 927

Answers (1)

Leon
Leon

Reputation: 11

Find out the reason by myself. The real cause is agent, i before used agent { docker { image 'XXX' } }, which makes jenkins run its job on docker image.Then i change it to agent any, so job will run on the server jenkins is deployed on.

Upvotes: 0

Related Questions