简体   繁体   English

Jenkins 总是从声明性管道代理定义中提取 docker 镜像

[英]Jenkins always pull docker image from a declarative pipeline agent definition

I have a working Jenkins pipeline defined with agent {any} .我有一个使用agent {any}定义的工作 Jenkins 管道。

But I want to try running the tests on a docker image.但我想尝试在 docker 镜像上运行测试。 According to documentation I can do that the following way:根据文档,我可以通过以下方式做到这一点:

pipeline {
     agent {
         docker { image 'centos/python-27-centos7:latest' }
     }
     stages {
        ...
     }
}

The problem is that my instance of Jenkins is offline and with this configuration it will try to docker pull the image when running the project.问题是我的 Jenkins 实例处于离线状态,使用此配置,它会在运行项目时尝试docker pull图像。

However I have the centos/python-27 image loaded in the docker (visible with docker images and it can be run with docker run -i -t centos/python-27-centos7 /bin/bash但是,我在 docker 中加载了 centos/python-27 图像(通过docker images可见,它可以通过docker run -i -t centos/python-27-centos7 /bin/bash

Is there any way I can configure the agent in Jenkins so it doesn't try to pull the image from Docker Hub?有什么方法可以在 Jenkins 中配置代理,使其不会尝试从 Docker Hub 中pull图像?

The Docker agent has an alwaysPull flag you can set to false or true : Docker 代理有一个alwaysPull标志,您可以将其设置为falsetrue

agent {
  docker {
    alwaysPull false
    image 'foo/bar'
  }
}

Jenkins has a Pipeline Syntax Generator that can help in these cases. Jenkins 有一个 Pipeline Syntax Generator 可以在这些情况下提供帮助。 In the Job menu on the left side, there is an icon for "Pipeline Syntax".在左侧的 Job 菜单中,有一个“Pipeline Syntax”图标。

在此处输入图片说明

There you can see some settings to help you generate your pipeline directives.在那里您可以看到一些设置来帮助您生成管道指令。

在此处输入图片说明

You could try to use a dockerfile agent.您可以尝试使用 dockerfile 代理。 If everything you need to build the image is local, then you won't have to be online.如果构建映像所需的一切都是本地的,那么您就不必在线了。

pipeline {
 agent {
   dockerfile {
     filename "someOtherDockerfile"
     label "docker-nodes"
     args "-v /tmp:/tmp"
   }
 }
 stages {
    ...
 }

Your other option is possibly setting up a private docker registry.您的另一个选择可能是设置私有 docker 注册表。 https://docs.docker.com/registry/deploying/ https://docs.docker.com/registry/deploying/

You should us siblings instead of nested container images.你应该我们兄弟姐妹而不是嵌套的容器图像。 ie Try to mount the volume of docker daemon sockets to the Jenkins container via -v /var/run/docker.sock:/var/run/docker.sock .即尝试通过-v /var/run/docker.sock:/var/run/docker.sock将 docker 守护进程套接字的卷挂载到 Jenkins 容器。 This way, you will get access to the images available on your host system.这样,您就可以访问主机系统上可用的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过 Jenkins 声明性管道在 Docker 映像中作为代理安装 pip - Unable to pip install in Docker image as agent through Jenkins declarative pipeline 带有来自 SCM 的 Docker/Dockerfile 代理的 Jenkins 声明式管道 - Jenkins declarative pipeline with Docker/Dockerfile agent from SCM 声明性管道中的 Jenkins docker 代理:找不到文件 - Jenkins docker agent in declarative pipeline: file not found 声明式 Jenkins 管道和 Docker - Declarative Jenkins pipeline and Docker 如何在Jenkins声明式管道中从docker hub推入和拉出 - How do I push and pull from docker hub in Jenkins declarative pipeline Jenkins 声明式管道 - 将 Docker 映像推送到私有 docker hub 存储库 - Jenkins declarative pipeline - push Docker image to private docker hub repo Jenkins Golang 声明式管道:构建 Docker 镜像并推送到 Docker Hub - Jenkins Golang Declarative Pipeline: Build Docker Image and Push to Docker Hub 如何在 Jenkins 声明性管道中将人工制品从一个代理复制到另一个代理? - How to copy an artefact from one agent to another in a Jenkins declarative pipeline? Jenkins 声明性 docker 管道与 angular - Jenkins declarative docker Pipeline with angular 将配置文件从 Dockerfile 插入到声明性 Jenkins 管道 Docker 容器中 - Insert a config file into a declarative Jenkins pipeline Docker container from Dockerfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM