fix(jenkinsxml): prevent nil-panic and broaden job coverage - #343
Open
dtsong-harness wants to merge 1 commit into
Open
fix(jenkinsxml): prevent nil-panic and broaden job coverage#343dtsong-harness wants to merge 1 commit into
dtsong-harness wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
convert/jenkinsxmlconverter 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()dereferencedctx.config.Builders.Tasks, butBuildersis a nil*Buildersfor 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 unmarshalledconcurrentBuild,disabled, andbuilders, so SCM, parameters, and Maven goals were never available to convert. Extended:hudson.plugins.git.GitSCM): parseuserRemoteConfigs/url+branches/nameand emit a git-clone plugin step first, which the downgrader lifts into the pipeline codebase. Branch refs are normalized (*/master->master).<goals>: emit anmvn <goals>Run step instead of an empty stage.StringParameterDefinition: map to v1 pipelineinputs(type/description/default).Tests
Adds
TestConvertNoBuilders,TestConvertMavenGoals,TestConvertParameters,TestConvertSCMand testdata. Updates the existing parse test for the newly-captured<scm>element. Fullgo-convertsuite passes.Notes / out of scope
flow-definitionjobs keep their SCM nested under<definition><scm>; only top-level<scm>is read here.🤖 Generated with Claude Code