Two steps give a Scripted Pipeline its shape. node(label) takes an executor on a matching agent and a workspace for its block, the job of Declarative's agent; stage(name) names a block for the graph. Groovy variables declared with def flow freely between them:
node('linux') {
stage('Checkout') {
git url: 'https://github.com/binarybehemoth/booknest-jenkins.git', branch: 'main'
}
stage('Inspect') {
def count = sh(script: 'grep -c \'"title"\' db/seed.json', returnStdout: true).trim()
echo "BookNest has ${count} books on ${env.NODE_NAME}"
}
}Output
Running on agent-1 in /home/jenkins/agent/workspace/scr-basic ... BookNest has 6 books on agent-1 Finished: SUCCESS
Code outside any node runs on the controller's flyweight executor (Executors and the Build Queue) and cannot touch files, so a Scripted Pipeline decides for itself when to hold an executor.