Conversation
… in Jenkinsfile example
…dd DeepWiki badge to README.md
There was a problem hiding this comment.
Pull request overview
Adds conversion support for Jenkins Declarative Pipeline parallel { ... } stages, emitting the corresponding Bitbucket Pipelines parallel: YAML structure while refactoring stage representation to distinguish single steps vs parallel groups.
Changes:
- Introduces
StepItem/ParallelItemand parses direct child stages to detectparallel {}blocks. - Updates YAML emission to output Bitbucket
parallel:blocks and refactors script emission viaemitStepScript. - Adds a new Jenkinsfile fixture for parallel-stage scenarios and bumps package version/docs badge.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Jenkinsfile-example3 | Adds a Jenkinsfile fixture containing both regular stages and a parallel stage group. |
| src/converter.ts | Refactors stage parsing and YAML emission to support parallel blocks; adds helper utilities. |
| package.json | Bumps package version to 0.2.3. |
| package-lock.json | Updates lockfile version fields to 0.2.3. |
| README.md | Adds a DeepWiki badge. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| for (const m of body.matchAll(pattern)) { | ||
| // Count brace depth at this match position | ||
| let depth = 0; | ||
| for (let i = 0; i < m.index!; i++) { | ||
| if (body[i] === '{') depth++; | ||
| else if (body[i] === '}') depth--; | ||
| } | ||
| if (depth === 0) { | ||
| const block = getBalancedBlock(body, m.index!); |
There was a problem hiding this comment.
findDirectChildStages computes brace depth by scanning from the start of body up to each regex match index, which makes this O(n*m) for n=body length and m=number of stage(...) matches. On larger Jenkinsfiles (or ones with many nested blocks), this can become a noticeable bottleneck. Consider a single-pass scan that tracks current brace depth while searching for stage(...), or precompute a depth-at-index array once per body string.
| for (const m of body.matchAll(pattern)) { | |
| // Count brace depth at this match position | |
| let depth = 0; | |
| for (let i = 0; i < m.index!; i++) { | |
| if (body[i] === '{') depth++; | |
| else if (body[i] === '}') depth--; | |
| } | |
| if (depth === 0) { | |
| const block = getBalancedBlock(body, m.index!); | |
| let depth = 0; | |
| let lastScannedIndex = 0; | |
| let m: RegExpExecArray | null; | |
| while ((m = pattern.exec(body)) !== null) { | |
| const matchIndex = m.index; | |
| // Update brace depth only for the characters since the previous match. | |
| for (let i = lastScannedIndex; i < matchIndex; i++) { | |
| if (body[i] === '{') depth++; | |
| else if (body[i] === '}') depth--; | |
| } | |
| lastScannedIndex = matchIndex; | |
| if (depth === 0) { | |
| const block = getBalancedBlock(body, matchIndex); |
| for (const item of items) { | ||
| if (item.kind === 'parallel') { | ||
| lines.push(' - parallel:'); | ||
| for (const step of item.steps) { | ||
| lines.push(' - step:'); | ||
| lines.push(` name: ${step.name}`); | ||
| if (runners) { | ||
| lines.push(' runs-on:'); | ||
| for (const r of runners) lines.push(` - ${r}`); | ||
| } | ||
| lines.push(' script:'); | ||
| emitStepScript(step, ' '); | ||
| } | ||
| lines.push(''); |
There was a problem hiding this comment.
Parallel-stage conversion is introduced here, but the automated test suite doesn’t appear to assert the emitted parallel: YAML structure (and tests/Jenkinsfile-example3 isn’t referenced by the current Jest tests). Add/extend a unit test that converts a Jenkinsfile containing a parallel { stage(...) ... } block and asserts the resulting YAML has a parallel item with the expected sub-steps.
| @@ -0,0 +1,41 @@ | |||
|
|
|||
There was a problem hiding this comment.
This fixture file starts with a blank line, so the shebang (#!/usr/bin/env groovy) is not on the first line. If the file is ever executed directly, the shebang will be ignored. Consider removing the leading blank line so the shebang is line 1.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request introduces support for Jenkins pipeline stages that use the
parallelblock, enabling conversion of Jenkinsfiles with parallel test or build stages into the correct Bitbucket Pipelines YAML structure. It also refactors the internal representation of stages to distinguish between regular steps and parallel groups, and adds a new test case to verify the feature.Key changes:
Parallel stage support and pipeline structure:
StepItem,ParallelItem, and a union typePipelineItem, allowing the converter to distinguish between regular and parallel stages. The YAML output now correctly emitsparallelblocks for Bitbucket Pipelines when parallel stages are detected in the Jenkinsfile. [1] [2] [3]findDirectChildStagesto accurately extract direct child stages from both regular and parallel blocks, ensuring correct parsing and nesting.emitStepScripthelper to centralize and unify the logic for emitting script lines for each step, reducing code duplication and improving maintainability.Testing and documentation:
tests/Jenkinsfile-example3) that includes both regular and parallel stages to verify the new parallel conversion logic.package.jsonversion to0.2.3and added a DeepWiki badge to theREADME.mdfor improved documentation and discoverability. [1] [2]