Skip to content

fix(jenkinsxml): prevent nil-panic and broaden job coverage - #343

Open
dtsong-harness wants to merge 1 commit into
drone:masterfrom
dtsong-harness:fix/jenkinsxml-nil-panics-and-coverage
Open

fix(jenkinsxml): prevent nil-panic and broaden job coverage#343
dtsong-harness wants to merge 1 commit into
drone:masterfrom
dtsong-harness:fix/jenkinsxml-nil-panics-and-coverage

Conversation

@dtsong-harness

Copy link
Copy Markdown

Summary

The convert/jenkinsxml converter panicked on any Jenkins job without a freestyle <builders> block, and silently dropped most of the job config it did parse. This PR fixes the crash and broadens coverage for the common cases.

Found while converting real-world Jenkins jobs (Maven module-sets and scripted pipelines) that crashed the tool.

Crash fix

convert() dereferenced ctx.config.Builders.Tasks, but Builders is a nil *Builders for any job type without a freestyle <builders> block, for example <maven2-moduleset> (Maven jobs) and <flow-definition> (scripted pipelines). Both panicked. Now nil-guarded; such jobs produce a valid pipeline instead of crashing.

Coverage

The parser (xml/project.go) previously only unmarshalled concurrentBuild, disabled, and builders, so SCM, parameters, and Maven goals were never available to convert. Extended:

  • Git SCM (hudson.plugins.git.GitSCM): parse userRemoteConfigs/url + branches/name and emit a git-clone plugin step first, which the downgrader lifts into the pipeline codebase. Branch refs are normalized (*/master -> master).
  • maven2-moduleset <goals>: emit an mvn <goals> Run step instead of an empty stage.
  • StringParameterDefinition: map to v1 pipeline inputs (type/description/default).

Tests

Adds TestConvertNoBuilders, TestConvertMavenGoals, TestConvertParameters, TestConvertSCM and testdata. Updates the existing parse test for the newly-captured <scm> element. Full go-convert suite passes.

Notes / out of scope

  • Jenkins triggers (timer/SCM-poll/GitHub-push) are not emitted: the v1 pipeline spec has no trigger type (Harness triggers are separate entities).
  • Scripted flow-definition jobs keep their SCM nested under <definition><scm>; only top-level <scm> is read here.

🤖 Generated with Claude Code

The jenkinsxml converter panicked on any job without a freestyle <builders>
block (maven2-moduleset, scripted flow-definition) because convert() derefed
a nil Builders. Guard the nil and emit a steps-less stage instead.

Also extend the parser (which only read concurrentBuild/disabled/builders)
and converter to cover the common cases that were silently dropped:

- Git SCM (hudson.plugins.git.GitSCM): emit a git-clone plugin step so the
  downgrader populates the pipeline codebase. Branch refs are normalized
  (*/master -> master).
- maven2-moduleset <goals>: emit an `mvn <goals>` Run step instead of an
  empty stage.
- StringParameterDefinition: map to v1 pipeline inputs (type/description/default).

Adds regression tests and testdata for each case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant