Use a lightweight executor for a declarative pipeline stage (agent none)

前端 未结 2 1516
盖世英雄少女心
盖世英雄少女心 2020-12-14 08:02

I\'m using Jenkins Pipeline with the declarative syntax, currently with the following stages:

  1. Prepare
  2. Build (two parallel sets of steps)
  3. Test
2条回答
  •  Happy的楠姐
    2020-12-14 08:24

    There is a workaround to use the same build slave in the other stages. You can set a variable with the node name and use it in the others.

    ie:

    pipeline {
        agent none
        stages {
            stage('First Stage Gets Agent Dynamically') {
                agent {
                    node {
                        label "some-agent"
                    }
                }
                steps {
                    echo "first stage running on ${NODE_NAME}"
                    script {
                      BUILD_AGENT = NODE_NAME
                    }
                }
            }
            stage('Second Stage Setting Node by Name') {
                agent {
                    node {
                        label "${BUILD_AGENT}"
                    }
                }
                steps {
                    echo "Second stage using ${NODE_NAME}"
                }
            }
        }
    }
    

提交回复
热议问题