v1.2.0
Minor Changes
-
712ec0d: Fluent Job Builder API
New Feature: Fluent Job Builder API
Added a powerful fluent builder interface for defining jobs and templates with chainable methods:
New Methods:
addJob(name)- Create a new job with fluent builder interfaceaddTemplate(name)- Create a new template with fluent builder interface
JobBuilder Methods:
Common properties:stage(stage)- Set job stageextends(extend)- Set extendsimage(image)- Set imagescript(script)- Set scriptbeforeScript(script)- Set before_scriptafterScript(script)- Set after_scriptservices(services)- Set servicescache(cache)- Set cacheartifacts(artifacts)- Set artifactssetVariables(vars)- Set job variablesenvironment(env)- Set environmentwhen(when)- Set when conditionrules(rules)- Set rulesneeds(needs)- Set needstags(tags)- Set tagsallowFailure(bool)- Set allow_failuretimeout(timeout)- Set timeoutretry(retry)- Set retryparallel(parallel)- Set paralleltrigger(trigger)- Set triggercoverage(pattern)- Set coverage patterndependencies(deps)- Set dependenciesresourceGroup(group)- Set resource_grouprelease(release)- Set releaseinterruptible(bool)- Set interruptibleidTokens(tokens)- Set id_tokens
Utility methods:
set(props)- Bulk set multiple properties at oncejobOptions(opts)- Set job options (remote, mergeExtends, etc.)remote(bool)- Mark job as remotemergeExtends(bool)- Control extends mergingresolveTemplatesOnly(bool)- Control template resolutiondone()- Finalize job and return to ConfigBuilder
Auto-Return Behavior:
When you calladdJob()oraddTemplate()from a JobBuilder, the previous job is automatically saved and a new builder is returned:const config = new ConfigBuilder() // Fluent API with auto-return config .stages("build", "test", "deploy") .addTemplate(".node") .image("node:20") .cache({ paths: ["node_modules/"] }) .addJob("test") .stage("test") .extends(".node") .script(["npm test"]) .addJob("build") .stage("build") .extends(".node") .script(["npm run build"]) .addJob("deploy") .stage("deploy") .extends("build") .script(["kubectl apply -f k8s/"]) .when("manual") .done() // Or use done() to explicitly return to ConfigBuilder config .addJob("lint") .stage("test") .script(["npm run lint"]) .done() .addJob("format") .stage("test") .script(["npm run format:check"]) .done() // Bulk property updates with set() config .addJob("complex") .set({ stage: "test", image: "node:20", script: ["npm test"], cache: { paths: ["node_modules/"] }, artifacts: { paths: ["coverage/"] }, }) .done()
Benefits:
- Type-safe: Full TypeScript support with autocomplete
- Readable: Clear, declarative pipeline definitions
- Flexible: Mix with existing
job()andtemplate()methods - Convenient: Auto-return behavior reduces boilerplate
- Powerful: All job properties supported with dedicated methods
This fluent API is especially useful for complex pipelines with many jobs, making the code more maintainable and easier to read.
-
712ec0d: Graph Visualization
New Features: Graph Visualization
Added powerful visualization capabilities to analyze and visualize extends relationships in your GitLab CI pipelines:
New Methods:
getExtendsGraph()- Get the extends dependency graph for programmatic accessgenerateMermaidDiagram(options?)- Generate Mermaid diagram for documentation/GitHubgenerateAsciiTree(options?)- Generate ASCII tree for terminal outputgenerateStageTable(options?)- Generate CLI table with stages as columns
Visualization Options:
showRemote: boolean- Show remote jobs with 🌐 indicatorshowStages: boolean- Include job stages in outputhighlightCycles: boolean- Highlight circular dependencies if detected
Example Usage:
const config = new ConfigBuilder() // ... configure your pipeline ... // Generate individual visualizations const mermaid = config.generateMermaidDiagram({ showStages: true }) const ascii = config.generateAsciiTree({ showRemote: true }) const table = config.generateStageTable() console.log(mermaid) // Mermaid diagram console.log(ascii) // ASCII tree console.log(table) // Stage table
This feature is especially useful for:
- Documenting complex CI configurations
- Debugging extends chains and dependencies
- Understanding job relationships at a glance
- Detecting circular dependencies visually
-
712ec0d: Enhanced Validation API
New Feature: Enhanced Validation API
Added dedicated validation methods for better control over pipeline validation:
New Methods:
validate()- Validate pipeline and throw errors if validation fails (logs warnings to console)safeValidate()- Validate pipeline without throwing errors, returns validation result with{ valid, errors, warnings }
Enhanced Methods:
getPlainObject(options?)- Now accepts{ skipValidation?: boolean }option to skip validation when you've already validated separatelytoJSON(options?)- Now accepts{ skipValidation?: boolean }optiontoYaml(options?)- Now accepts{ skipValidation?: boolean }option
Breaking Changes:
finalize()is nowprivate- usesafeValidate()for programmatic validation orvalidate()for validation that throws errors
Usage Examples:
// Standard validation (throws on error) config.validate() const pipeline = config.getPlainObject({ skipValidation: true }) // Safe validation (no throw) const result = config.safeValidate() if (!result.valid) { console.error("Validation errors:", result.errors) return } if (result.warnings.length > 0) { console.warn("Warnings:", result.warnings) } const pipeline = config.getPlainObject({ skipValidation: true }) // Quick validation (default behavior) const pipeline = config.getPlainObject() // validates automatically
Benefits:
- Separation of concerns: Validation is now separate from pipeline retrieval
- Better error handling:
safeValidate()enables programmatic error handling without try/catch - Performance: Skip validation when using multiple output methods (
toYaml(),toJSON(), etc.) - Flexible: Choose between throwing (
validate()) or returning errors (safeValidate())