akin-ozer/cc-devops-skills24 files

Jenkinsfile Generator

Generate/create/scaffold Jenkinsfile — declarative, scripted, shared library, CI/CD pipelines.

Specification
Skill ID
akin-ozer/cc-devops-skills/jenkinsfile-generator
Publisher
akin-ozer
Repository
cc-devops-skills
Installs
0
Files
24
Synced
Sep 23, 2026
How to use it

Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.

akin-ozer/cc-devops-skills/jenkinsfile-generatorInstalls these files
  • .gitignore
  • SKILL.md
  • assets/templates/declarative/basic.Jenkinsfile
  • assets/templates/scripted/basic.Jenkinsfile
  • examples/declarative-ci-basic.Jenkinsfile
  • examples/declarative-docker.Jenkinsfile
  • examples/declarative-kubernetes.Jenkinsfile
  • examples/declarative-matrix.Jenkinsfile
  • examples/declarative-parallel.Jenkinsfile
  • examples/declarative-security-scan.Jenkinsfile
  • examples/declarative-shared-library.Jenkinsfile
  • examples/scripted-basic.Jenkinsfile
  • examples/scripted-conditional.Jenkinsfile
  • examples/scripted-docker.Jenkinsfile
  • references/best_practices.md
  • references/common_plugins.md
  • scripts/generate_declarative.py
  • scripts/generate_scripted.py
  • scripts/generate_shared_library.py
  • scripts/lib/__init__.py
  • scripts/lib/common_patterns.py
  • scripts/lib/syntax_helpers.py
  • scripts/test_generate_declarative.py
  • scripts/test_generate_shared_library.py

What this skill tells the agent

Jenkinsfile Generator Skill

Generate production-ready Jenkinsfiles following best practices. All generated files are validated using devops-skills:jenkinsfile-validator skill.

Trigger Phrases

  • "Generate a CI pipeline for Maven/Gradle/npm"
  • "Create a Jenkins deployment pipeline with approvals"
  • "Build a Jenkinsfile with parallel test stages"
  • "Create a scripted pipeline with dynamic stage logic"
  • "Scaffold a Jenkins shared library"
  • "Generate a Jenkinsfile for Docker or Kubernetes agents"

When to Use

  • Creating new Jenkinsfiles (declarative or scripted)
  • CI/CD pipelines, Docker/Kubernetes deployments
  • Parallel execution, matrix builds, parameterized pipelines
  • DevSecOps pipelines with security scanning
  • Shared library scaffolding

Declarative vs Scripted Decision Tree

  1. Choose Declarative by default when stage order and behavior are mostly static.
  2. Choose Scripted when runtime-generated stages, complex loops, or dynamic control flow are required.
  3. Choose Shared Library scaffolding when request is about reusable pipeline functions (vars/, src/, resources/).
  4. If unsure, start Declarative and only switch to Scripted if requirements cannot be expressed cleanly.

Template Map

TemplatePathUse When
Declarative basicassets/templates/declarative/basic.JenkinsfileStandard CI/CD with predictable stages
Declarative parallel exampleexamples/declarative-parallel.JenkinsfileParallel test/build branches with fail-fast behavior
Declarative kubernetes exampleexamples/declarative-kubernetes.JenkinsfileKubernetes agent execution using pod templates
Scripted basicassets/templates/scripted/basic.JenkinsfileComplex conditional logic or generated stages
Shared library scaffoldGenerated by scripts/generate_shared_library.pyReusable pipeline functions and organization-wide patterns

Quick Reference

// Minimal Declarative Pipeline
pipeline {
    agent any
    stages {
        stage('Build') { steps { sh 'make' } }
        stage('Test') { steps { sh 'make test' } }
    }
}

// Error-tolerant stage
stage('Flaky Tests') {
    steps {
        catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
            sh 'run-flaky-tests.sh'
        }
    }
}

// Conditional deployment with approval
stage('Deploy') {
    when { branch 'main'; beforeAgent true }
    input { message 'Deploy to production?' }
    steps { sh './deploy.sh' }
}
OptionPurpose
timeout(time: 1, unit: 'HOURS')Prevent hung builds
buildDiscarder(logRotator(numToKeepStr: '10'))Manage disk space
disableConcurrentBuilds()Prevent race conditions
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')Continue on error

Core Capabilities

1. Declarative Pipelines (RECOMMENDED)

