简体   繁体   English

是否可以在代理内的代理上执行 Jenkins 管道?

[英]Is it possible to execute Jenkins pipeline on an agent, within an agent?

Specifically, every build I want to hand off to an Agent on a VM and then that agent will send the pipeline to be executed and built entirely within a docker agent具体来说,我想将每个构建移交给 VM 上的代理,然后该代理将发送管道以完全在 docker 代理中执行和构建

I am not sure I entirely understand the question, but yes you can run docker containers "agents" inside an agent.我不确定我是否完全理解这个问题,但是是的,您可以在代理中运行 docker 容器“代理”。

eg here I select a docker capable agent to run the build and then use a Python container to run certain steps例如,在这里我 select 一个 docker 能够运行构建的代理,然后使用 Python 容器运行某些步骤

pipeline {
    agent { label "docker-capable" }
    options {
        timestamps()
    }
    stages {
        stage("Build the Lambda") { // Runs in container on agent
            agent {
                docker {
                    image "python:3.7"
                    reuseNode true
                    args "-v /usr/bin/zip:/usr/bin/zip"
                }
            }
            environment {
                HOME = "/tmp"
            }
            steps {
                sh "make release"
            }
        }
        stage("Release if Required") { //Runs on agent
            when {
                anyOf {
                    branch 'master'
                    branch 'main'
                }
                not { buildingTag() }
            }
            steps {
                script {
                    publishRelease()
                }
            }
        }

You can run multiple stages in the same container too eg您也可以在同一个容器中运行多个阶段,例如

        stage("Python Module Testing") {
            agent {
                docker {
                    image "python:3.7"
                    reuseNode true
                }
            }
            environment {
                HOME = "/tmp"
                // Resolve dependencies
                PYTHONPATH = "${WORKSPACE}/package"
            }
            stages {
                stage("Deps") {
                    steps {
                        sh("pip install --user --no-cache-dir pylint flake8")
                    }
                }
                stage("Pylint") {
                    steps {
                        sh("pylint .")
                    }
                }
                stage("Flake8") {
                    steps {
                        sh("flake 8 .")
                    }
                }

If you mean can you run some stages on 1 agent and some stages on another agent, then also yes you just dont specify and agent block at the top of the pipeline, but do it for each stage.如果您的意思是您可以在 1 个代理上运行一些阶段,而在另一个代理上运行一些阶段,那么您也可以在管道顶部不指定和代理阻止,而是为每个阶段执行此操作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM