Skip to content

ClassCastException when parsing yaml #123

@fmotalleb

Description

@fmotalleb

Jenkins and plugins versions report

The Pipeline as YAML plugin in Jenkins fails to parse Jenkinsfile.yaml, resulting in a ClassCastException:

class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')

This issue occurs when attempting to:

  • Validate YAML syntax using the Pipeline Syntax Generator
  • Run a pipeline in a Jenkins project

Full Error:
The stack trace points to a type mismatch in TriggersModel.toGroovy(), indicating that the plugin expects a String but encounters a LinkedHashMap.

00:00:00.017  java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')
00:00:00.017  	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
00:00:00.017  	at java.base/java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
00:00:00.017  	at PluginClassLoader for pipeline-as-yaml//io.jenkins.plugins.pipeline.models.TriggersModel.toGroovy(TriggersModel.java:29)
00:00:00.017  	at java.base/java.util.Optional.map(Unknown Source)
00:00:00.017  	at PluginClassLoader for pipeline-as-yaml//io.jenkins.plugins.pipeline.models.PipelineModel.toGroovy(PipelineModel.java:40)
00:00:00.017  	at PluginClassLoader for pipeline-as-yaml//io.jenkins.plugins.pipeline.models.PipelineModel.toPrettyGroovy(PipelineModel.java:53)
00:00:00.017  	at PluginClassLoader for pipeline-as-yaml//io.jenkins.plugins.pipeline.cps.PipelineCpsFlowDefinition.create(PipelineCpsFlowDefinition.java:44)
00:00:00.017  	at PluginClassLoader for pipeline-as-yaml//io.jenkins.plugins.pipeline.PipelineAsYamlScriptFlowDefinition.create(PipelineAsYamlScriptFlowDefinition.java:57)
00:00:00.017  	at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:319)
00:00:00.017  	at hudson.model.ResourceController.execute(ResourceController.java:101)
00:00:00.017  	at hudson.model.Executor.run(Executor.java:446)
00:00:00.026  Finished: FAILURE

Sample Curl request:

curl 'https://jenkins.org.local/$stapler/bound/---/parseAndValidatePay' \
  --data-raw $'["pipeline:\\n  agent:\\n    label: Docker\\n  triggers:\\n    - cron: \\"H 0 * * 5\\"\\n  stages:\\n    - stage: Build\\n      steps:\\n        - script:\\n            - sh \'./build.sh dry\'\\n            - sh \'./build.sh build\'"]'

Additional Context:

  • We are using worker nodes, but the issue seems unrelated to agent execution and occurs at the YAML parsing stage.
