A Jenkinsfile linter that validates Jenkinsfiles using Jenkins API
Project description
Jenkinsfile Lint
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 URLJENKINS_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
-
With Jenkins API: When Jenkins credentials are provided, the linter sends the Jenkinsfile to your Jenkins instance's
/pipeline-model-converter/validateendpoint for full validation. -
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jenkinsfilelint-0.0.0-py3-none-any.whl.
File metadata
- Download URL: jenkinsfilelint-0.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d3b817a07200a5d8f00af09917f20b40718c7a79ed82cb0ee40b9185293c728
|
|
| MD5 |
b9f142647ee099de2dd2a1628ce51043
|
|
| BLAKE2b-256 |
db8ae9919f06d6b5de8ea31bada152cb995cbccf0596e06d9f9e2488f60e9538
|