Skip to content
Latchkey

Jenkins "WorkflowScript: unexpected token" Jenkinsfile Parse Error

Jenkins could not parse your Jenkinsfile. The Groovy compiler hit a token it did not expect, so the pipeline failed before any stage executed.

What this error means

The build fails immediately at "Loading pipeline" with a WorkflowScript compilation error pointing at a line and column. No stage runs, and the same file fails identically every time.

jenkins
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 18: unexpected token: } @ line 18, column 1.
   }
   ^

1 error

Common causes

Unbalanced braces or parentheses

A missing or extra } or ) from an edited stage or steps block shifts the parser, which reports the error a few lines after the real mistake.

Broken string quoting

An unterminated "..." or a ${...} interpolation inside single quotes confuses the lexer and produces an unexpected-token error.

A directive in the wrong place

Putting a step outside steps {}, or environment / when in an invalid position, breaks the declarative grammar.

How to fix it

Validate the Jenkinsfile with the linter

  1. Run the pipeline-model-converter validator, which uses the same parser as the build.
  2. Read the exact line and column it reports.
Terminal
curl -X POST -F "jenkinsfile=<Jenkinsfile" https://jenkins.example.com/pipeline-model-converter/validate

Balance braces and fix quoting

  1. Open the reported line, then scan upward for the unclosed {, (, or string.
  2. Use double quotes when you need ${...} interpolation; single quotes are literal.
  3. Re-indent so block boundaries are visible.

How to prevent it

  • Lint the Jenkinsfile in a pre-merge check and keep it small, moving logic into a unit-testable shared library.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →