简体   繁体   English

在特定代理 Jenkins 中的 docker 容器内运行作业

[英]Run job inside docker container in specific agent Jenkins

I am trying to run the Jenkins pipeline steps in the Docker container in a specific agent.我正在尝试在特定代理中的 Docker 容器中运行 Jenkins 管道步骤。 I could use docker to run it but the container will run in a random agent but i need it to run in specific agent.我可以使用 docker 来运行它,但容器将在随机代理中运行,但我需要它在特定代理中运行。

Here's what i tried:这是我尝试过的:

pipeline {
    agent { label 'agent-007' }

    stages {            
        stage("Unit Tests") {
          agent { docker 'image-name' }
          steps {
            sh 'pwd'
            sh 'hostname'
          }
        }
    }
    
}

In the documentation Specifying a Docker Label it says that in the configuration for your Jenkins job, you can specify which agent you want docker to run on. In the documentation Specifying a Docker Label it says that in the configuration for your Jenkins job, you can specify which agent you want docker to run on. In your case, you could set "Docker Label" to "agent-007" in your job configuration.在您的情况下,您可以在作业配置中将“Docker Label”设置为“agent-007”。 You can also specify which docker registry you want to pull from which is really handy if you use Artifactory, for instance.例如,如果您使用 Artifactory,您还可以指定要从中提取的 docker 注册表非常方便。

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

相关问题 Jenkins 无法在具有特定运行 arguments 的声明性管道中启动 docker 代理容器 - Jenkins cannot start a docker agent container in declarative pipeline with specific run arguments 如何在 docker 容器中运行 cron 作业? - How to run a cron job inside a docker container? 如何在 Jenkins 的 docker 容器中运行构建? - How to run the build inside docker container in Jenkins? 如何在 docker 容器内运行 cron 作业 - How to run a cron job inside a docker container Docker jenkins ssh-agent“不在容器内运行”在 Ubuntu 22.04 - Docker jenkins ssh-agent "not running inside container" on Ubuntu 22.04 是否有任何配置可以在 jenkins 容器内运行 docker? - Is there any configuration to run docker inside a jenkins container? 在容器中运行 Jenkins 作业 - Run Jenkins Job in a container 在 docker 容器中运行 jenkins 代理,问题与 jenkins 管道和 /var/run/docker.socket - Run jenkins agent in docker container, issue with jenkins pipeline and /var/run/docker.socket 在Centos7上使用jenkins容器内的jenkins用户运行docker - Run docker with jenkins user inside jenkins container on Centos7 Jenkins:从与代理(另一个 Docker 容器)一起运行的阶段连接到 Docker 容器 - Jenkins: Connect to a Docker container from a stage that is run with an agent (another Docker container)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM