How to restrict the jenkins pipeline docker agent in specific slave?

后端 未结 2 1064

I have several jenkins slaves configured and only label with dockerserver has docker env, then how can I restrict the jenkins pipeline docker agent in this slav

2条回答
  •  孤城傲影
    2020-12-30 04:33

    Just had the same problem, seems to work for me like this:

    pipeline {
        agent { label 'dockerserver' } // if you don't have other steps, 'any' agent works
        stages {
            stage('Back-end') {
                agent {
                    docker {
                      label 'dockerserver'  // both label and image
                      image 'maven:3-alpine'
                    }
                }
                steps {
                    sh 'mvn --version'
                }
            }
            stage('Front-end') {
                agent {
                  docker {
                    label 'dockerserver'  // both label and image
                    image 'node:7-alpine' 
                  }
                }
                steps {
                    sh 'node --version'
                }
            }
        }
    }
    

提交回复
热议问题