Skip to main content

A Jenkinsfile linter that validates Jenkinsfiles using Jenkins API

Project description

Jenkinsfile Lint

CI codecov PyPI version

Catch Jenkinsfile syntax errors before they break your CI.

jenkinsfilelint sends your Jenkinsfiles to your Jenkins server's /pipeline-model-converter/validate endpoint for real syntax validation. It's primarily a pre-commit hook, but also works as a CLI tool.

📖 Read the official blog post for the story behind this tool.

demo

Table of Contents

Quick Start

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/jenkinsci/jenkinsfilelint
    rev: # use the latest or a specific version, e.g. v1.4.0
    hooks:
      - id: jenkinsfilelint
export JENKINS_URL=https://jenkins.example.com
export JENKINS_USER=your-username
export JENKINS_TOKEN=your-api-token

pip install pre-commit
pre-commit install

Usage

Pre-commit Hook

Once installed, every commit that touches a Jenkinsfile is validated:

git commit -m "Update Jenkinsfile"
jenkinsfilelint..........................................................Passed

If the file has a syntax error the commit is blocked:

git commit -m "Update Jenkinsfile"
jenkinsfilelint..........................................................Failed
- hook id: jenkinsfilelint
- exit code: 1

Errors encountered validating Jenkinsfile:
WorkflowScript: 17: Expected a step @ line 17, column 11.
             test
             ^

Fix the error, re-commit, and it passes.

CLI

pip install jenkinsfilelint

jenkinsfilelint Jenkinsfile
jenkinsfilelint Jenkinsfile Jenkinsfile.prod tests/Jenkinsfile

Filtering files

Use --include (whitelist) and --skip (blacklist) to control which files are validated:

# Only validate Jenkinsfiles
jenkinsfilelint --include 'Jenkinsfile*' Jenkinsfile src/Utils.groovy

# Exclude shared-library helper classes
jenkinsfilelint --skip '*/src/*.groovy' --skip 'vars/*.groovy' Jenkinsfile src/Utils.groovy

These work in pre-commit too:

Exclude non-pipeline Groovy files (shared library helpers):

- id: jenkinsfilelint
  args: ["--skip=*/src/*.groovy", "--skip=vars/*.groovy"]

Only validate files matching specific patterns:

- id: jenkinsfilelint
  args: ["--include=Jenkinsfile*", "--include=pipelines/*.groovy"]

You can also combine both — --include narrows first, then --skip removes from that set:

- id: jenkinsfilelint
  args: ["--include=Jenkinsfile*", "--skip=*/src/*.groovy"]

Configuration

Supply credentials via environment variables (recommended) or CLI flags:

Env Variable CLI Flag Required
JENKINS_URL --jenkins-url Yes
JENKINS_USER --username No *
JENKINS_TOKEN --token No *

* Only required if your Jenkins requires authentication.

[!TIP] Even if your Jenkins allows anonymous access for validation, using an API token is recommended for production setups.

CLI flags override env vars. There is no config file.

Security

[!WARNING] Never hardcode credentials in config files — use environment variables.

  • Never put --token or --username in .pre-commit-config.yaml — use environment variables.
  • Use an API token, not your password.
  • A regular user token with read access is sufficient — no need for admin privileges.

How It Works

jenkinsfilelint is a syntax gate — it checks that your Declarative Pipeline syntax is valid.

  1. Reads the local Jenkinsfile.
  2. POSTs it to <JENKINS_URL>/pipeline-model-converter/validate.
  3. Jenkins parses the Pipeline and returns "ok" or errors.
  4. Errors are printed and the tool exits non-zero.

It only answers: "Will Jenkins accept this syntax?"

Requirements

  • Python 3.10+
  • Jenkins server with the Pipeline plugin

Contributing

See CONTRIBUTING.md.

License

MIT — see 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 Distribution

jenkinsfilelint-1.4.1.tar.gz (131.8 kB view details)

Uploaded Source

Built Distribution

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

jenkinsfilelint-1.4.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file jenkinsfilelint-1.4.1.tar.gz.

File metadata

  • Download URL: jenkinsfilelint-1.4.1.tar.gz
  • Upload date:
  • Size: 131.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for jenkinsfilelint-1.4.1.tar.gz
Algorithm Hash digest
SHA256 c2998260d447ca3ea1c00ab5fac5f90b2ee00023b4e26eddff2d44e40e53182e
MD5 36b62bd64750356595a9d5fbb9cf2c36
BLAKE2b-256 dc40c21bb3721a2cf8f9aba9df693ac718b0b77a2226d80fdde4dab737c0ad38

See more details on using hashes here.

Provenance

The following attestation bundles were made for jenkinsfilelint-1.4.1.tar.gz:

Publisher: release.yml on jenkinsci/jenkinsfilelint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for jenkinsfilelint-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c247667328f74b7916c49da2676767b964b4358b2aa3f8cc593f13a04636844a
MD5 15518ef59bf40f6a00d88b499a519c34
BLAKE2b-256 f28f7b09f3fdd0e589bb2c1845793b1626e41b128d5a35de5c777abce1dbeb23

See more details on using hashes here.

Provenance

The following attestation bundles were made for jenkinsfilelint-1.4.1-py3-none-any.whl:

Publisher: release.yml on jenkinsci/jenkinsfilelint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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