jenkinsfilelint 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. jenkinsfilelint-1.4.0/.env.example +6 -0
  2. jenkinsfilelint-1.4.0/.github/CODEOWNERS +1 -0
  3. jenkinsfilelint-1.4.0/.github/dependabot.yml +23 -0
  4. jenkinsfilelint-1.4.0/.github/workflows/main.yml +44 -0
  5. jenkinsfilelint-1.4.0/.github/workflows/release-drafter.yml +22 -0
  6. jenkinsfilelint-1.4.0/.github/workflows/release.yml +34 -0
  7. jenkinsfilelint-1.4.0/.gitignore +31 -0
  8. jenkinsfilelint-1.4.0/.pre-commit-config.yaml +31 -0
  9. jenkinsfilelint-1.4.0/.pre-commit-hooks.yaml +8 -0
  10. jenkinsfilelint-1.4.0/CONTRIBUTING.md +28 -0
  11. jenkinsfilelint-1.4.0/LICENSE +21 -0
  12. jenkinsfilelint-1.4.0/PKG-INFO +210 -0
  13. jenkinsfilelint-1.4.0/README.md +191 -0
  14. jenkinsfilelint-1.4.0/jenkinsfilelint/__init__.py +9 -0
  15. jenkinsfilelint-1.4.0/jenkinsfilelint/cli.py +175 -0
  16. jenkinsfilelint-1.4.0/jenkinsfilelint/linter.py +132 -0
  17. jenkinsfilelint-1.4.0/jenkinsfilelint.egg-info/PKG-INFO +210 -0
  18. jenkinsfilelint-1.4.0/jenkinsfilelint.egg-info/SOURCES.txt +29 -0
  19. jenkinsfilelint-1.4.0/jenkinsfilelint.egg-info/dependency_links.txt +1 -0
  20. jenkinsfilelint-1.4.0/jenkinsfilelint.egg-info/entry_points.txt +2 -0
  21. jenkinsfilelint-1.4.0/jenkinsfilelint.egg-info/requires.txt +5 -0
  22. jenkinsfilelint-1.4.0/jenkinsfilelint.egg-info/top_level.txt +1 -0
  23. jenkinsfilelint-1.4.0/pyproject.toml +70 -0
  24. jenkinsfilelint-1.4.0/setup.cfg +4 -0
  25. jenkinsfilelint-1.4.0/tests/Jenkinsfile +21 -0
  26. jenkinsfilelint-1.4.0/tests/Jenkinsfile.fail +13 -0
  27. jenkinsfilelint-1.4.0/tests/__init__.py +1 -0
  28. jenkinsfilelint-1.4.0/tests/conftest.py +103 -0
  29. jenkinsfilelint-1.4.0/tests/test_cli.py +692 -0
  30. jenkinsfilelint-1.4.0/tests/test_init.py +37 -0
  31. jenkinsfilelint-1.4.0/tests/test_linter.py +699 -0
