Limiting Jenkins pipeline to running only on specific nodes

后端 未结 3 1623
南方客
南方客 2021-02-03 17:25

I\'m building jobs that will be using Jenkins piplines extensively. Our nodes are designated per project by their tags, but unlike regular jobs the pipeline build does not seem

3条回答
  •  后悔当初
    2021-02-03 18:04

    To be clear, because Pipeline has two Syntax, there are two ways to achieve that.

    Declarative

    pipeline {
        agent none
    
        stages {
            stage('Build') {
                agent { label 'slave-node​' }
                steps {
                    echo 'Building..'
                    sh '''
                    '''
                }
            }
        }
    
        post {
            success {
                echo 'This will run only if successful'
            }
        }
    }
    

    Scripted

    node('your-node') {
      try {
    
        stage 'Build'
        node('build-run-on-this-node') {
            sh ""
        }
      } catch(Exception e) {
        throw e
      }
    }
    

提交回复
热议问题