Interview Prep/Jenkins/Jenkinsfile syntax, Groovy & CPS errors

`WorkflowScript: 1: Missing required section "agent" @ line 1, column 1.`

BeginnerTroubleshootingJenkinsfile syntax, Groovy & CPS errors
Answer

Likely causes → The declarative pipeline {} block has no top-level agent, or it was put inside stages.

Diagnose →

curl -s -X POST -u alice:$TOKEN -F "jenkinsfile=<Jenkinsfile" https://jenkins/pipeline-model-converter/validate

Fix → Add agent any, agent none (with per-stage agents) or a specific agent directly under pipeline {.

Prevent → Lint Jenkinsfiles in a pre-commit hook or PR check with the validate endpoint.

All Jenkins questions Roadmap: Jenkins

More on Jenkinsfile syntax, Groovy & CPS errors