【发布时间】:2019-02-20 23:17:51
【问题描述】:
我在 dockerhub 中有一个 docker 映像,我想将它作为代理添加到我的 jenkins 管道脚本中。作为图像的一部分,我执行 git clone 以从 github 获取一个存储库,该存储库具有多个 python 脚本,这些脚本对应于我的 jenkins 管道中的多个阶段。我尝试到处搜索,但找不到有关如何访问 jenkins 管道中 docker 容器内文件的相关信息。
我在虚拟机上运行 jenkins,它安装了 docker。管道在 docker 容器上执行构建。由于管道的每个阶段都涉及许多步骤,因此我尝试尽可能多地使用 python API。
这就是我的 dockerfile 的样子,并且图像构建成功,我可以将它托管在 dockerhub 中。当我运行容器时,我可以看到“jenkins_pipeline_scripts”目录,其中包含管道阶段所需的所有 Python 脚本。
FROM ros:melodic-ros-core-stretch
RUN apt-get update && apt-get -y install python-pip
RUN git clone <private-repo with token>
这就是我当前的 jenkins 管道脚本的样子。
pipeline {
agent {
docker {
image '<image name>'
registryUrl 'https://registry.hub.docker.com'
registryCredentialsId 'docker-credentials'
args '--network host -u root:root'
}
}
stages {
stage('Test') {
steps {
sh 'python jenkins_pipeline_scripts/scripts/test.py'
}
}
}
}
这是我在执行作业时遇到的错误。
$ docker top 05587cd75db5c4282b86b2f1ded2c43a0f4eae161d6c7d7c03d065b0d45e1 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
+ python jenkins_pipeline_scripts/scripts/test.py
python: can't open file 'jenkins_pipeline_scripts/scripts/test.py': [Errno 2] No such file or directory
【问题讨论】:
-
请给Jenkins的所有控制台输出
标签: python docker jenkins jenkins-pipeline