Limiting Jenkins pipeline to running only on specific nodes

You specify the desired node or tag when you do the node step:

node('specialSlave') {
   // Will run on the slave with name or tag specialSlave
}

See https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node for an extended explanation of the arguments to node.

Edit 2019: This answer (and question) was made back in 2017, back then there only was one flavor of Jenkins pipeline, scripted pipeline, since then declarative pipeline has been added. So above answer is true for scripted pipeline, for answers regarding declarative pipeline please see other answers below.


For the record let's have the declarative pipeline example here as well (choosing a node which has the label 'X'):

pipeline {
    agent { label 'X' }
...
...
}

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
  }
}