Skip to main content

A Jenkinsfile linter that validates Jenkinsfiles using Jenkins API

Project description

Jenkinsfile Lint

CI codecov

A Python-based Jenkinsfile linter that validates Jenkinsfiles using Jenkins API.

Table of Contents

Features

  • Validates Jenkinsfiles using Jenkins REST API
  • Works as a pre-commit hook
  • Supports both command-line usage and environment variables for configuration
  • Requires Jenkins credentials for validation
  • Supports skipping files that are not Jenkins pipelines (e.g., pure Groovy helper classes)

Installation

Using pip

pip install jenkinsfilelint

Using pre-commit

Add this to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/shenxianpeng/jenkinsfilelint
    rev: # or specific version tag
    hooks:
      - id: jenkinsfilelint

Usage

[!IMPORTANT] jenkinsfilelint requires Jenkins credentials to be set via environment variables for validation:

  • JENKINS_URL: Your Jenkins server URL (required)
  • JENKINS_USER: Your Jenkins username (required unless anonymous access is enabled)
  • JENKINS_TOKEN: Your Jenkins API token (required unless anonymous access is enabled)

Command Line

Validation requires Jenkins credentials. Set them using environment variables:

export JENKINS_URL=https://your-jenkins-instance.com
export JENKINS_USER=your-username
export JENKINS_TOKEN=your-api-token

jenkinsfilelint path/to/Jenkinsfile

Or using command-line arguments:

jenkinsfilelint path/to/Jenkinsfile \
  --jenkins-url https://your-jenkins-instance.com \
  --username your-username \
  --token your-api-token

Validate multiple files:

jenkinsfilelint Jenkinsfile Jenkinsfile.prod tests/Jenkinsfile

Skipping Files

In Jenkins shared libraries, some Groovy files are pure Groovy helper classes, not Jenkins pipeline scripts. Use the --skip option to exclude files from validation:

# Skip a specific file pattern
jenkinsfilelint --skip '*/src/*.groovy' Jenkinsfile src/Utils.groovy

# Skip multiple patterns
jenkinsfilelint --skip '*/src/*.groovy' --skip 'vars/*.groovy' Jenkinsfile src/Utils.groovy vars/deploy.groovy

The --skip option accepts glob patterns and can be used multiple times.

Pre-commit Hook

Create or update .pre-commit-config.yaml in your repository:

repos:
  - repo: https://github.com/shenxianpeng/jenkinsfilelint
    rev: # or specific version tag
    hooks:
      - id: jenkinsfilelint

Or using command-line arguments:

repos:
  - repo: https://github.com/shenxianpeng/jenkinsfilelint
    rev: # or specific version tag
    hooks:
      - id: jenkinsfilelint
        args: ["--jenkins-url=https://your-jenkins-instance.com", "--username=your-username", "--token=your-api-token"]

To skip certain files (e.g., pure Groovy classes in Jenkins shared libraries):

repos:
  - repo: https://github.com/shenxianpeng/jenkinsfilelint
    rev: # or specific version tag
    hooks:
      - id: jenkinsfilelint
        args: ["--skip=*/src/*.groovy", "--skip=vars/*.groovy"]

[!WARNING] Using args to pass credentials directly in the configuration file is not recommended for security reasons. Consider using environment variables instead. For more details, see pre-commit/pre-commit#758.

Then install the pre-commit hook:

pre-commit install

How It Works

The linter sends the Jenkinsfile to your Jenkins instance's /pipeline-model-converter/validate endpoint for validation. Jenkins credentials (URL, username, and API token) are required.

Requirements

  • Python 3.6+
  • Jenkins server with Pipeline plugin installed

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jenkinsfilelint-1.2.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file jenkinsfilelint-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jenkinsfilelint-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f37393b5cf959b8e5154f27db8152bbad011d7c090116c29f3e12da5e3974250
MD5 660e5b37aa1999ccc71c7edf87501734
BLAKE2b-256 1ea6fe07b0fd711ad3e9c8afb58f05eb2e6b0c00a84616f0ffc5107814a37141

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page