@@ -0,0 +1,6 @@
1
+ # Copy this file to .env and fill in your Jenkins credentials.
2
+ # .env is git-ignored and will never be committed.
3
+
4
+ JENKINS_URL=http://localhost:8080
5
+ JENKINS_USER=your-username
6
+ JENKINS_TOKEN=your-api-token
@@ -0,0 +1 @@
1
+ * @jenkinsci/jenkinsfilelint-developers
@@ -0,0 +1,23 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: github-actions
9
+ directory: /
10
+ schedule:
11
+ interval: "monthly"
12
+ groups:
13
+ github-action:
14
+ patterns:
15
+ - "*"
16
+ - package-ecosystem: pip
17
+ directory: /
18
+ schedule:
19
+ interval: "monthly"
20
+ groups:
21
+ pip:
22
+ patterns:
23
+ - "*"
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ${{ matrix.os }}
12
+ strategy:
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest, windows-latest]
15
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
19
+ with:
20
+ fetch-depth: 0 # Required for setuptools-scm
21
+
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+
27
+ - name: Install dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ pip install -e ".[dev]"
31
+
32
+ - name: Test CLI installation
33
+ run: |
34
+ jenkinsfilelint --help
35
+
36
+ - name: Run unit tests
37
+ run: |
38
+ pytest tests/ -v --cov=jenkinsfilelint --cov-report=term-missing --cov-report=xml
39
+ shell: bash
40
+ - name: Upload coverage to Codecov
41
+ uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
42
+ with:
43
+ token: ${{ secrets.CODECOV_TOKEN }}
44
+ files: ./coverage.xml
@@ -0,0 +1,22 @@
1
+ name: Release Drafter
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "main"
7
+ # allowing to run manually
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ update_release_draft:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ # Required to create/update the release
15
+ contents: write
16
+ # Required for autolabeler to add labels to PRs
17
+ pull-requests: write
18
+
19
+ steps:
20
+ - uses: release-drafter/release-drafter@v7
21
+ with:
22
+ config-name: github:shenxianpeng/.github:/.github/release-drafter.yml
@@ -0,0 +1,34 @@
1
+ name: Release Package
2
+
3
+ on:
4
+ release:
5
+ branches: [main]
6
+ types: [published]
7
+
8
+ jobs:
9
+ deploy:
10
+
11
+ runs-on: ubuntu-latest
12
+ environment:
13
+ name: pypi
14
+ url: https://pypi.org/p/jenkinsfilelint
15
+
16
+ permissions:
17
+ id-token: write # required for PyPI Trusted Publishing (OIDC)
18
+
19
+ steps:
20
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21
+ with:
22
+ fetch-depth: 0 # needed for setuptools_scm to derive version from git tags
23
+ - name: Set up Python
24
+ uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
25
+ with:
26
+ python-version: '3.x'
27
+ - name: Install build tools
28
+ run: python -m pip install --upgrade pip build twine
29
+ - name: Build distribution
30
+ run: python -m build
31
+ - name: Check distribution
32
+ run: twine check dist/*
33
+ - name: Publish to PyPI
34
+ uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
@@ -0,0 +1,31 @@
1
+ # Environment
2
+ .env
3
+
4
+ # Python virtual environment
5
+ venv/
6
+ .venv/
7
+
8
+ # Python compiled files
9
+ __pycache__/
10
+ *.py[cod]
11
+ *$py.class
12
+
13
+ # Distribution / packaging
14
+ dist/
15
+ build/
16
+ *.egg-info/
17
+ .eggs/
18
+
19
+ # Testing
20
+ .pytest_cache/
21
+ .coverage
22
+ coverage.xml
23
+ htmlcov/
24
+ *.log
25
+
26
+ # IDE
27
+ .vscode/
28
+ .idea/
29
+ *.swp
30
+ *.swo
31
+ *~
@@ -0,0 +1,31 @@
1
+ ci:
2
+ skip: [jenkinsfilelint]
3
+
4
+ repos:
5
+ - repo: https://github.com/pre-commit/pre-commit-hooks
6
+ rev: v6.0.0
7
+ hooks:
8
+ - id: check-yaml
9
+ - id: end-of-file-fixer
10
+ - id: trailing-whitespace
11
+ - id: check-added-large-files
12
+ - id: debug-statements
13
+ - repo: https://github.com/astral-sh/ruff-pre-commit
14
+ rev: v0.14.6
15
+ hooks:
16
+ - id: ruff-check
17
+ - id: ruff-format
18
+ - repo: local
19
+ # This is a "local" hook to run jenkinsfilelint
20
+ hooks:
21
+ - id: jenkinsfilelint
22
+ name: jenkinsfilelint
23
+ description: Lint Jenkinsfiles and Groovy files.
24
+ entry: jenkinsfilelint
25
+ language: python
26
+ additional_dependencies: ['requests']
27
+ files: (?i)^(.*/)?(Jenkinsfile[^/]*|.*\.groovy)$
28
+ exclude: ^jenkinsfilelint/
29
+ pass_filenames: true
30
+ verbose: true
31
+ stages: [manual] # pre-commit run jenkinsfilelint --all-files --hook-stage manual
@@ -0,0 +1,8 @@
1
+ - id: jenkinsfilelint
2
+ name: jenkinsfilelint
3
+ description: Lint Jenkinsfiles and Groovy files.
4
+ entry: jenkinsfilelint
5
+ language: python
6
+ types: [file]
7
+ files: ^.*(Jenkinsfile.*|.*\.groovy)$
8
+ require_serial: true
@@ -0,0 +1,28 @@
1
+ # Contributing
2
+
3
+ Contributions are welcome! Here's how to get started.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ pip install -e ".[dev]"
9
+ pre-commit install
10
+ ```
11
+
12
+ Run pre-commit before submitting:
13
+
14
+ ```bash
15
+ pre-commit run --all-files
16
+ ```
17
+
18
+ ## Testing
19
+
20
+ ```bash
21
+ pytest tests/ -v --cov=jenkinsfilelint
22
+ ```
23
+
24
+ ## Conventions
25
+
26
+ - Follow [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `chore:`, etc.)
27
+ - Keep PRs focused — one logical change per PR.
28
+ - Update the README if your change affects usage or configuration.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Xianpeng Shen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.4
2
+ Name: jenkinsfilelint
3
+ Version: 1.4.0
4
+ Summary: A Jenkinsfile linter that validates Jenkinsfiles using Jenkins API
5
+ Author-email: Xianpeng Shen <xianpeng.shen@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/shenxianpeng/jenkinsfilelint
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
17
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # Jenkinsfile Lint
21
+
22
+ [![CI](https://github.com/shenxianpeng/jenkinsfilelint/actions/workflows/main.yml/badge.svg)](https://github.com/shenxianpeng/jenkinsfilelint/actions/workflows/main.yml)
23
+ [![codecov](https://codecov.io/gh/shenxianpeng/jenkinsfilelint/graph/badge.svg?token=Z9UTXBL2XG)](https://codecov.io/gh/shenxianpeng/jenkinsfilelint)
24
+ [![PyPI version](https://img.shields.io/pypi/v/jenkinsfilelint )](https://pypi.org/project/jenkinsfilelint/)
25
+
26
+ Catch Jenkinsfile syntax errors before they break your CI.
27
+
28
+ `jenkinsfilelint` validates Jenkinsfiles through your real Jenkins instance and works as a CLI or pre-commit hook.
29
+
30
+ ## Table of Contents
31
+
32
+ - [Features](#features)
33
+ - [Installation](#installation)
34
+ - [Usage](#usage)
35
+ - [Security Notes](#security-notes)
36
+ - [How It Works](#how-it-works)
37
+ - [Requirements](#requirements)
38
+ - [License](#license)
39
+
40
+ ## Features
41
+
42
+ - Validates Jenkinsfiles using Jenkins REST API
43
+ - Works as a pre-commit hook
44
+ - Supports both command-line usage and environment variables for configuration
45
+ - Requires Jenkins credentials for validation
46
+ - Supports skipping files that are not Jenkins pipelines (e.g., pure Groovy helper classes)
47
+
48
+ ## Installation
49
+
50
+ ### Using pip
51
+
52
+ ```bash
53
+ pip install jenkinsfilelint
54
+ ```
55
+
56
+ ### Using pre-commit
57
+
58
+ Add this to your `.pre-commit-config.yaml`:
59
+
60
+ ```yaml
61
+ repos:
62
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
63
+ rev: # or specific version tag
64
+ hooks:
65
+ - id: jenkinsfilelint
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ > [!IMPORTANT]
71
+ > jenkinsfilelint requires Jenkins credentials to be set via environment variables for validation:
72
+ >
73
+ > - `JENKINS_URL`: Your Jenkins server URL (required)
74
+ > - `JENKINS_USER`: Your Jenkins username (required unless anonymous access is enabled)
75
+ > - `JENKINS_TOKEN`: Your Jenkins API token (required unless anonymous access is enabled)
76
+
77
+ ### Command Line
78
+
79
+ Validation requires Jenkins credentials. Set them using environment variables:
80
+
81
+ ```bash
82
+ export JENKINS_URL=https://your-jenkins-instance.com
83
+ export JENKINS_USER=your-username
84
+ export JENKINS_TOKEN=your-api-token
85
+
86
+ jenkinsfilelint path/to/Jenkinsfile
87
+ ```
88
+
89
+ Or using command-line arguments:
90
+
91
+ ```bash
92
+ jenkinsfilelint path/to/Jenkinsfile \
93
+ --jenkins-url https://your-jenkins-instance.com \
94
+ --username your-username \
95
+ --token your-api-token
96
+ ```
97
+
98
+ Validate multiple files:
99
+
100
+ ```bash
101
+ jenkinsfilelint Jenkinsfile Jenkinsfile.prod tests/Jenkinsfile
102
+ ```
103
+
104
+ ### Skipping Files
105
+
106
+ 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:
107
+
108
+ ```bash
109
+ # Skip a specific file pattern
110
+ jenkinsfilelint --skip '*/src/*.groovy' Jenkinsfile src/Utils.groovy
111
+
112
+ # Skip multiple patterns
113
+ jenkinsfilelint --skip '*/src/*.groovy' --skip 'vars/*.groovy' Jenkinsfile src/Utils.groovy vars/deploy.groovy
114
+ ```
115
+
116
+ The `--skip` option accepts glob patterns and can be used multiple times.
117
+
118
+ ### Including Only Specific Files
119
+
120
+ Use the `--include` option to validate only files that match specified patterns (whitelist approach). Files not matching any include pattern are silently skipped:
121
+
122
+ ```bash
123
+ # Only validate Jenkinsfiles (files starting with "Jenkinsfile")
124
+ jenkinsfilelint --include 'Jenkinsfile*' Jenkinsfile Jenkinsfile.prod src/Utils.groovy
125
+
126
+ # Only validate pipeline groovy files in a specific folder
127
+ jenkinsfilelint --include 'pipelines/*.groovy' pipelines/deploy.groovy src/Utils.groovy
128
+
129
+ # Use multiple include patterns
130
+ jenkinsfilelint --include 'Jenkinsfile*' --include 'pipelines/*.groovy' \
131
+ Jenkinsfile pipelines/deploy.groovy src/Utils.groovy
132
+ ```
133
+
134
+ The `--include` and `--skip` options can be combined: `--include` first narrows the set of files to consider, then `--skip` further excludes files within that set.
135
+
136
+ ### Pre-commit Hook
137
+
138
+ Create or update `.pre-commit-config.yaml` in your repository:
139
+
140
+ ```yaml
141
+ repos:
142
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
143
+ rev: # or specific version tag
144
+ hooks:
145
+ - id: jenkinsfilelint
146
+ ```
147
+
148
+ Or using command-line arguments:
149
+
150
+ ```yaml
151
+ repos:
152
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
153
+ rev: # or specific version tag
154
+ hooks:
155
+ - id: jenkinsfilelint
156
+ args: ["--jenkins-url=https://your-jenkins-instance.com", "--username=your-username", "--token=your-api-token"]
157
+ ```
158
+
159
+ To skip certain files (e.g., pure Groovy classes in Jenkins shared libraries):
160
+
161
+ ```yaml
162
+ repos:
163
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
164
+ rev: # or specific version tag
165
+ hooks:
166
+ - id: jenkinsfilelint
167
+ args: ["--skip=*/src/*.groovy", "--skip=vars/*.groovy"]
168
+ ```
169
+
170
+ To validate only specific files:
171
+
172
+ ```yaml
173
+ repos:
174
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
175
+ rev: # or specific version tag
176
+ hooks:
177
+ - id: jenkinsfilelint
178
+ args: ["--include=Jenkinsfile*", "--include=pipelines/*.groovy"]
179
+ ```
180
+
181
+ > [!WARNING]
182
+ > Using `args` to pass credentials directly in the configuration file is not recommended for security reasons.
183
+ > Consider using environment variables instead. For more details, see [pre-commit/pre-commit#758](https://github.com/pre-commit/pre-commit/issues/758#issuecomment-505935221).
184
+
185
+ Then install the pre-commit hook:
186
+
187
+ ```bash
188
+ pre-commit install
189
+ ```
190
+
191
+ ## Security Notes
192
+
193
+ - Do not commit Jenkins tokens to `.pre-commit-config.yaml` or `.env` .
194
+ - Prefer environment variables or local secret managers.
195
+ - Avoid using administrator tokens for local linting.
196
+
197
+ ## How It Works
198
+
199
+ > **What it is:** A Jenkinsfile syntax gate — not a Groovy formatter, not a static analyzer.
200
+
201
+ The linter sends the Jenkinsfile to your Jenkins instance's `/pipeline-model-converter/validate` endpoint for validation. If it passes here, it will pass on the server. Jenkins credentials (URL, username, and API token) are required.
202
+
203
+ ## Requirements
204
+
205
+ - Python 3.10+
206
+ - Jenkins server with Pipeline plugin installed
207
+
208
+ ## License
209
+
210
+ MIT License
@@ -0,0 +1,191 @@
1
+ # Jenkinsfile Lint
2
+
3
+ [![CI](https://github.com/shenxianpeng/jenkinsfilelint/actions/workflows/main.yml/badge.svg)](https://github.com/shenxianpeng/jenkinsfilelint/actions/workflows/main.yml)
4
+ [![codecov](https://codecov.io/gh/shenxianpeng/jenkinsfilelint/graph/badge.svg?token=Z9UTXBL2XG)](https://codecov.io/gh/shenxianpeng/jenkinsfilelint)
5
+ [![PyPI version](https://img.shields.io/pypi/v/jenkinsfilelint )](https://pypi.org/project/jenkinsfilelint/)
6
+
7
+ Catch Jenkinsfile syntax errors before they break your CI.
8
+
9
+ `jenkinsfilelint` validates Jenkinsfiles through your real Jenkins instance and works as a CLI or pre-commit hook.
10
+
11
+ ## Table of Contents
12
+
13
+ - [Features](#features)
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [Security Notes](#security-notes)
17
+ - [How It Works](#how-it-works)
18
+ - [Requirements](#requirements)
19
+ - [License](#license)
20
+
21
+ ## Features
22
+
23
+ - Validates Jenkinsfiles using Jenkins REST API
24
+ - Works as a pre-commit hook
25
+ - Supports both command-line usage and environment variables for configuration
26
+ - Requires Jenkins credentials for validation
27
+ - Supports skipping files that are not Jenkins pipelines (e.g., pure Groovy helper classes)
28
+
29
+ ## Installation
30
+
31
+ ### Using pip
32
+
33
+ ```bash
34
+ pip install jenkinsfilelint
35
+ ```
36
+
37
+ ### Using pre-commit
38
+
39
+ Add this to your `.pre-commit-config.yaml`:
40
+
41
+ ```yaml
42
+ repos:
43
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
44
+ rev: # or specific version tag
45
+ hooks:
46
+ - id: jenkinsfilelint
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ > [!IMPORTANT]
52
+ > jenkinsfilelint requires Jenkins credentials to be set via environment variables for validation:
53
+ >
54
+ > - `JENKINS_URL`: Your Jenkins server URL (required)
55
+ > - `JENKINS_USER`: Your Jenkins username (required unless anonymous access is enabled)
56
+ > - `JENKINS_TOKEN`: Your Jenkins API token (required unless anonymous access is enabled)
57
+
58
+ ### Command Line
59
+
60
+ Validation requires Jenkins credentials. Set them using environment variables:
61
+
62
+ ```bash
63
+ export JENKINS_URL=https://your-jenkins-instance.com
64
+ export JENKINS_USER=your-username
65
+ export JENKINS_TOKEN=your-api-token
66
+
67
+ jenkinsfilelint path/to/Jenkinsfile
68
+ ```
69
+
70
+ Or using command-line arguments:
71
+
72
+ ```bash
73
+ jenkinsfilelint path/to/Jenkinsfile \
74
+ --jenkins-url https://your-jenkins-instance.com \
75
+ --username your-username \
76
+ --token your-api-token
77
+ ```
78
+
79
+ Validate multiple files:
80
+
81
+ ```bash
82
+ jenkinsfilelint Jenkinsfile Jenkinsfile.prod tests/Jenkinsfile
83
+ ```
84
+
85
+ ### Skipping Files
86
+
87
+ 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:
88
+
89
+ ```bash
90
+ # Skip a specific file pattern
91
+ jenkinsfilelint --skip '*/src/*.groovy' Jenkinsfile src/Utils.groovy
92
+
93
+ # Skip multiple patterns
94
+ jenkinsfilelint --skip '*/src/*.groovy' --skip 'vars/*.groovy' Jenkinsfile src/Utils.groovy vars/deploy.groovy
95
+ ```
96
+
97
+ The `--skip` option accepts glob patterns and can be used multiple times.
98
+
99
+ ### Including Only Specific Files
100
+
101
+ Use the `--include` option to validate only files that match specified patterns (whitelist approach). Files not matching any include pattern are silently skipped:
102
+
103
+ ```bash
104
+ # Only validate Jenkinsfiles (files starting with "Jenkinsfile")
105
+ jenkinsfilelint --include 'Jenkinsfile*' Jenkinsfile Jenkinsfile.prod src/Utils.groovy
106
+
107
+ # Only validate pipeline groovy files in a specific folder
108
+ jenkinsfilelint --include 'pipelines/*.groovy' pipelines/deploy.groovy src/Utils.groovy
109
+
110
+ # Use multiple include patterns
111
+ jenkinsfilelint --include 'Jenkinsfile*' --include 'pipelines/*.groovy' \
112
+ Jenkinsfile pipelines/deploy.groovy src/Utils.groovy
113
+ ```
114
+
115
+ The `--include` and `--skip` options can be combined: `--include` first narrows the set of files to consider, then `--skip` further excludes files within that set.
116
+
117
+ ### Pre-commit Hook
118
+
119
+ Create or update `.pre-commit-config.yaml` in your repository:
120
+
121
+ ```yaml
122
+ repos:
123
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
124
+ rev: # or specific version tag
125
+ hooks:
126
+ - id: jenkinsfilelint
127
+ ```
128
+
129
+ Or using command-line arguments:
130
+
131
+ ```yaml
132
+ repos:
133
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
134
+ rev: # or specific version tag
135
+ hooks:
136
+ - id: jenkinsfilelint
137
+ args: ["--jenkins-url=https://your-jenkins-instance.com", "--username=your-username", "--token=your-api-token"]
138
+ ```
139
+
140
+ To skip certain files (e.g., pure Groovy classes in Jenkins shared libraries):
141
+
142
+ ```yaml
143
+ repos:
144
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
145
+ rev: # or specific version tag
146
+ hooks:
147
+ - id: jenkinsfilelint
148
+ args: ["--skip=*/src/*.groovy", "--skip=vars/*.groovy"]
149
+ ```
150
+
151
+ To validate only specific files:
152
+
153
+ ```yaml
154
+ repos:
155
+ - repo: https://github.com/shenxianpeng/jenkinsfilelint
156
+ rev: # or specific version tag
157
+ hooks:
158
+ - id: jenkinsfilelint
159
+ args: ["--include=Jenkinsfile*", "--include=pipelines/*.groovy"]
160
+ ```
161
+
162
+ > [!WARNING]
163
+ > Using `args` to pass credentials directly in the configuration file is not recommended for security reasons.
164
+ > Consider using environment variables instead. For more details, see [pre-commit/pre-commit#758](https://github.com/pre-commit/pre-commit/issues/758#issuecomment-505935221).
165
+
166
+ Then install the pre-commit hook:
167
+
168
+ ```bash
169
+ pre-commit install
170
+ ```
171
+
172
+ ## Security Notes
173
+
174
+ - Do not commit Jenkins tokens to `.pre-commit-config.yaml` or `.env` .
175
+ - Prefer environment variables or local secret managers.
176
+ - Avoid using administrator tokens for local linting.
177
+
178
+ ## How It Works
179
+
180
+ > **What it is:** A Jenkinsfile syntax gate — not a Groovy formatter, not a static analyzer.
181
+
182
+ The linter sends the Jenkinsfile to your Jenkins instance's `/pipeline-model-converter/validate` endpoint for validation. If it passes here, it will pass on the server. Jenkins credentials (URL, username, and API token) are required.
183
+
184
+ ## Requirements
185
+
186
+ - Python 3.10+
187
+ - Jenkins server with Pipeline plugin installed
188
+
189
+ ## License
190
+
191
+ MIT License
@@ -0,0 +1,9 @@
1
+ """Jenkinsfile linter package."""
2
+
3
+ from importlib.metadata import version, PackageNotFoundError
4
+
5
+ try:
6
+ __version__ = version("jenkinsfilelint")
7
+ except PackageNotFoundError:
8
+ # Package is not installed
9
+ __version__ = "0.0.0.dev0"