【发布时间】:2019-02-22 19:03:17
【问题描述】:
我创建了一个可以使用 pip 安装的 python 包(用于自动化 jenkins 中的构建阶段)。我还创建了一个 dockerfile,它将从 github 克隆 python 包,执行 pip install 并导出在容器中安装可执行文件(入口点,但是你想调用它)的路径(例如:~/.local/斌)。这就是我的 dockerfile 的样子。
FROM ros:melodic-ros-core-stretch
RUN apt-get update && apt-get -y install python-pip
RUN git clone <private-repo-with-personal-access-token>
RUN pip install <package-name>
RUN export PATH=~/.local/bin:$PATH
所以我构建了这个镜像,运行了容器并输入了一个打印 hello world 的可执行文件(入口点)。工作得很好。对此没有任何问题。谈到全局,我想在 jenkins 管道中调用这个可执行文件(入口点)。我最初遇到了一个问题,然后我了解到 jenkins 管道在使用 docker 映像设置时运行在容器顶部,但使用为 jenkins 分配的工作空间,即 /var/lib/jenkins/workspace。这就是我的詹金斯管道脚本的样子
pipeline {
agent {
docker {
args '--network host -u root:root'
image '<private-docker-hub-image>'
registryCredentialsId 'docker-credentials'
registryUrl 'https://registry.hub.docker.com'
}
}
stages {
stage('Test') {
steps {
sh 'test-build'
}
}
}
}
这是我遇到的错误。
Started by user Automated Build Environment
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/First_item
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withDockerRegistry
$ docker login -u <docker username> -p ******** https://registry.hub.docker.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /var/lib/jenkins/workspace/First_item@tmp/251189be-62eb-4134-84ca-d70190ab080f/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . <private-dockerhub-image>
Error: No such object: <private-dockerhub-image>
[Pipeline] sh
+ docker inspect -f . registry.hub.docker.com/<private-dockerhub-image>
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 125:130 --network host -u root:root -v /var/lib/jenkins:/var/lib/jenkins -w /var/lib/jenkins/workspace/First_item -v /var/lib/jenkins/workspace/First_item:/var/lib/jenkins/workspace/First_item:rw,z -v /var/lib/jenkins/workspace/First_item@tmp:/var/lib/jenkins/workspace/First_item@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** registry.hub.docker.com/<private-dockerhub-image> cat
$ docker top ab1f2ec9b503f9b916ee96943dc849acc90716f7543b4841ff3901b7a65aea54 -eo pid,comm
[Pipeline] {
[Pipeline] stage (hide)
[Pipeline] { (Test)
[Pipeline] sh
+ test-build
/var/lib/jenkins/workspace/First_item@tmp/durable-7cb108f7/script.sh: 1: /var/lib/jenkins/workspace/First_item@tmp/durable-7cb108f7/script.sh: test-build: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 ab1f2ec9b503f9b916ee96943dc849acc90716f7543b4841ff3901b7a65aea54
$ docker rm -f ab1f2ec9b503f9b916ee96943dc849acc90716f7543b4841ff3901b7a65aea54
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
我的问题是 rosdep、bloom-generate 和其他几个脚本(足以知道这些脚本是作为机器人操作系统中 ~/.local/bin 中另一个 pip 包的一部分安装的脚本)在管道中工作,但是不是我通过 pip 安装的脚本。我非常感谢任何帮助指出我所缺少的东西。
谢谢。非常感谢您的帮助。
【问题讨论】:
-
你能展示你的 Dockerfile 吗?
-
就在上面。我已经有了。
-
如错误信息所述,在 Jenkins Pipeline 中运行的环境的 PATH 中没有
test-build命令。 -
@MattSchuchard,谢谢您的回答。我可以理解在 jenkins 管道环境中没有测试构建。我发布了寻找解决方案的问题。
标签: python docker jenkins jenkins-pipeline ros