python-jcli 0.1.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.
- python_jcli-0.1.0/PKG-INFO +311 -0
- python_jcli-0.1.0/README.md +295 -0
- python_jcli-0.1.0/jcli/__init__.py +1 -0
- python_jcli-0.1.0/jcli/__main__.py +3 -0
- python_jcli-0.1.0/jcli/cli.py +79 -0
- python_jcli-0.1.0/jcli/cli_helpers.py +58 -0
- python_jcli-0.1.0/jcli/plugins/__init__.py +28 -0
- python_jcli-0.1.0/jcli/plugins/build.py +197 -0
- python_jcli-0.1.0/jcli/plugins/config.py +268 -0
- python_jcli-0.1.0/jcli/plugins/credential.py +210 -0
- python_jcli-0.1.0/jcli/plugins/job.py +425 -0
- python_jcli-0.1.0/jcli/plugins/node.py +134 -0
- python_jcli-0.1.0/jcli/plugins/pipeline.py +108 -0
- python_jcli-0.1.0/jcli/plugins/plugin.py +173 -0
- python_jcli-0.1.0/jcli/plugins/skills.py +399 -0
- python_jcli-0.1.0/jcli/plugins/system.py +173 -0
- python_jcli-0.1.0/jcli/plugins/view.py +148 -0
- python_jcli-0.1.0/jcli/sdk/__init__.py +0 -0
- python_jcli-0.1.0/jcli/sdk/build.py +182 -0
- python_jcli-0.1.0/jcli/sdk/client.py +264 -0
- python_jcli-0.1.0/jcli/sdk/config.py +227 -0
- python_jcli-0.1.0/jcli/sdk/credential.py +143 -0
- python_jcli-0.1.0/jcli/sdk/exceptions.py +59 -0
- python_jcli-0.1.0/jcli/sdk/job.py +191 -0
- python_jcli-0.1.0/jcli/sdk/job_templates.py +128 -0
- python_jcli-0.1.0/jcli/sdk/node.py +139 -0
- python_jcli-0.1.0/jcli/sdk/output/__init__.py +3 -0
- python_jcli-0.1.0/jcli/sdk/output/formatter.py +131 -0
- python_jcli-0.1.0/jcli/sdk/pipeline.py +121 -0
- python_jcli-0.1.0/jcli/sdk/plugin.py +155 -0
- python_jcli-0.1.0/jcli/sdk/system.py +202 -0
- python_jcli-0.1.0/jcli/sdk/view.py +94 -0
- python_jcli-0.1.0/jcli/skills/jcli/SKILL.md +73 -0
- python_jcli-0.1.0/jcli/skills/jcli/config/SKILL.md +81 -0
- python_jcli-0.1.0/jcli/skills/jcli/credential/SKILL.md +47 -0
- python_jcli-0.1.0/jcli/skills/jcli/job/SKILL.md +55 -0
- python_jcli-0.1.0/jcli/skills/jcli/node/SKILL.md +51 -0
- python_jcli-0.1.0/jcli/skills/jcli/pipeline/SKILL.md +58 -0
- python_jcli-0.1.0/jcli/skills/jcli/plugin/SKILL.md +51 -0
- python_jcli-0.1.0/jcli/skills/jcli/system/SKILL.md +70 -0
- python_jcli-0.1.0/jcli/skills/jcli/view/SKILL.md +47 -0
- python_jcli-0.1.0/pyproject.toml +36 -0
- python_jcli-0.1.0/python_jcli.egg-info/PKG-INFO +311 -0
- python_jcli-0.1.0/python_jcli.egg-info/SOURCES.txt +60 -0
- python_jcli-0.1.0/python_jcli.egg-info/dependency_links.txt +1 -0
- python_jcli-0.1.0/python_jcli.egg-info/entry_points.txt +2 -0
- python_jcli-0.1.0/python_jcli.egg-info/requires.txt +9 -0
- python_jcli-0.1.0/python_jcli.egg-info/top_level.txt +1 -0
- python_jcli-0.1.0/setup.cfg +4 -0
- python_jcli-0.1.0/tests/test_build.py +915 -0
- python_jcli-0.1.0/tests/test_cli.py +269 -0
- python_jcli-0.1.0/tests/test_client.py +539 -0
- python_jcli-0.1.0/tests/test_config.py +269 -0
- python_jcli-0.1.0/tests/test_credential.py +774 -0
- python_jcli-0.1.0/tests/test_exceptions.py +105 -0
- python_jcli-0.1.0/tests/test_job.py +1375 -0
- python_jcli-0.1.0/tests/test_node.py +420 -0
- python_jcli-0.1.0/tests/test_pipeline.py +544 -0
- python_jcli-0.1.0/tests/test_plugin.py +822 -0
- python_jcli-0.1.0/tests/test_skills.py +278 -0
- python_jcli-0.1.0/tests/test_system.py +877 -0
- python_jcli-0.1.0/tests/test_view.py +679 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-jcli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python Jenkins CLI tool
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: click>=8.1.0
|
|
9
|
+
Requires-Dist: requests~=2.31.0
|
|
10
|
+
Requires-Dist: pyyaml~=6.0.1
|
|
11
|
+
Requires-Dist: rich>=13.7.1
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
14
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
15
|
+
Requires-Dist: responses>=0.23.0; extra == "dev"
|
|
16
|
+
|
|
17
|
+
# jcli
|
|
18
|
+
|
|
19
|
+
A command-line tool for managing Jenkins servers. jcli wraps the Jenkins REST API into readable commands that work the way you'd expect, with table, JSON, and YAML output options.
|
|
20
|
+
|
|
21
|
+
[中文文档](README-zh.md)
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **8 command modules** covering jobs, builds, nodes, plugins, credentials, pipelines, views, and system management
|
|
26
|
+
- **Multiple output formats**: human-readable tables (default, via Rich), JSON, and YAML
|
|
27
|
+
- **Multi-profile support** via `~/.jcli/config.yaml` with environment variable overrides
|
|
28
|
+
- **Automatic CSRF (Crumb) handling** for Jenkins servers with CSRF protection enabled
|
|
29
|
+
- **Built with Click and Rich** for a polished terminal experience
|
|
30
|
+
|
|
31
|
+
## Requirements
|
|
32
|
+
|
|
33
|
+
- Python 3.10 or later
|
|
34
|
+
- A Jenkins server running Jenkins 2.x or later
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
Install from source with pip:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or in editable mode for development:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install -e ".[dev]"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
After installation, `jcli` is available as a console script.
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
### 1. Configure your Jenkins connection
|
|
55
|
+
|
|
56
|
+
Create a configuration file at `~/.jcli/config.yaml`:
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
active_profile: default
|
|
60
|
+
profiles:
|
|
61
|
+
default:
|
|
62
|
+
url: https://jenkins.example.com
|
|
63
|
+
username: admin
|
|
64
|
+
api_token: "11abcdef0123456789abcdef0123456789ab"
|
|
65
|
+
description: "Production Jenkins"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
If the file doesn't exist, jcli creates it with a template on first run.
|
|
69
|
+
|
|
70
|
+
To generate an API token, go to your Jenkins user page: **Your Username > Configure > API Token > Add new Token**.
|
|
71
|
+
|
|
72
|
+
### 2. Run your first command
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
jcli job list
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
If your server is configured correctly, this prints a table of all Jenkins jobs.
|
|
79
|
+
|
|
80
|
+
## Configuration
|
|
81
|
+
|
|
82
|
+
### Config file
|
|
83
|
+
|
|
84
|
+
jcli stores profiles in `~/.jcli/config.yaml`. Each profile has four fields:
|
|
85
|
+
|
|
86
|
+
| Field | Description |
|
|
87
|
+
|-------------|----------------------------|
|
|
88
|
+
| `url` | Jenkins server URL |
|
|
89
|
+
| `username` | Jenkins username |
|
|
90
|
+
| `api_token` | Jenkins API token |
|
|
91
|
+
| `description` | Human-readable description |
|
|
92
|
+
|
|
93
|
+
The `active_profile` key selects which profile to use.
|
|
94
|
+
|
|
95
|
+
To add another server profile, edit the file and add a new entry under `profiles`:
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
active_profile: prod
|
|
99
|
+
profiles:
|
|
100
|
+
prod:
|
|
101
|
+
url: https://jenkins.prod.example.com
|
|
102
|
+
username: admin
|
|
103
|
+
api_token: "..."
|
|
104
|
+
description: "Production"
|
|
105
|
+
staging:
|
|
106
|
+
url: https://jenkins.staging.example.com
|
|
107
|
+
username: admin
|
|
108
|
+
api_token: "..."
|
|
109
|
+
description: "Staging"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Environment variables
|
|
113
|
+
|
|
114
|
+
Environment variables override config file values. This is useful in CI pipelines.
|
|
115
|
+
|
|
116
|
+
| Variable | Overrides |
|
|
117
|
+
|-------------------|---------------------|
|
|
118
|
+
| `JCLI_URL` | `url` |
|
|
119
|
+
| `JCLI_USERNAME` | `username` |
|
|
120
|
+
| `JCLI_API_TOKEN` | `api_token` |
|
|
121
|
+
| `JCLI_PROFILE` | `active_profile` |
|
|
122
|
+
|
|
123
|
+
Set `JCLI_PROFILE` to select a profile without editing the config file.
|
|
124
|
+
|
|
125
|
+
### CLI options
|
|
126
|
+
|
|
127
|
+
Profile and server can also be set with command-line flags:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
jcli -p staging job list # use the "staging" profile
|
|
131
|
+
jcli -s https://ci.example.com job list # override server URL
|
|
132
|
+
jcli -d job list # enable debug logging
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Run `jcli --help` for the full option list.
|
|
136
|
+
|
|
137
|
+
## Command Reference
|
|
138
|
+
|
|
139
|
+
### Global options
|
|
140
|
+
|
|
141
|
+
Every command accepts these global flags before the subcommand:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
-d, --debug Enable debug output
|
|
145
|
+
-f, --format [table|json|yaml] Output format (default: table)
|
|
146
|
+
-p, --profile TEXT Configuration profile name
|
|
147
|
+
-s, --server TEXT Jenkins server URL
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### job — Manage Jenkins jobs
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
jcli job list List all jobs
|
|
154
|
+
jcli job get JOB_NAME Show details for a specific job
|
|
155
|
+
jcli job create JOB_NAME -f job-config.xml Create a new job from XML config file
|
|
156
|
+
jcli job config JOB_NAME Print the XML configuration of a job
|
|
157
|
+
jcli job copy SOURCE_JOB NEW_NAME Copy a job to a new name
|
|
158
|
+
jcli job enable JOB_NAME Enable a disabled job
|
|
159
|
+
jcli job disable JOB_NAME Disable a job
|
|
160
|
+
jcli job delete JOB_NAME Delete a job
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### build — Manage Jenkins builds
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
jcli build list JOB_NAME List recent builds for a job
|
|
167
|
+
jcli build get JOB_NAME BUILD_NUMBER Show details for a specific build
|
|
168
|
+
jcli build trigger JOB_NAME Trigger a new build
|
|
169
|
+
jcli build log JOB_NAME BUILD_NUMBER Show console log for a build
|
|
170
|
+
jcli build stop JOB_NAME BUILD_NUMBER Stop a running build
|
|
171
|
+
jcli build queue Show the current build queue
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### node — Manage Jenkins nodes (agents)
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
jcli node list List all nodes
|
|
178
|
+
jcli node get NODE_NAME Get details of a specific node
|
|
179
|
+
jcli node delete NODE_NAME Delete a node
|
|
180
|
+
jcli node toggle NODE_NAME --offline Take a node offline
|
|
181
|
+
jcli node toggle NODE_NAME --online Bring a node back online
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### plugin — Manage Jenkins plugins
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
jcli plugin list List installed plugins
|
|
188
|
+
jcli plugin get PLUGIN_NAME Show details for a single plugin
|
|
189
|
+
jcli plugin install PLUGIN_NAME Install a plugin
|
|
190
|
+
jcli plugin uninstall PLUGIN_NAME Uninstall a plugin
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### credential — Manage Jenkins credentials
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
jcli credential list List credentials
|
|
197
|
+
jcli credential get CREDENTIAL_NAME Get credential details
|
|
198
|
+
jcli credential create -f cred-config.xml Create a credential from XML config
|
|
199
|
+
jcli credential delete CREDENTIAL_NAME Delete a credential
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### pipeline — Manage Jenkins pipelines
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
jcli pipeline stages JOB_NAME BUILD_NUMBER List stages for a Pipeline build
|
|
206
|
+
jcli pipeline log JOB_NAME BUILD_NUMBER Get log output for a Pipeline step
|
|
207
|
+
jcli pipeline pending JOB_NAME BUILD_NUMBER Show pending input actions
|
|
208
|
+
jcli pipeline validate -f Jenkinsfile Validate a Jenkinsfile against the server
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### view — Manage Jenkins views
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
jcli view list List all views
|
|
215
|
+
jcli view get VIEW_NAME Get details for a view
|
|
216
|
+
jcli view create -f view-config.xml Create a view from XML config
|
|
217
|
+
jcli view delete VIEW_NAME Delete a view
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### system — Jenkins system information and management
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
jcli system info Show system version and stats
|
|
224
|
+
jcli system load Show queue length and executor counts
|
|
225
|
+
jcli system quiet-down Put Jenkins into quiet-down mode
|
|
226
|
+
jcli system cancel-quiet-down Cancel quiet-down mode
|
|
227
|
+
jcli system restart Trigger a safe restart
|
|
228
|
+
jcli system script "println('hello')" Execute a Groovy script on the server
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Output Formats
|
|
232
|
+
|
|
233
|
+
jcli supports three output formats, selectable with `-f` / `--format`:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
jcli -f table job list # Rich-formatted table (default)
|
|
237
|
+
jcli -f json job list # JSON output
|
|
238
|
+
jcli -f yaml job list # YAML output
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Table mode uses the [Rich](https://github.com/Textualize/rich) library with alternating row colors and auto-width columns. Pipe the output to any file or command as needed.
|
|
242
|
+
|
|
243
|
+
## Development
|
|
244
|
+
|
|
245
|
+
### Setup
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
git clone <repo-url> jcli
|
|
249
|
+
cd jcli
|
|
250
|
+
pip install -e ".[dev]"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Running tests
|
|
254
|
+
|
|
255
|
+
The test suite uses pytest with the `responses` library for HTTP mocking:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pytest
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
For coverage:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
pytest --cov=jcli --cov-report=term-missing
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Project structure
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
jcli/
|
|
271
|
+
cli.py Main CLI entry point (Click group)
|
|
272
|
+
__init__.py Version
|
|
273
|
+
plugins/ Command modules (one per Jenkins domain)
|
|
274
|
+
job.py
|
|
275
|
+
build.py
|
|
276
|
+
node.py
|
|
277
|
+
plugin.py
|
|
278
|
+
credential.py
|
|
279
|
+
pipeline.py
|
|
280
|
+
view.py
|
|
281
|
+
system.py
|
|
282
|
+
sdk/ Shared libraries
|
|
283
|
+
client.py Jenkins REST API client (HTTP, auth, crumb)
|
|
284
|
+
config.py Configuration management (YAML, env vars)
|
|
285
|
+
output/
|
|
286
|
+
formatter.py Table/JSON/YAML output formatting
|
|
287
|
+
exceptions.py Typed exceptions
|
|
288
|
+
tests/ pytest test suite
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Dependencies
|
|
292
|
+
|
|
293
|
+
| Package | Purpose |
|
|
294
|
+
|-----------------|-----------------------------|
|
|
295
|
+
| click >= 8.1.0 | CLI framework |
|
|
296
|
+
| requests ~= 2.31 | HTTP client |
|
|
297
|
+
| pyyaml ~= 6.0.1 | YAML config parsing |
|
|
298
|
+
| rich >= 13.7.1 | Terminal formatting (tables) |
|
|
299
|
+
| argcomplete >= 3.3 | Shell tab completion |
|
|
300
|
+
|
|
301
|
+
Dev dependencies (optional `[dev]` extra):
|
|
302
|
+
|
|
303
|
+
| Package | Purpose |
|
|
304
|
+
|-----------------|-----------------------------|
|
|
305
|
+
| pytest >= 7.0 | Test runner |
|
|
306
|
+
| pytest-cov >= 4.0 | Coverage reporting |
|
|
307
|
+
| responses >= 0.23 | HTTP response mocking |
|
|
308
|
+
|
|
309
|
+
## License
|
|
310
|
+
|
|
311
|
+
MIT
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# jcli
|
|
2
|
+
|
|
3
|
+
A command-line tool for managing Jenkins servers. jcli wraps the Jenkins REST API into readable commands that work the way you'd expect, with table, JSON, and YAML output options.
|
|
4
|
+
|
|
5
|
+
[中文文档](README-zh.md)
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **8 command modules** covering jobs, builds, nodes, plugins, credentials, pipelines, views, and system management
|
|
10
|
+
- **Multiple output formats**: human-readable tables (default, via Rich), JSON, and YAML
|
|
11
|
+
- **Multi-profile support** via `~/.jcli/config.yaml` with environment variable overrides
|
|
12
|
+
- **Automatic CSRF (Crumb) handling** for Jenkins servers with CSRF protection enabled
|
|
13
|
+
- **Built with Click and Rich** for a polished terminal experience
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Python 3.10 or later
|
|
18
|
+
- A Jenkins server running Jenkins 2.x or later
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Install from source with pip:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or in editable mode for development:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install -e ".[dev]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
After installation, `jcli` is available as a console script.
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### 1. Configure your Jenkins connection
|
|
39
|
+
|
|
40
|
+
Create a configuration file at `~/.jcli/config.yaml`:
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
active_profile: default
|
|
44
|
+
profiles:
|
|
45
|
+
default:
|
|
46
|
+
url: https://jenkins.example.com
|
|
47
|
+
username: admin
|
|
48
|
+
api_token: "11abcdef0123456789abcdef0123456789ab"
|
|
49
|
+
description: "Production Jenkins"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If the file doesn't exist, jcli creates it with a template on first run.
|
|
53
|
+
|
|
54
|
+
To generate an API token, go to your Jenkins user page: **Your Username > Configure > API Token > Add new Token**.
|
|
55
|
+
|
|
56
|
+
### 2. Run your first command
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
jcli job list
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
If your server is configured correctly, this prints a table of all Jenkins jobs.
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
### Config file
|
|
67
|
+
|
|
68
|
+
jcli stores profiles in `~/.jcli/config.yaml`. Each profile has four fields:
|
|
69
|
+
|
|
70
|
+
| Field | Description |
|
|
71
|
+
|-------------|----------------------------|
|
|
72
|
+
| `url` | Jenkins server URL |
|
|
73
|
+
| `username` | Jenkins username |
|
|
74
|
+
| `api_token` | Jenkins API token |
|
|
75
|
+
| `description` | Human-readable description |
|
|
76
|
+
|
|
77
|
+
The `active_profile` key selects which profile to use.
|
|
78
|
+
|
|
79
|
+
To add another server profile, edit the file and add a new entry under `profiles`:
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
active_profile: prod
|
|
83
|
+
profiles:
|
|
84
|
+
prod:
|
|
85
|
+
url: https://jenkins.prod.example.com
|
|
86
|
+
username: admin
|
|
87
|
+
api_token: "..."
|
|
88
|
+
description: "Production"
|
|
89
|
+
staging:
|
|
90
|
+
url: https://jenkins.staging.example.com
|
|
91
|
+
username: admin
|
|
92
|
+
api_token: "..."
|
|
93
|
+
description: "Staging"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Environment variables
|
|
97
|
+
|
|
98
|
+
Environment variables override config file values. This is useful in CI pipelines.
|
|
99
|
+
|
|
100
|
+
| Variable | Overrides |
|
|
101
|
+
|-------------------|---------------------|
|
|
102
|
+
| `JCLI_URL` | `url` |
|
|
103
|
+
| `JCLI_USERNAME` | `username` |
|
|
104
|
+
| `JCLI_API_TOKEN` | `api_token` |
|
|
105
|
+
| `JCLI_PROFILE` | `active_profile` |
|
|
106
|
+
|
|
107
|
+
Set `JCLI_PROFILE` to select a profile without editing the config file.
|
|
108
|
+
|
|
109
|
+
### CLI options
|
|
110
|
+
|
|
111
|
+
Profile and server can also be set with command-line flags:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
jcli -p staging job list # use the "staging" profile
|
|
115
|
+
jcli -s https://ci.example.com job list # override server URL
|
|
116
|
+
jcli -d job list # enable debug logging
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Run `jcli --help` for the full option list.
|
|
120
|
+
|
|
121
|
+
## Command Reference
|
|
122
|
+
|
|
123
|
+
### Global options
|
|
124
|
+
|
|
125
|
+
Every command accepts these global flags before the subcommand:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
-d, --debug Enable debug output
|
|
129
|
+
-f, --format [table|json|yaml] Output format (default: table)
|
|
130
|
+
-p, --profile TEXT Configuration profile name
|
|
131
|
+
-s, --server TEXT Jenkins server URL
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### job — Manage Jenkins jobs
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
jcli job list List all jobs
|
|
138
|
+
jcli job get JOB_NAME Show details for a specific job
|
|
139
|
+
jcli job create JOB_NAME -f job-config.xml Create a new job from XML config file
|
|
140
|
+
jcli job config JOB_NAME Print the XML configuration of a job
|
|
141
|
+
jcli job copy SOURCE_JOB NEW_NAME Copy a job to a new name
|
|
142
|
+
jcli job enable JOB_NAME Enable a disabled job
|
|
143
|
+
jcli job disable JOB_NAME Disable a job
|
|
144
|
+
jcli job delete JOB_NAME Delete a job
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### build — Manage Jenkins builds
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
jcli build list JOB_NAME List recent builds for a job
|
|
151
|
+
jcli build get JOB_NAME BUILD_NUMBER Show details for a specific build
|
|
152
|
+
jcli build trigger JOB_NAME Trigger a new build
|
|
153
|
+
jcli build log JOB_NAME BUILD_NUMBER Show console log for a build
|
|
154
|
+
jcli build stop JOB_NAME BUILD_NUMBER Stop a running build
|
|
155
|
+
jcli build queue Show the current build queue
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### node — Manage Jenkins nodes (agents)
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
jcli node list List all nodes
|
|
162
|
+
jcli node get NODE_NAME Get details of a specific node
|
|
163
|
+
jcli node delete NODE_NAME Delete a node
|
|
164
|
+
jcli node toggle NODE_NAME --offline Take a node offline
|
|
165
|
+
jcli node toggle NODE_NAME --online Bring a node back online
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### plugin — Manage Jenkins plugins
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
jcli plugin list List installed plugins
|
|
172
|
+
jcli plugin get PLUGIN_NAME Show details for a single plugin
|
|
173
|
+
jcli plugin install PLUGIN_NAME Install a plugin
|
|
174
|
+
jcli plugin uninstall PLUGIN_NAME Uninstall a plugin
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### credential — Manage Jenkins credentials
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
jcli credential list List credentials
|
|
181
|
+
jcli credential get CREDENTIAL_NAME Get credential details
|
|
182
|
+
jcli credential create -f cred-config.xml Create a credential from XML config
|
|
183
|
+
jcli credential delete CREDENTIAL_NAME Delete a credential
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### pipeline — Manage Jenkins pipelines
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
jcli pipeline stages JOB_NAME BUILD_NUMBER List stages for a Pipeline build
|
|
190
|
+
jcli pipeline log JOB_NAME BUILD_NUMBER Get log output for a Pipeline step
|
|
191
|
+
jcli pipeline pending JOB_NAME BUILD_NUMBER Show pending input actions
|
|
192
|
+
jcli pipeline validate -f Jenkinsfile Validate a Jenkinsfile against the server
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### view — Manage Jenkins views
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
jcli view list List all views
|
|
199
|
+
jcli view get VIEW_NAME Get details for a view
|
|
200
|
+
jcli view create -f view-config.xml Create a view from XML config
|
|
201
|
+
jcli view delete VIEW_NAME Delete a view
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### system — Jenkins system information and management
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
jcli system info Show system version and stats
|
|
208
|
+
jcli system load Show queue length and executor counts
|
|
209
|
+
jcli system quiet-down Put Jenkins into quiet-down mode
|
|
210
|
+
jcli system cancel-quiet-down Cancel quiet-down mode
|
|
211
|
+
jcli system restart Trigger a safe restart
|
|
212
|
+
jcli system script "println('hello')" Execute a Groovy script on the server
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Output Formats
|
|
216
|
+
|
|
217
|
+
jcli supports three output formats, selectable with `-f` / `--format`:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
jcli -f table job list # Rich-formatted table (default)
|
|
221
|
+
jcli -f json job list # JSON output
|
|
222
|
+
jcli -f yaml job list # YAML output
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Table mode uses the [Rich](https://github.com/Textualize/rich) library with alternating row colors and auto-width columns. Pipe the output to any file or command as needed.
|
|
226
|
+
|
|
227
|
+
## Development
|
|
228
|
+
|
|
229
|
+
### Setup
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
git clone <repo-url> jcli
|
|
233
|
+
cd jcli
|
|
234
|
+
pip install -e ".[dev]"
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Running tests
|
|
238
|
+
|
|
239
|
+
The test suite uses pytest with the `responses` library for HTTP mocking:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
pytest
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
For coverage:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
pytest --cov=jcli --cov-report=term-missing
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Project structure
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
jcli/
|
|
255
|
+
cli.py Main CLI entry point (Click group)
|
|
256
|
+
__init__.py Version
|
|
257
|
+
plugins/ Command modules (one per Jenkins domain)
|
|
258
|
+
job.py
|
|
259
|
+
build.py
|
|
260
|
+
node.py
|
|
261
|
+
plugin.py
|
|
262
|
+
credential.py
|
|
263
|
+
pipeline.py
|
|
264
|
+
view.py
|
|
265
|
+
system.py
|
|
266
|
+
sdk/ Shared libraries
|
|
267
|
+
client.py Jenkins REST API client (HTTP, auth, crumb)
|
|
268
|
+
config.py Configuration management (YAML, env vars)
|
|
269
|
+
output/
|
|
270
|
+
formatter.py Table/JSON/YAML output formatting
|
|
271
|
+
exceptions.py Typed exceptions
|
|
272
|
+
tests/ pytest test suite
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Dependencies
|
|
276
|
+
|
|
277
|
+
| Package | Purpose |
|
|
278
|
+
|-----------------|-----------------------------|
|
|
279
|
+
| click >= 8.1.0 | CLI framework |
|
|
280
|
+
| requests ~= 2.31 | HTTP client |
|
|
281
|
+
| pyyaml ~= 6.0.1 | YAML config parsing |
|
|
282
|
+
| rich >= 13.7.1 | Terminal formatting (tables) |
|
|
283
|
+
| argcomplete >= 3.3 | Shell tab completion |
|
|
284
|
+
|
|
285
|
+
Dev dependencies (optional `[dev]` extra):
|
|
286
|
+
|
|
287
|
+
| Package | Purpose |
|
|
288
|
+
|-----------------|-----------------------------|
|
|
289
|
+
| pytest >= 7.0 | Test runner |
|
|
290
|
+
| pytest-cov >= 4.0 | Coverage reporting |
|
|
291
|
+
| responses >= 0.23 | HTTP response mocking |
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Jenkins CLI - Command line interface for managing Jenkins."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
from jcli import __version__
|
|
9
|
+
from jcli.plugins import register_commands
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger("jcli")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@click.group()
|
|
15
|
+
@click.version_option(version=__version__, prog_name="jcli")
|
|
16
|
+
@click.option(
|
|
17
|
+
"-f",
|
|
18
|
+
"--format",
|
|
19
|
+
"output_format",
|
|
20
|
+
default="table",
|
|
21
|
+
type=click.Choice(["table", "json", "yaml"]),
|
|
22
|
+
help="Output format.",
|
|
23
|
+
)
|
|
24
|
+
@click.option("-p", "--profile", default=None, help="Configuration profile name.")
|
|
25
|
+
@click.option("-s", "--server", default=None, help="Jenkins server URL.")
|
|
26
|
+
@click.option("-d", "--debug", is_flag=True, default=False, help="Enable debug output.")
|
|
27
|
+
@click.pass_context
|
|
28
|
+
def cli(ctx, output_format, profile, server, debug):
|
|
29
|
+
"""Jenkins CLI - Manage Jenkins from the command line."""
|
|
30
|
+
ctx.ensure_object(dict)
|
|
31
|
+
ctx.obj["format"] = output_format
|
|
32
|
+
ctx.obj["profile"] = profile
|
|
33
|
+
ctx.obj["server"] = server
|
|
34
|
+
ctx.obj["debug"] = debug
|
|
35
|
+
|
|
36
|
+
# Configure debug logging when --debug / -d is set
|
|
37
|
+
if debug:
|
|
38
|
+
logging.basicConfig(
|
|
39
|
+
level=logging.DEBUG,
|
|
40
|
+
format="%(asctime)s %(name)s %(levelname)s %(message)s",
|
|
41
|
+
stream=sys.stderr,
|
|
42
|
+
)
|
|
43
|
+
logger.debug("Debug logging enabled")
|
|
44
|
+
else:
|
|
45
|
+
# Ensure WARNING+ level when not in debug mode
|
|
46
|
+
logging.basicConfig(level=logging.WARNING, stream=sys.stderr)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Register all plugin subcommands
|
|
50
|
+
register_commands(cli)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@click.group()
|
|
54
|
+
def completion():
|
|
55
|
+
"""Shell completion support for jcli."""
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@completion.command()
|
|
60
|
+
@click.argument("shell", type=click.Choice(["bash", "zsh", "fish"]))
|
|
61
|
+
def show(shell):
|
|
62
|
+
"""Output shell completion script for the specified shell."""
|
|
63
|
+
from click.shell_completion import BashComplete, ZshComplete, FishComplete
|
|
64
|
+
|
|
65
|
+
shell_cls = {"bash": BashComplete, "zsh": ZshComplete, "fish": FishComplete}
|
|
66
|
+
complete = shell_cls[shell](cli, {}, "jcli", "_JCLI_COMPLETE")
|
|
67
|
+
click.echo(complete.source(), nl=False)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
cli.add_command(completion)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def main():
|
|
74
|
+
"""CLI entry point."""
|
|
75
|
+
cli()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
main()
|