我使用Jenkins Docker插件来构建我的图像(这个工作),我可以使用像
这样的命令运行容器 docker run test-env:latest /etc/bootstrap.sh -jenkins
然而,当我跑
时 docker run -u root -v $WORKSPACE:/test test-env:latest /etc/bootstrap.sh -jenkins
我遇到了一些问题。卷/测试存在于容器中,但它不包含$ WORKSPACE所具有的任何文件。在运行我的docker容器之前,我做了一个
cd $WORKSPACE && ls -al
显示以下内容:
total 52
drwxr-xr-x 10 root root 4096 Sep 3 15:49 .
drwxr-xr-x 3 root root 4096 Sep 3 15:49 ..
drwxr-xr-x 8 root root 4096 Sep 3 15:49 .git
-rw-r--r-- 1 root root 361 Sep 3 15:49 .gitignore
-rw-r--r-- 1 root root 71 Sep 3 15:49 README.md
drwxr-xr-x 3 root root 4096 Sep 3 15:49 bin
-rw-r--r-- 1 root root 1900 Sep 3 15:49 build.sbt
drwxr-xr-x 3 root root 4096 Sep 3 15:49 conf
drwxr-xr-x 2 root root 4096 Sep 3 15:49 docs
drwxr-xr-x 2 root root 4096 Sep 3 15:49 lib
drwxr-xr-x 2 root root 4096 Sep 3 15:49 project
drwxr-xr-x 3 root root 4096 Sep 3 15:49 scripts
drwxr-xr-x 4 root root 4096 Sep 3 15:49 src
并且看到我要与容器共享的git存储库(test_repo)是否包含所有正确的文件,但是当我这样做时在容器内
cd /test && ls -al
我所看到的只是
total 16
drwxr-xr-x 4 root root 4096 Sep 2 14:30 .
drwxr-xr-x 1 root root 4096 Sep 3 10:27 ..
drwxr-xr-x 3 root root 4096 Sep 2 13:26 test_repo
drwxr-xr-x 5 root root 4096 Sep 2 14:30 target
这两个代码都不包含我的代码,我通过使用$ WORKSPACE / test_repo和$ WORKSPACE / target作为我安装的卷进行了进一步测试。
为什么容器中没有可见的$ WORKSPACE文件?我怎样才能让它正常工作?
编辑:$ WORKSPACE = / var / tmp / workspace / test-jenkins的值,其中test-jenkins是我的Jenkins工作的名称