Skip to main content

A Jenkinsfile linter that validates Jenkinsfiles using Jenkins API

Project description

Jenkinsfile Lint

CI

A Python-based Jenkinsfile linter that validates Jenkinsfiles using Jenkins API or performs basic syntax checking.

Features

  • Validates Jenkinsfiles using Jenkins REST API
  • Falls back to basic syntax checking when Jenkins is not available
  • Works as a pre-commit hook
  • Supports both command-line usage and environment variables for configuration
  • No mandatory Jenkins credentials required (but recommended for full validation)

Installation

Using pip

pip install -e .

Using pre-commit

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

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

Usage

Command Line

Basic usage (performs syntax check only):

jenkinsfilelint path/to/Jenkinsfile

With Jenkins validation (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

With Jenkins validation (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

Environment Variables

  • JENKINS_URL: Your Jenkins server URL
  • JENKINS_USER: Your Jenkins username (optional if anonymous read access is enabled)
  • JENKINS_TOKEN: Your Jenkins API token (optional if anonymous read access is enabled)

Pre-commit Hook

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

repos:
  - repo: local
    hooks:
      - id: jenkinsfile-lint
        name: Lint Jenkinsfile
        description: Validate Jenkinsfile
        entry: jenkinsfilelint
        language: python
        types: [file]
        files: ^(Jenkinsfile(\..*)?|.*\.groovy)$

Then install the pre-commit hook:

pre-commit install

How It Works

  1. With Jenkins API: When Jenkins credentials are provided, the linter sends the Jenkinsfile to your Jenkins instance's /pipeline-model-converter/validate endpoint for full validation.

  2. Without Jenkins API: When Jenkins credentials are not provided, the linter performs basic syntax checking to ensure the file is not empty and contains expected pipeline declarations.

Requirements

  • Python 3.6+
  • requests library

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-0.0.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for jenkinsfilelint-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3b817a07200a5d8f00af09917f20b40718c7a79ed82cb0ee40b9185293c728
MD5 b9f142647ee099de2dd2a1628ce51043
BLAKE2b-256 db8ae9919f06d6b5de8ea31bada152cb995cbccf0596e06d9f9e2488f60e9538

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