Loading...
Loading...
Comprehensive toolkit for validating, linting, testing, and automating Jenkinsfile pipelines (both Declarative and Scripted). Use this skill when working with Jenkins pipeline files, validating pipeline syntax, checking best practices, debugging pipeline issues, or working with custom plugins.
npx skill4agent add akin-ozer/cc-devops-skills jenkinsfile-validatorpipeline {node# Run complete validation (syntax + security + best practices)
bash scripts/validate_jenkinsfile.sh Jenkinsfile# Full validation (default)
bash scripts/validate_jenkinsfile.sh Jenkinsfile
# Syntax validation only (fastest)
bash scripts/validate_jenkinsfile.sh --syntax-only Jenkinsfile
# Security audit only
bash scripts/validate_jenkinsfile.sh --security-only Jenkinsfile
# Best practices check only
bash scripts/validate_jenkinsfile.sh --best-practices Jenkinsfile
# Skip security checks
bash scripts/validate_jenkinsfile.sh --no-security Jenkinsfile
# Skip best practices
bash scripts/validate_jenkinsfile.sh --no-best-practices Jenkinsfile
# Strict mode (fail on warnings)
bash scripts/validate_jenkinsfile.sh --strict Jenkinsfile┌─────────────────────────────────────────────────────────────┐
│ 1. Type Detection (Automatic) │
│ ├─ Declarative: starts with 'pipeline {' │
│ └─ Scripted: starts with 'node' or Groovy code │
│ ↓ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 2. Syntax Validation (Required) │
│ ├─ Structure validation │
│ ├─ Required sections │
│ └─ Groovy syntax │
│ ↓ │
│ Reports errors → Continues to next phase │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 3. Security Scan (Required) │
│ ├─ Hardcoded credentials │
│ ├─ API keys / tokens │
│ ├─ Cloud provider credentials │
│ └─ Private keys / certificates │
│ ↓ │
│ Reports issues → Continues to next phase │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 4. Best Practices Check (Recommended) │
│ ├─ Combined shell commands │
│ ├─ Timeout configuration │
│ ├─ Workspace cleanup │
│ ├─ Error handling │
│ └─ Test result publishing │
│ ↓ │
│ Reports suggestions → Complete with summary │
└─────────────────────────────────────────────────────────────┘
**Note:** All validation phases run regardless of errors found in previous phases.
This ensures comprehensive reporting of all issues in a single run.scripts/
├── validate_jenkinsfile.sh # Main orchestrator (USE THIS)
│ ├── Auto-detects pipeline type
│ ├── Runs syntax validation
│ ├── Runs security scan
│ ├── Runs best practices check
│ └── Produces unified summary
│
├── validate_declarative.sh # Declarative syntax validator
│ └── Called automatically for pipeline {} blocks
│
├── validate_scripted.sh # Scripted syntax validator
│ └── Called automatically for node {} blocks
│
├── common_validation.sh # Shared functions + security scan
│ ├── detect_type: Determine pipeline type
│ ├── check_credentials: Security credential scan
│ └── Common utilities
│
├── best_practices.sh # 15-point best practices scorer
│ └── Performance, security, maintainability checks
│
└── validate_shared_library.sh # Shared library validator
└── For vars/*.groovy and src/**/*.groovy filesvalidate_jenkinsfile.sh# Detect pipeline type
bash scripts/common_validation.sh detect_type Jenkinsfile
# Run syntax validation only
bash scripts/validate_declarative.sh Jenkinsfile # For declarative
bash scripts/validate_scripted.sh Jenkinsfile # For scripted
# Run security checks only
bash scripts/common_validation.sh check_credentials Jenkinsfile
# Run best practices check only
bash scripts/best_practices.sh Jenkinsfilevalidate_shared_library.sh# Validate a single vars file
bash scripts/validate_shared_library.sh vars/myStep.groovy
# Validate entire shared library directory
bash scripts/validate_shared_library.sh /path/to/shared-library
# Validate just vars directory
bash scripts/validate_shared_library.sh vars/
# Validate just src directory
bash scripts/validate_shared_library.sh src/=== Validating Global Variable: myStep ===
File: vars/myStep.groovy
=== Validation Results ===
ERRORS (2):
ERROR [Line 15]: @NonCPS method contains pipeline steps (sh, echo, etc.)
ERROR [Line 15]: → Pipeline steps cannot be used in @NonCPS methods
WARNINGS (3):
WARNING [Line 22]: Using 'new File()' - prefer readFile/writeFile for pipeline compatibility
WARNING [Line 1]: No call() method found - file may not be callable as a step
WARNING [Line 1]: Filename 'BadStep' should be camelCase starting with lowercase
=== Summary ===
✗ Validation failed with 2 error(s) and 3 warning(s)references/common_plugins.mdcustomDeploysendToDatadoggrafanaNotifynexusArtifactUploadersonarQubeScanner┌─────────────────────────────────────────────────────────────┐
│ 1. Identify Unknown Plugin Step │
│ - Review Jenkinsfile for unrecognized steps │
│ - Example: customDeploy, nexusPublish, datadogEvent │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 2. Check Local Reference First │
│ - Read: references/common_plugins.md │
│ - Contains: git, docker, kubernetes, credentials, etc. │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 3. Use Context7 MCP (if not in local reference) │
│ - mcp__context7__resolve-library-id │
│ query: "jenkinsci <plugin-name>-plugin" │
│ - mcp__context7__get-library-docs │
│ for usage examples and parameters │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 4. Web Search Fallback (if Context7 has no results) │
│ - WebSearch: "Jenkins <plugin-name> plugin documentation"│
│ - Official source: https://plugins.jenkins.io/ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 5. Provide Usage Guidance │
│ - Required vs optional parameters │
│ - Best practices for the plugin │
│ - Security considerations │
└─────────────────────────────────────────────────────────────┘// User's Jenkinsfile contains:
stage('Deploy') {
steps {
nexusArtifactUploader artifacts: [[...]], nexusUrl: 'http://nexus'
datadogEvent title: 'Deployment', text: 'Deployed v1.0'
}
}nexusArtifactUploaderdatadogEventmcp__context7__resolve-library-idshshcredentials()withCredentialsparallel${VAR}$VARERROR [Line 5]: Missing required section 'agent'
→ Add 'agent any' or specific agent configuration at top level
WARNING [Line 12]: Multiple consecutive 'sh' steps detected
→ Combine into single sh step with triple-quoted string
→ See: best_practices.md#combine-shell-commands
INFO [Line 23]: Consider using parallel execution for independent stages
→ See: references/declarative_syntax.md#parallel-stagesbash scripts/validate_jenkinsfile.sh <path-to-jenkinsfile>references/common_plugins.mdmcp__context7__resolve-library-idUser: "Validate my Jenkinsfile"
1. Read the Jenkinsfile
2. Detect type: Declarative (starts with 'pipeline {')
3. Run: bash scripts/validate_declarative.sh Jenkinsfile
4. Run: bash scripts/best_practices.sh Jenkinsfile
5. Report results with suggestionsUser: "Check this pipeline with custom plugin steps"
1. Read Jenkinsfile
2. Run validation
3. Detect unknown step (e.g., 'customDeploy')
4. Search context7 for plugin docs
5. If not found, web search "Jenkins custom deploy plugin"
6. Validate plugin usage against found documentation
7. Report resultsUser: "Check for security issues in my pipeline"
1. Read Jenkinsfile
2. Run: bash scripts/common_validation.sh check_credentials Jenkinsfile
3. Scan for hardcoded secrets, passwords, API keys
4. Check credential management best practices
5. Report security findings with fix suggestionssh '''
echo "Building..."
mkdir build
./gradlew build
echo "Build complete"
'''sh 'echo "Building..."'
sh 'mkdir build'
sh './gradlew build'
sh 'echo "Build complete"'withCredentials([string(credentialsId: 'api-key', variable: 'API_KEY')]) {
sh 'curl -H "Authorization: Bearer $API_KEY" ...'
}sh 'curl -H "Authorization: Bearer abc123xyz" ...'chmod +x scripts/*.sh# Run with bash debug mode
bash -x scripts/validate_jenkinsfile.sh Jenkinsfile
# Check individual validator output
bash scripts/validate_declarative.sh Jenkinsfile
bash scripts/best_practices.sh Jenkinsfile
bash scripts/common_validation.sh check_credentials Jenkinsfile