Process:

  1. Read templates for structure reference:
  • Read assets/templates/declarative/basic.Jenkinsfile to understand the standard structure
  • Templates show the expected sections: pipeline → agent → environment → options → parameters → stages → post
  • For complex requests, adapt the structure rather than copying verbatim
  1. Consult reference documentation:
  • Read references/best_practices.md for performance, security, and reliability patterns
  • Read references/common_plugins.md for plugin-specific syntax
  1. Generate with required elements:
  • Proper stages with descriptive names
  • Environment block with credentials binding (never hardcode secrets)
  • Options: timeout, buildDiscarder, timestamps, disableConcurrentBuilds
  • Post conditions: always (cleanup), success (artifacts), failure (notifications)
  • Always add `failFast true` or `parallelsAlwaysFailFast()` for parallel blocks
  • Always include `fingerprint: true` when using `archiveArtifacts`
  1. ALWAYS validate using devops-skills:jenkinsfile-validator skill

2. Scripted Pipelines

When: Complex conditional logic, dynamic generation, full Groovy control Process:

  1. Read templates for structure reference:
  • Read assets/templates/scripted/basic.Jenkinsfile for node/stage patterns
  • Understand try-catch-finally structure for error handling
  1. Implement try-catch-finally for error handling
  2. ALWAYS validate using devops-skills:jenkinsfile-validator skill

3. Parallel/Matrix Pipelines

Use parallel {} block or matrix {} with axes {} for multi-dimensional builds.

  • Default behavior is fail-fast for generated parallel pipelines (parallelsAlwaysFailFast() or stage-level failFast true).

4. Security Scanning (DevSecOps)

Add SonarQube, OWASP Dependency-Check, Trivy stages with fail thresholds.

5. Shared Library Scaffolding

python3 scripts/generate_shared_library.py --name my-library --package org.example

Declarative Syntax Reference

Agent Types

agent any                                    // Any available agent
agent { label 'linux && docker' }           // Label-based
agent { docker { image 'maven:3.9.11-eclipse-temurin-21' } }
agent { kubernetes { yaml '...' } }         // K8s pod template
agent { kubernetes { yamlFile 'pod.yaml' } } // External YAML

Environment & Credentials

environment {
    VERSION = '1.0.0'
    AWS_KEY = credentials('aws-key-id')     // Creates _USR and _PSW vars
}

Options

options {
    buildDiscarder(logRotator(numToKeepStr: '10'))
    timeout(time: 1, unit: 'HOURS')
    disableConcurrentBuilds()
    timestamps()
    parallelsAlwaysFailFast()
    durabilityHint('PERFORMANCE_OPTIMIZED')  // 2-6x faster for simple pipelines
}

Parameters

parameters {
    string(name: 'VERSION', defaultValue: '1.0.0')
    choice(name: 'ENV', choices: ['dev', 'staging', 'prod'])
    booleanParam(name: 'SKIP_TESTS', defaultValue: false)
}

When Conditions

ConditionExample
branchbranch 'main' or branch pattern: 'release/*', comparator: 'GLOB'
tagtag pattern: 'v*', comparator: 'GLOB'
changeRequestchangeRequest target: 'main'
changesetchangeset 'src/**/*.java'
expressionexpression { env.DEPLOY == 'true' }
allOf/anyOf/notCombine conditions

Add beforeAgent true to skip agent allocation if condition fails.

Error Handling

catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { sh '...' }
warnError('msg') { sh '...' }      // Mark UNSTABLE but continue
unstable(message: 'Coverage low')   // Explicit UNSTABLE
error('Config missing')             // Fail without stack trace

Post Section

post {
    always { junit '**/target/*.xml'; cleanWs() }
    success { archiveArtifacts artifacts: '**/*.jar', fingerprint: true }
    failure { slackSend color: 'danger', message: 'Build failed' }
    fixed { echo 'Build fixed!' }
}

Order: always → changed → fixed → regression → failure → success → unstable → cleanup

NOTE: Always use fingerprint: true with archiveArtifacts for build traceability and artifact tracking.

Parallel & Matrix

IMPORTANT: Always ensure parallel blocks fail fast on first failure using one of these approaches:

Option 1: Global (RECOMMENDED) - Use parallelsAlwaysFailFast() in pipeline options:

options {
    parallelsAlwaysFailFast()  // Applies to ALL parallel blocks in pipeline
}

This is the preferred approach as it covers all parallel blocks automatically.

Option 2: Per-block - Use failFast true on individual parallel stages:

stage('Tests') {
    failFast true  // Only affects this parallel block
    parallel {
        stage('Unit') { steps { sh 'npm test:unit' } }
        stage('E2E') { steps { sh 'npm test:e2e' } }
    }
}

NOTE: When parallelsAlwaysFailFast() is set in options, explicit failFast true on individual parallel blocks is redundant.

Use this skill in a project

Open any RiverX project, search the Skills panel for akin-ozer/cc-devops-skills/jenkinsfile-generator, and install it in one click.

Use this skill