[英]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.