Job DSL Restrict jobs to selected nodes

groovy, jenkins, jenkins-job-dsl

Solution

The `label` method sets the `Restrict where this project can run` on job level:

job('example') {
    label('agentA agentB')
}

See the API viewer for details: https://jenkinsci.github.io/job-dsl-plugin/#path/job-label

Problem

I am struggling to restrict Jenkins job to specific nodes using Job DSL plugin. I tried something like : ``` job("campaign") { parameters { stringParam("ARTIFACT_NUMBER", "","") nodeParam('TEST_HOST') { defaultNodes(["Slave"]) } } steps { shell('''#!/bin/bash ARTIFACT_DIR=daily_${ARTIFACT_NUMBER} echo ${ARTIFACT_DIR} ''') } } ``` but no success. Basically, I want to set the property `Restrict where this project can run` through Job DSL plugin

Original source