Environment
Jenkins: 2.492.1
OS: Linux - 6.8.0-52-generic
Java: 21.0.6 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)
---
ansicolor:1.0.6
antisamy-markup-formatter:162.v0e6ec0fcfcf6
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.4-136.v5a_21779c63f8
asm-api:9.7.1-97.v4cc844130d97
authentication-tokens:1.119.v50285141b_7e1
badge:2.5
basic-branch-build-strategies:190.v343a_ee70d920
better-pipeline-flowgraph-table:1.5.vd6dfd1f235cb_
blueocean:1.27.16
blueocean-bitbucket-pipeline:1.27.16
blueocean-commons:1.27.16
blueocean-config:1.27.16
blueocean-core-js:1.27.16
blueocean-dashboard:1.27.16
blueocean-display-url:2.4.3
blueocean-events:1.27.16
blueocean-git-pipeline:1.27.16
blueocean-github-pipeline:1.27.16
blueocean-i18n:1.27.16
blueocean-jira:1.27.16
blueocean-jwt:1.27.16
blueocean-personalization:1.27.16
blueocean-pipeline-api-impl:1.27.16
blueocean-pipeline-editor:1.27.16
blueocean-pipeline-scm-api:1.27.16
blueocean-rest:1.27.16
blueocean-rest-impl:1.27.16
blueocean-web:1.27.16
bootstrap5-api:5.3.3-1
bouncycastle-api:2.30.1.80-256.vf98926042a_9b_
branch-api:2.1208.vf528356feca_4
build-name-setter:2.4.3
build-timeout:1.35
caffeine-api:3.1.8-133.v17b_1ff2e0599
checks-api:2.2.2
cloud-stats:377.vd8a_6c953e98e
cloudbees-bitbucket-branch-source:934.4.2
cloudbees-folder:6.980.v5a_cc0cb_25881
command-launcher:118.v72741845c17a_
commons-compress-api:1.27.1-2
commons-lang3-api:3.17.0-84.vb_b_938040b_078
commons-text-api:1.13.0-153.v91dcd89e2a_22
compress-artifacts:112.v52b_808b_85a_e8
conditional-buildstep:1.5.0
config-file-provider:982.vb_a_e458a_37021
configuration-as-code:1932.v75cb_b_f1b_698d
copyartifact:763.v66351b_9c297f
credentials:1408.va_622a_b_f5b_1b_1
credentials-binding:687.v619cb_15e923f
dark-theme:524.vd675b_22b_30cb_
dashboard-view:2.528.v3470c02b_d7c9
data-tables-api:2.1.8-1
display-url-api:2.209.v582ed814ff2f
docker-commons:445.v6b_646c962a_94
docker-java-api:3.4.1-96.v77147a_de67f8
docker-plugin:1.9.0
docker-workflow:592.v1001d948426c
durable-task:581.v299a_5609d767
echarts-api:5.5.1-5
eddsa-api:0.3.0-4.v84c6f0f4969e
email-ext:1876.v28d8d38315b_d
embeddable-build-status:548.v5653c6e28c41
emoji-symbols-api:16.0-26.v9818ff7423f0
enhanced-credentials:1.2
envinject:2.926.v69c9b_3896a_96
envinject-api:1.235.va_14c74f8f487
favorite:2.225.v68765b_b_a_1fa_3
file-operations:331.v9d88a_0206e2e
flatpickr-api:4.6.13-15.vf6e534338831
font-awesome-api:6.6.0-2
forensics-api:2.7.0
generic-webhook-trigger:2.3.0
git:5.7.0
git-client:6.1.1
git-parameter:0.11.0
github:1.41.0
github-api:1.321-478.vc9ce627ce001
github-branch-source:1810.v913311241fa_9
gitlab-api:5.6.0-97.v6603a_83f8690
gitlab-branch-source:718.v40b_5f0e67cd3
gitlab-plugin:1.9.7
global-build-stats:316.vf8870f424d78
groovy:457.v99900cb_85593
gson-api:2.12.1-113.v347686d6729f
handy-uri-templates-2-api:2.1.8-30.v7e777411b_148
htmlpublisher:1.37
http_request:1.20
inline-pipeline:1.0.3
instance-identity:201.vd2a_b_5a_468a_a_6
ionicons-api:74.v93d5eb_813d5f
jackson2-api:2.17.0-379.v02de8ec9f64c
jakarta-activation-api:2.1.3-1
jakarta-mail-api:2.1.3-1
javax-activation-api:1.2.0-7
javax-mail-api:1.6.2-10
jaxb:2.3.9-1
jdk-tool:83.v417146707a_3d
jenkins-design-language:1.27.16
jersey2-api:2.45-154.v4ded3dc34f81
jira:3.13
jjwt-api:0.11.5-112.ve82dfb_224b_a_d
jobConfigHistory:1302.va_65b_ccb_fde71
jobcacher:589.v10419b_45a_a_72
joda-time-api:2.13.1-115.va_6b_5f8efb_1d8
jquery3-api:3.7.1-2
jsch:0.2.16-86.v42e010d9484b_
json-api:20250107-125.v28b_a_ffa_eb_f01
json-path-api:2.9.0-138.vc943da_d833b_6
junit:1314.vd966e9a_88895
lockable-resources:1349.v8b_ccb_c5487f7
mailer:489.vd4b_25144138f
matrix-auth:3.2.4
matrix-project:845.vffd7fa_f27555
metrics:4.2.21-461.v881e35d8fa_b_a_
mina-sshd-api-common:2.14.0-143.v2b_362fc39576
mina-sshd-api-core:2.14.0-143.v2b_362fc39576
multibranch-action-triggers:1.8.10
multibranch-build-strategy-extension:60.vce1b_19770361
nodejs:1.6.3
okhttp-api:4.11.0-183.va_87fc7a_89810
outbound-webhook:0.3.0
parameterized-trigger:840.v3c7d4a_a_5e6c7
people-view:1.2
pipeline-aggregator-view:119.v4b_ec11953552
pipeline-as-yaml:246.veb_b_2e368b_395
pipeline-build-step:555.v589d5c24a_3d6
pipeline-graph-analysis:216.vfd8b_ece330ca_
pipeline-graph-view:409.v98f212e980b_4
pipeline-groovy-lib:752.vdddedf804e72
pipeline-input-step:508.v584c0e9a_2177
pipeline-milestone-step:119.vdfdc43fc3b_9a_
pipeline-model-api:2.2221.vc657003fb_d93
pipeline-model-definition:2.2221.vc657003fb_d93
pipeline-model-extensions:2.2221.vc657003fb_d93
pipeline-rest-api:2.35
pipeline-stage-step:312.v8cd10304c27a_
pipeline-stage-tags-metadata:2.2221.vc657003fb_d93
pipeline-stage-view:2.35
pipeline-utility-steps:2.18.0
plain-credentials:183.va_de8f1dd5a_2b_
plot:2.3.0
plugin-usage-plugin:4.8
plugin-util-api:5.1.0
prism-api:1.29.0-18
prometheus:811.v1823c780b_e8e
pubsub-light:1.18
rebuild:332.va_1ee476d8f6d
resource-disposer:0.25
role-strategy:756.v978cb_392eb_d3
run-condition:243.v3c3f94e46a_8b_
scm-api:703.v72ff4b_259600
script-security:1369.v9b_98a_4e95b_2d
skip-certificate-check:1.1
snakeyaml-api:2.3-123.v13484c65210a_
sonar:2.18
sse-gateway:1.27
ssh-agent:376.v8933585c69d3
ssh-credentials:349.vb_8b_6b_9709f5b_
ssh-slaves:3.1031.v72c6b_883b_869
ssh-steps:2.0.68.va_d21a_12a_6476
sshd:3.350.v1080103a_10fd
structs:338.v848422169819
theme-manager:278.v2e3c063e42cc
thinBackup:2.1.2
throttle-concurrents:2.16
timestamper:1.28
token-macro:444.v52de7e9c573d
trilead-api:2.147.vb_73cc728a_32e
variant:70.va_d9f17f859e0
versionnumber:1.11
workflow-aggregator:600.vb_57cdd26fdd7
workflow-api:1363.v03f731255494
workflow-basic-steps:1079.vce64b_a_929c5a_
workflow-cps:4018.vf02e01888da_f
workflow-durable-task-step:1405.v1fcd4a_d00096
workflow-job:1505.vea_4b_20a_4a_495
workflow-multibranch:800.v5f0a_a_660950e
workflow-scm-step:427.v4ca_6512e7df1
workflow-step-api:686.v603d058a_e148
workflow-support:946.v2a_79d8a_4b_e14
ws-cleanup:0.48

What Operating System are you using (both controller, and any agents involved in the problem)?

Linux 6.8.0-52-generic (Ubuntu 24.04x64)

Reproduction steps

curl 'https://jenkins.org.local/$stapler/bound/---/parseAndValidatePay'
--data-raw $'["pipeline:\n agent:\n label: Docker\n triggers:\n - cron: \"H 0 * * 5\"\n stages:\n - stage: Build\n steps:\n - script:\n - sh './build.sh dry'\n - sh './build.sh build'"]'

Expected Results

Validate YAML syntax

Actual Results

class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')

Anything else?

No response

Are you interested in contributing a fix?

Unfortunately, I'm not a Java developer, so I don't think I can do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions