不能用root docker代理从声明管道启动随机代理

问题描述 投票:0回答:1

或此脚本管道版本

node {
  withDockerContainer(image: 'debian:stable', args: '-v /var/run/docker.sock:/var/run/docker.sock') {
    stage("first") {
      sh 'bash --version'
    }

    node {
      stage("second") {
        sh "bash --version"
      }
    }
  }
}

在这条管道中,我们希望第二阶段以与根,docker的不同代理运行。但是,这个第二阶段的步骤从未运行,至少在詹金斯设置我的公司正在运行的情况下。

一些日志:
Pull request #17677 updated
...
[Pipeline] Start of Pipeline
[Pipeline] milestone
Trying to pass milestone 51
[Pipeline] node
Running on jenkins-agent-n2-custom-8-32768-hswu4b
 in /tmp/....
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: git
using credential github-blablacarbot-ssh
Fetching changes from the remote Git repository
Fetching without tags
...
[GitHub Checks] GitHub check (name: Jenkins, status: in_progress) has been published.
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . debian:stable
.
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withDockerContainer
jenkins-agent-n2-custom-8-32768-hswu4b does not seem to be running inside a container
$ docker run -t -d -u 0:0 -v /var/run/docker.sock:/var/run/docker.sock -w ... debian:stable cat
$ docker top c67eb42eef77ae16fce698c21eabbcb14d8e6591130429ce2413bd57dc7e02f8 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (On root agent)
[Pipeline] sh
+ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (On other agent)
[Pipeline] node
Running on jenkins-agent-n2-custom-8-32768-8cbh5v
 in /tmp...
[Pipeline] {
[Pipeline] checkout
The recommended git tool is: git
...
[GitHub Checks] GitHub check (name: Jenkins, status: in_progress) has been published.
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
process apparently never started in /tmp/...
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 c67eb42eef77ae16fce698c21eabbcb14d8e6591130429ce2413bd57dc7e02f8
$ docker rm -f --volumes c67eb42eef77ae16fce698c21eabbcb14d8e6591130429ce2413bd57dc7e02f8
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code -2
[GitHub Checks] GitHub check (name: Jenkins, status: completed) has been published.

GitHub has been notified of this commit’s build result

Finished: FAILURE

为什么在第二代理中无法开始的过程?

在现实生活中,我正在为性能目的探索此选项:我的大多数阶段都可以在同一代理上运行(因此,让我们使用root One阶段,以便不必为每个阶段弹出一个新的阶段) ,但是在另一个代理商中孤立的跑步阶段可以受益。
    

我记得遇到了同样的问题,甚至认为它在某个时间之前正在工作。事实证明,在不同代理商上运行管道jenkins的管道(至少是根据文档

)只提供了两个选项:

jenkins jenkins-pipeline
1个回答
0
投票
在顶级使用

agent none

定义管道的顶部级别可确保不会不必要地分配执行人。使用
    agent none
  • 还强迫每个阶段部分包含自己的
    agent none
    部分。

    使用一些代理,但不能使用
    agent
    块。可以将其与
    docker { ... }
    优化资源分配和性能相结合:
    

    REUSENODE
  • a布尔,默认情况下是错误的。如果为true,请在管道顶部指定的节点上运行容器,在同一工作空间中,而不是完全在新节点上。
    
    此选项对
    reuseNode
    docker

    有效,只有在用于单个阶段的代理时才有效。

    我也建议不要使用

    dockerfile

    ,因为它使构建环境未知,最终可能导致错误而不可重现的构建。

    所以,您的管道看起来像这样:

    agent any
    或这样 - 

    但这会浪费遗嘱执行人
    ,因此只有在您不需要运行Docker容器中的大部分阶段时才有意义:
pipeline { agent none stages { stage('On standard agent') { agent { docker { label 'standard' image 'debian:stable' args '-v /var/run/docker.sock:/var/run/docker.sock' } } steps { sh 'bash --version' } } stage('On other agent') { agent { docker { label 'other' image 'some-other-image:1.0.0' args '-v /var/run/docker.sock:/var/run/docker.sock' } } steps { sh ''' bash --version ''' } } } }

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.