jenkinsfile pipeline grouping stages by agent

后端 未结 1 603
长情又很酷
长情又很酷 2021-02-10 01:27

What do I have

I am trying to run my jenkins pipeline using two different agents. I want to execute some process on the same agent but so far I am unable to do this be

相关标签:
1条回答
  • 2021-02-10 02:16

    Check out the new (July 2018) Sequential Stages in Declarative Pipeline 1.3:

    Running Multiple Stages with the Same agent, or environment, or options

    While the sequential stages feature was originally driven by users wanting to have multiple stages in parallel branches, we’ve found that being able to group multiple stages together with the same agent, environment, when, etc has a lot of other uses.

    For example, if you are using multiple agents in your Pipeline, but would like to be sure that stages using the same agent use the same workspace, you can use a parent stage with an agent directive on it, and then all the stages inside its stages directive will run on the same executor, in the same workspace.

    pipeline {
        agent none
    
        stages {
            stage("build and test the project") {
                agent {
                    docker "our-build-tools-image"
                }
                stages {
                   stage("build") {
                       steps {
                           sh "./build.sh"
                       }
                   }
                   stage("test") {
                       steps {
                           sh "./test.sh"
                       }
                   }
                }
                post {
                    success {
                        stash name: "artifacts", includes: "artifacts/**/*"
                    }
                }
            }
    
    0 讨论(0)
提交回复
热议问题