我创建了一个python包(用于在jenkins中自动化构建阶段),可以使用pip进行安装。我还创建了一个dockerfile,它将从github克隆python包,执行pip install并导出容器中安装可执行文件(入口点,不管你怎么叫它)的路径(示例:~/.local/bin)。这是我的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。这是我的jenkins管道脚本的样子
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和其他几个脚本(它们是作为Robot操作系统的~/.local/bin中另一个pip包的一部分安装的脚本)是如何在管道中工作的,而不是我通过pip安装的脚本。如果你能帮我指出我错过了什么,我将不胜感激。
谢谢。非常感谢您的帮助。
发布于 2019-02-23 09:17:25
抱歉的。解决方案非常简单。我犯的错误是我更新了dockerfile并创建了一个新的镜像,将其推送到dockerhub,但忘记了修剪和更新Jenkins master运行的实例中的最新副本。所以基本上我的dockerhub只有一个版本。101和我创建dockerfile和docker镜像的本地机器的版本。101。但是Jenkins的主人是52版本的。所以,即使我做了修改,更新后的图像也不是由Jenkins master拉出来的,就这样吧!这是我犯的一个愚蠢的错误。我感谢你们每一个人在这里帮助我。安息吧!
https://stackoverflow.com/questions/54833546
复制相似问题