jenkinsctl 0.1.0__tar.gz → 1.0.5__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.

Potentially problematic release.


This version of jenkinsctl might be problematic. Click here for more details.

Files changed (38) hide show
  1. jenkinsctl-1.0.5/PKG-INFO +172 -0
  2. jenkinsctl-1.0.5/README.md +140 -0
  3. jenkinsctl-1.0.5/jenkinsctl/cli.py +158 -0
  4. jenkinsctl-1.0.5/jenkinsctl/commands/__init__.py +0 -0
  5. jenkinsctl-1.0.5/jenkinsctl/commands/build.py +46 -0
  6. jenkinsctl-1.0.5/jenkinsctl/commands/config.py +15 -0
  7. jenkinsctl-1.0.5/jenkinsctl/commands/enable_completion.py +22 -0
  8. jenkinsctl-1.0.5/jenkinsctl/commands/jobs.py +18 -0
  9. jenkinsctl-1.0.5/jenkinsctl/commands/json.py +14 -0
  10. jenkinsctl-1.0.5/jenkinsctl/commands/list.py +62 -0
  11. jenkinsctl-1.0.5/jenkinsctl/commands/logs.py +12 -0
  12. jenkinsctl-1.0.5/jenkinsctl/commands/rebuild.py +14 -0
  13. jenkinsctl-1.0.5/jenkinsctl/configs/__init__.py +0 -0
  14. jenkinsctl-1.0.5/jenkinsctl/configs/logging_config.py +19 -0
  15. jenkinsctl-1.0.5/jenkinsctl/configs/session.py +21 -0
  16. jenkinsctl-1.0.5/jenkinsctl/jenkins/cli_helper.py +25 -0
  17. jenkinsctl-1.0.5/jenkinsctl/jenkins/commons.py +9 -0
  18. jenkinsctl-1.0.5/jenkinsctl/jenkins/console_util.py +31 -0
  19. jenkinsctl-1.0.5/jenkinsctl/jenkins/job.py +69 -0
  20. jenkinsctl-1.0.5/jenkinsctl/jenkins/utils.py +37 -0
  21. jenkinsctl-1.0.5/pyproject.toml +36 -0
  22. jenkinsctl-0.1.0/PKG-INFO +0 -118
  23. jenkinsctl-0.1.0/README.md +0 -98
  24. jenkinsctl-0.1.0/jenkinsctl/commons.py +0 -8
  25. jenkinsctl-0.1.0/jenkinsctl/jbuild.py +0 -115
  26. jenkinsctl-0.1.0/jenkinsctl/jenkins.py +0 -53
  27. jenkinsctl-0.1.0/jenkinsctl/jget_config.py +0 -41
  28. jenkinsctl-0.1.0/jenkinsctl.egg-info/PKG-INFO +0 -118
  29. jenkinsctl-0.1.0/jenkinsctl.egg-info/SOURCES.txt +0 -15
  30. jenkinsctl-0.1.0/jenkinsctl.egg-info/dependency_links.txt +0 -1
  31. jenkinsctl-0.1.0/jenkinsctl.egg-info/entry_points.txt +0 -2
  32. jenkinsctl-0.1.0/jenkinsctl.egg-info/requires.txt +0 -4
  33. jenkinsctl-0.1.0/jenkinsctl.egg-info/top_level.txt +0 -2
  34. jenkinsctl-0.1.0/pyproject.toml +0 -32
  35. jenkinsctl-0.1.0/setup.cfg +0 -4
  36. {jenkinsctl-0.1.0 → jenkinsctl-1.0.5}/LICENSE +0 -0
  37. {jenkinsctl-0.1.0 → jenkinsctl-1.0.5}/jenkinsctl/__init__.py +0 -0
  38. {jenkinsctl-0.1.0/jenkinsctl → jenkinsctl-1.0.5/jenkinsctl/configs}/config.py +0 -0
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.1
2
+ Name: jenkinsctl
3
+ Version: 1.0.5
4
+ Summary: A command-line tool to interact with Jenkins jobs 🚀
5
+ Home-page: https://github.com/amanshaw4511/jenkinsctl
6
+ License: GPL-3.0-or-later
7
+ Keywords: jenkins,jenkin
8
+ Author: Aman Shaw
9
+ Author-email: amanshaw4511@protonmail.com
10
+ Maintainer: Aman Shaw
11
+ Maintainer-email: amanshaw4511@protonmail.com
12
+ Requires-Python: >=3.8,<4.0
13
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Requires-Dist: click (>=8.1.7,<9.0.0)
23
+ Requires-Dist: click-completion (>=0.5.2,<0.6.0)
24
+ Requires-Dist: dynaconf (>=3.2.6,<4.0.0)
25
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
26
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
27
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
28
+ Requires-Dist: rich (>=13.8.1,<14.0.0)
29
+ Project-URL: Repository, https://github.com/amanshaw4511/jenkinsctl
30
+ Description-Content-Type: text/markdown
31
+
32
+ ![jenkinsctl](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Jenkins_logo.svg/226px-Jenkins_logo.svg.png?20120629215426)
33
+ # jenkinsctl [![PyPI version](https://badge.fury.io/py/jenkinsctl.svg?)](https://badge.fury.io/py/jenkinsctl) [![Downloads](https://static.pepy.tech/badge/jenkinsctl/week?)](https://pepy.tech/project/jenkinsctl) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
34
+ # jenkinsctl – Jenkins Control Right from Your Terminal 🚀
35
+
36
+ `jenkinsctl` is a CLI tool that puts Jenkins management right in your terminal. It simplifies tasks like listing builds, fetching logs, and triggering parameterized jobs—no more web UI hassle!
37
+
38
+ ## Why jenkinsctl? 🔥
39
+
40
+ Jenkins workflows can be tedious through the web UI. `jenkinsctl` keeps your hands on the keyboard, streamlining Jenkins management directly from your terminal, making it perfect for quick job control, scripting, and automation.
41
+
42
+ ---
43
+
44
+ ### Key Features
45
+
46
+ - **Quick Build Listings**: View recent builds for any job.
47
+ - **Instant Log Access**: Fetch build logs effortlessly.
48
+ - **JSON & YAML API Data**: Retrieve job configurations and build data in JSON or YAML.
49
+ - **Easy Rebuilds**: Re-run jobs without reopening Jenkins.
50
+ - **Parameterized Builds**: Customize builds with dynamic parameters.
51
+ - **Folder Job Listings**: Organize and access jobs in specific folders.
52
+ - **Autocompletion**: Enhance the CLI experience with shell autocompletion for bash, zsh, or fish.
53
+
54
+ ---
55
+
56
+ ## Installation 📦
57
+ ```sh
58
+ pip3 install jenkinsctl
59
+ ```
60
+
61
+ ## Jenkins Configuration 🛠️
62
+ Before using jenkinsctl, configure your Jenkins server details in your shell profile.
63
+ Add these lines in your ~/.bashrc or ~/.zshrc file:
64
+ ```sh
65
+ export JENKINS_SERVER_URL=http://localhost:8080
66
+ export JENKINS_USERNAME=amanshaw4511
67
+ export JENKINS_API_KEY=21df49caf41726094323b803a6de363eae
68
+ ```
69
+ Adjust the values to match your Jenkins server's URL, your username, and the corresponding API key. This configuration is essential for jenkinsctl to interact with Jenkins and execute tasks efficiently.
70
+
71
+ How to Get the API Token: https://www.baeldung.com/ops/jenkins-api-token
72
+
73
+ Reload your shell profile:
74
+ ```sh
75
+ exec $SHELL
76
+ ```
77
+
78
+ ## Commands & Options 🤖
79
+ All `jenkinsctl` commands are designed to be terminal-friendly with structured flags and arguments.
80
+
81
+ ### `list`
82
+ List recent builds of a Jenkins job.
83
+ ```sh
84
+ jenkinsctl list <job_name> [-n <number_of_builds>]
85
+ ```
86
+ | Option | Description |
87
+ |----------------|------------------------------------------------|
88
+ | `job_name` | Name of the Jenkins job |
89
+ | `-n, --number` | Number of builds to list (default: 5) |
90
+
91
+ ### `logs`
92
+ View logs of a specific build.
93
+ ```sh
94
+ jenkinsctl logs <job_name> [build_no]
95
+ ```
96
+ | Option | Description |
97
+ |-------------|---------------------------------------------------|
98
+ | `job_name` | Name of the Jenkins job |
99
+ | `build_no` | Build number (optional, defaults to last build) |
100
+
101
+ ### `json`
102
+ Get JSON API data for a build.
103
+ ```sh
104
+ jenkinsctl json <job_name> [build_no]
105
+ ```
106
+ ### `config`
107
+ Get build configuration in YAML format.
108
+ ```sh
109
+ jenkinsctl config <job_name> [build_no]
110
+ ```
111
+
112
+ ### `rebuild`
113
+ Trigger a rebuild of a specific job.
114
+ ```sh
115
+ jenkinsctl rebuild <job_name> [build_no]
116
+ ```
117
+
118
+ ### `build`
119
+ Start a new build using YAML configuration with optional parameters.
120
+ ```sh
121
+ jenkinsctl build -f <config_file> [--param key=value]
122
+ ```
123
+ | Option | Description |
124
+ |----------------|-------------------------------------------------|
125
+ | `-f, --file` | YAML configuration file for the Jenkins job |
126
+ | `--param` | Key-value pairs to override config parameters |
127
+
128
+ ### `enable-completion`
129
+ Enable shell autocompletion for streamlined CLI use.
130
+ ```sh
131
+ jenkinsctl enable-completion [shell]
132
+ ```
133
+ | Argument | Description |
134
+ |----------|-------------------------------------------------------|
135
+ | `shell` | Optional: specify shell (`bash`, `zsh`, or `fish`) |
136
+
137
+ ### `jobs`
138
+ List all jobs in a specified Jenkins folder.
139
+ ```sh
140
+ jenkinsctl jobs [folder_name]
141
+ ```
142
+ | Option | Description |
143
+ |--------------|-----------------------------------------------|
144
+ | `folder_name`| Folder path for jobs (optional) |
145
+
146
+
147
+ ## Quick Examples 🎭
148
+
149
+ 1. **List Recent Builds**: Show the last 10 builds for a job.
150
+ ```
151
+ jenkinsctl list my-awesome-job -n 10
152
+ ```
153
+
154
+ 2. **Get Logs for a Build**: View logs for a specific build.
155
+ ```
156
+ jenkinsctl logs my-awesome-job 42
157
+ ```
158
+
159
+ 3. **Start a Build with Parameters**: Launch a build with custom parameters.
160
+ ```
161
+ jenkinsctl build -f path/to/config.yaml --param version=1.2.3
162
+ ```
163
+
164
+ ---
165
+
166
+ ## Contributing 🤝
167
+
168
+ Contributions are welcome! If you want to contribute, fork the repo, make your changes, and submit a pull request. Found an issue? Open an issue in the repo!
169
+
170
+ ---
171
+
172
+
@@ -0,0 +1,140 @@
1
+ ![jenkinsctl](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Jenkins_logo.svg/226px-Jenkins_logo.svg.png?20120629215426)
2
+ # jenkinsctl [![PyPI version](https://badge.fury.io/py/jenkinsctl.svg?)](https://badge.fury.io/py/jenkinsctl) [![Downloads](https://static.pepy.tech/badge/jenkinsctl/week?)](https://pepy.tech/project/jenkinsctl) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
3
+ # jenkinsctl – Jenkins Control Right from Your Terminal 🚀
4
+
5
+ `jenkinsctl` is a CLI tool that puts Jenkins management right in your terminal. It simplifies tasks like listing builds, fetching logs, and triggering parameterized jobs—no more web UI hassle!
6
+
7
+ ## Why jenkinsctl? 🔥
8
+
9
+ Jenkins workflows can be tedious through the web UI. `jenkinsctl` keeps your hands on the keyboard, streamlining Jenkins management directly from your terminal, making it perfect for quick job control, scripting, and automation.
10
+
11
+ ---
12
+
13
+ ### Key Features
14
+
15
+ - **Quick Build Listings**: View recent builds for any job.
16
+ - **Instant Log Access**: Fetch build logs effortlessly.
17
+ - **JSON & YAML API Data**: Retrieve job configurations and build data in JSON or YAML.
18
+ - **Easy Rebuilds**: Re-run jobs without reopening Jenkins.
19
+ - **Parameterized Builds**: Customize builds with dynamic parameters.
20
+ - **Folder Job Listings**: Organize and access jobs in specific folders.
21
+ - **Autocompletion**: Enhance the CLI experience with shell autocompletion for bash, zsh, or fish.
22
+
23
+ ---
24
+
25
+ ## Installation 📦
26
+ ```sh
27
+ pip3 install jenkinsctl
28
+ ```
29
+
30
+ ## Jenkins Configuration 🛠️
31
+ Before using jenkinsctl, configure your Jenkins server details in your shell profile.
32
+ Add these lines in your ~/.bashrc or ~/.zshrc file:
33
+ ```sh
34
+ export JENKINS_SERVER_URL=http://localhost:8080
35
+ export JENKINS_USERNAME=amanshaw4511
36
+ export JENKINS_API_KEY=21df49caf41726094323b803a6de363eae
37
+ ```
38
+ Adjust the values to match your Jenkins server's URL, your username, and the corresponding API key. This configuration is essential for jenkinsctl to interact with Jenkins and execute tasks efficiently.
39
+
40
+ How to Get the API Token: https://www.baeldung.com/ops/jenkins-api-token
41
+
42
+ Reload your shell profile:
43
+ ```sh
44
+ exec $SHELL
45
+ ```
46
+
47
+ ## Commands & Options 🤖
48
+ All `jenkinsctl` commands are designed to be terminal-friendly with structured flags and arguments.
49
+
50
+ ### `list`
51
+ List recent builds of a Jenkins job.
52
+ ```sh
53
+ jenkinsctl list <job_name> [-n <number_of_builds>]
54
+ ```
55
+ | Option | Description |
56
+ |----------------|------------------------------------------------|
57
+ | `job_name` | Name of the Jenkins job |
58
+ | `-n, --number` | Number of builds to list (default: 5) |
59
+
60
+ ### `logs`
61
+ View logs of a specific build.
62
+ ```sh
63
+ jenkinsctl logs <job_name> [build_no]
64
+ ```
65
+ | Option | Description |
66
+ |-------------|---------------------------------------------------|
67
+ | `job_name` | Name of the Jenkins job |
68
+ | `build_no` | Build number (optional, defaults to last build) |
69
+
70
+ ### `json`
71
+ Get JSON API data for a build.
72
+ ```sh
73
+ jenkinsctl json <job_name> [build_no]
74
+ ```
75
+ ### `config`
76
+ Get build configuration in YAML format.
77
+ ```sh
78
+ jenkinsctl config <job_name> [build_no]
79
+ ```
80
+
81
+ ### `rebuild`
82
+ Trigger a rebuild of a specific job.
83
+ ```sh
84
+ jenkinsctl rebuild <job_name> [build_no]
85
+ ```
86
+
87
+ ### `build`
88
+ Start a new build using YAML configuration with optional parameters.
89
+ ```sh
90
+ jenkinsctl build -f <config_file> [--param key=value]
91
+ ```
92
+ | Option | Description |
93
+ |----------------|-------------------------------------------------|
94
+ | `-f, --file` | YAML configuration file for the Jenkins job |
95
+ | `--param` | Key-value pairs to override config parameters |
96
+
97
+ ### `enable-completion`
98
+ Enable shell autocompletion for streamlined CLI use.
99
+ ```sh
100
+ jenkinsctl enable-completion [shell]
101
+ ```
102
+ | Argument | Description |
103
+ |----------|-------------------------------------------------------|
104
+ | `shell` | Optional: specify shell (`bash`, `zsh`, or `fish`) |
105
+
106
+ ### `jobs`
107
+ List all jobs in a specified Jenkins folder.
108
+ ```sh
109
+ jenkinsctl jobs [folder_name]
110
+ ```
111
+ | Option | Description |
112
+ |--------------|-----------------------------------------------|
113
+ | `folder_name`| Folder path for jobs (optional) |
114
+
115
+
116
+ ## Quick Examples 🎭
117
+
118
+ 1. **List Recent Builds**: Show the last 10 builds for a job.
119
+ ```
120
+ jenkinsctl list my-awesome-job -n 10
121
+ ```
122
+
123
+ 2. **Get Logs for a Build**: View logs for a specific build.
124
+ ```
125
+ jenkinsctl logs my-awesome-job 42
126
+ ```
127
+
128
+ 3. **Start a Build with Parameters**: Launch a build with custom parameters.
129
+ ```
130
+ jenkinsctl build -f path/to/config.yaml --param version=1.2.3
131
+ ```
132
+
133
+ ---
134
+
135
+ ## Contributing 🤝
136
+
137
+ Contributions are welcome! If you want to contribute, fork the repo, make your changes, and submit a pull request. Found an issue? Open an issue in the repo!
138
+
139
+ ---
140
+
@@ -0,0 +1,158 @@
1
+ import logging
2
+ from io import TextIOWrapper
3
+ from typing import Optional
4
+
5
+ import click
6
+ import click_completion
7
+
8
+ from jenkinsctl.commands.build import build_handler
9
+ from jenkinsctl.commands.config import config_handler
10
+ from jenkinsctl.commands.enable_completion import handle_enable_completion
11
+ from jenkinsctl.commands.jobs import jobs_handler
12
+ from jenkinsctl.commands.json import json_handler
13
+ from jenkinsctl.commands.list import list_handler
14
+ from jenkinsctl.commands.logs import logs_handler
15
+ from jenkinsctl.commands.rebuild import rebuild_handler
16
+ from jenkinsctl.configs.logging_config import setup_logging
17
+ from jenkinsctl.jenkins.cli_helper import error_handler_and_session
18
+
19
+ click_completion.init()
20
+
21
+
22
+ @click.group()
23
+ @click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
24
+ @click.pass_context
25
+ def cli(ctx: click.Context, verbose: bool) -> None:
26
+ """A command-line tool to interact with Jenkins jobs"""
27
+ log_level: int = logging.DEBUG if verbose else logging.INFO
28
+ ctx.logger = setup_logging(log_level)
29
+
30
+
31
+ @cli.command("list")
32
+ @click.argument("job_name")
33
+ @click.option("-n", "--number", default=5, type=int, help="No of builds to list (default: 5)")
34
+ def list_command(job_name: str, number: int) -> None:
35
+ """
36
+ List all builds of a Jenkins job
37
+
38
+ \b
39
+ JOB_NAME: Name of the Jenkins job
40
+ """
41
+ with error_handler_and_session() as session:
42
+ list_handler(session, job_name, number)
43
+
44
+
45
+ @cli.command("logs")
46
+ @click.argument("job_name")
47
+ @click.argument("build_no", required=False, type=int)
48
+ def logs_command(job_name: str, build_no: Optional[int]) -> None:
49
+ """
50
+ Print logs of a Jenkins build
51
+
52
+ \b
53
+ JOB_NAME: Name of the Jenkins job
54
+ BUILD_NO: Build number (default: last build)
55
+ """
56
+ with error_handler_and_session() as session:
57
+ logs_handler(session, job_name, build_no)
58
+
59
+
60
+ @cli.command("json")
61
+ @click.argument("job_name")
62
+ @click.argument("build_no", required=False, type=int)
63
+ def json_command(job_name: str, build_no: Optional[int]) -> None:
64
+ """
65
+ Fetch and print the JSON API response of a Jenkins build
66
+
67
+ \b
68
+ JOB_NAME: Name of the Jenkins job
69
+ BUILD_NO: Build number (default: last build)
70
+ """
71
+ with error_handler_and_session() as session:
72
+ json_handler(session, job_name, build_no)
73
+
74
+
75
+ @cli.command("config")
76
+ @click.argument("job_name")
77
+ @click.argument("build_no", required=False, type=int)
78
+ def config_command(job_name: str, build_no: Optional[int]) -> None:
79
+ """
80
+ Get the configuration of a specific build in YAML format
81
+
82
+ \b
83
+ JOB_NAME: Name of the Jenkins job
84
+ BUILD_NO: Build number (default: last build)
85
+ """
86
+ with error_handler_and_session() as session:
87
+ config_handler(session, job_name, build_no)
88
+
89
+
90
+ @cli.command("rebuild")
91
+ @click.argument("job_name")
92
+ @click.argument("build_no", required=False, type=int)
93
+ def rebuild_command(job_name: str, build_no: Optional[int]) -> None:
94
+ """
95
+ Rebuild a specific Jenkins job
96
+
97
+ \b
98
+ JOB_NAME: Name of the Jenkins job
99
+ BUILD_NO: Build number (default: last build)
100
+ """
101
+ with error_handler_and_session() as session:
102
+ rebuild_handler(session, job_name, build_no)
103
+
104
+
105
+ @cli.command("build")
106
+ @click.option("-p", "--param", multiple=True,
107
+ help="Override parameters in the YAML configuration (e.g., --param key=value)")
108
+ @click.option("-f", "--file", type=click.File('r'), required=True, help="YAML configuration file for the Jenkins job")
109
+ def build_command(file: TextIOWrapper, param: tuple[str]) -> None:
110
+ """
111
+ Trigger a new Jenkins build
112
+ """
113
+ params = [p for p in param]
114
+ with error_handler_and_session() as session:
115
+ build_handler(session, file, params)
116
+
117
+
118
+ @cli.command("enable-completion")
119
+ @click.argument('shell', required=False)
120
+ def enable_completion(shell: str):
121
+ """
122
+ Enable shell autocompletion for jenkinsctl.
123
+
124
+ This command allows you to set up autocompletion for the jenkinsctl command-line tool,
125
+ making it easier to use by providing suggestions as you type.
126
+
127
+ \b
128
+ SHELL: Specify a shell for which to enable autocompletion.
129
+ Supported options include:
130
+ - bash
131
+ - zsh
132
+ - fish
133
+
134
+ If no shell is specified, it will attempt to autodetect your shell.
135
+ """
136
+ if shell is None:
137
+ shell = click_completion.core.get_auto_shell() # Detect the current shell
138
+
139
+ handle_enable_completion(shell)
140
+
141
+
142
+ @cli.command("jobs")
143
+ @click.argument("folder_name", default="")
144
+ def jobs_command(folder_name: str) -> None:
145
+ """
146
+ List all jobs in a Jenkins folder.
147
+
148
+ \b
149
+ FOLDER_NAME: Path of the folder to list jobs (e.g., projectA/subProjectX).
150
+ If no folder is specified, it lists jobs in the root folder.
151
+ """
152
+ with error_handler_and_session() as session:
153
+ jobs_handler(session, folder_name)
154
+
155
+
156
+ # Entry point
157
+ if __name__ == '__main__':
158
+ cli()
File without changes
@@ -0,0 +1,46 @@
1
+ import logging
2
+ import sys
3
+ from io import TextIOWrapper
4
+ from typing import List
5
+
6
+ import yaml
7
+
8
+ from jenkinsctl.configs.session import Session
9
+ from jenkinsctl.jenkins.console_util import json_preety
10
+ from jenkinsctl.jenkins.job import build_job
11
+
12
+ log = logging.getLogger(__name__)
13
+
14
+
15
+ def get_config_from_yaml(file):
16
+ config_data = None
17
+ try:
18
+ with open(file.name, "r") as config_file:
19
+ config_data = yaml.safe_load(config_file) # Use safe_load for YAML
20
+ except FileNotFoundError:
21
+ print(f"Error: Configuration file '{file}' not found.")
22
+ sys.exit()
23
+ except yaml.YAMLError as e:
24
+ print(f"Error: Invalid YAML format in '{file}': {e}")
25
+ sys.exit()
26
+
27
+ return config_data
28
+
29
+
30
+ def get_conf(file, params):
31
+ config = get_config_from_yaml(file)
32
+ override_params(params, config)
33
+ return config
34
+
35
+
36
+ def override_params(params, file_config):
37
+ for param in params:
38
+ name, value = param.split('=')
39
+ file_config['params'][name] = value
40
+
41
+
42
+ def build_handler(session: Session, file: TextIOWrapper, params: List[str]):
43
+ conf = get_conf(file, params)
44
+ log.debug(f"config: {json_preety(conf)}")
45
+ location = build_job(session, conf["job"], conf["params"])
46
+ print(location)
@@ -0,0 +1,15 @@
1
+ from typing import Optional
2
+
3
+ from jenkinsctl.configs.session import Session
4
+ from jenkinsctl.jenkins.commons import get_last_build_no_if_none
5
+ from jenkinsctl.jenkins.job import get_build
6
+ from jenkinsctl.jenkins.utils import get_build_params, to_yaml, normalize_job_path
7
+
8
+
9
+ def config_handler(session: Session, job_name: str, build_no: Optional[int]):
10
+ job_name = normalize_job_path(job_name)
11
+ build_no = get_last_build_no_if_none(session, job_name, build_no)
12
+
13
+ build = get_build(session, job_name, build_no)
14
+ params = get_build_params(build)
15
+ print(to_yaml(job_name, params))
@@ -0,0 +1,22 @@
1
+ def handle_enable_completion(shell: str):
2
+ if shell == "bash":
3
+ print("\n# To enable autocompletion for bash, add the following to your ~/.bashrc:")
4
+ print("echo 'eval \"$(_JENKINSCTL_COMPLETE=bash_source jenkinsctl)\"' >> ~/.bashrc")
5
+ print("\n# Then reload your bash configuration:")
6
+ print("source ~/.bashrc")
7
+
8
+ elif shell == "zsh":
9
+ print("\n# To enable autocompletion for zsh, add the following to your ~/.zshrc:")
10
+ print("echo 'eval \"$(_JENKINSCTL_COMPLETE=zsh_source jenkinsctl)\"' >> ~/.zshrc")
11
+ print("\n# Then reload your zsh configuration:")
12
+ print("source ~/.zshrc")
13
+
14
+ elif shell == "fish":
15
+ print(
16
+ "\n# To enable autocompletion for fish, add the following to your Fish config (~/.config/fish/config.fish):")
17
+ print("echo 'eval (jenkinsctl enable-completion fish | source)' >> ~/.config/fish/config.fish")
18
+ print("\n# Then reload your fish shell configuration:")
19
+ print("source ~/.config/fish/config.fish")
20
+
21
+ else:
22
+ print("\n# Unsupported shell. Please specify bash, zsh, or fish.")
@@ -0,0 +1,18 @@
1
+ from jenkinsctl.configs.session import Session
2
+ from jenkinsctl.jenkins.job import get_jobs
3
+ from jenkinsctl.jenkins.utils import normalize_job_path
4
+
5
+
6
+ def jobs_handler(session: Session, folder_name: str):
7
+ folder_name = normalize_job_path(folder_name)
8
+ response = get_jobs(session, folder_name)
9
+ all_jobs = response["jobs"]
10
+
11
+ folders = [job for job in all_jobs if job["_class"] == "com.cloudbees.hudson.plugins.folder.Folder"]
12
+ jobs = [job for job in all_jobs if job["_class"] != "com.cloudbees.hudson.plugins.folder.Folder"]
13
+
14
+ for folder in folders:
15
+ print(f"[{folder["name"]}]")
16
+
17
+ for job in jobs:
18
+ print(f"{job["name"]}")
@@ -0,0 +1,14 @@
1
+ from typing import Optional
2
+
3
+ from jenkinsctl.configs.session import Session
4
+ from jenkinsctl.jenkins.commons import get_last_build_no_if_none
5
+ from jenkinsctl.jenkins.console_util import print_json
6
+ from jenkinsctl.jenkins.job import progressive_log, get_build
7
+ from jenkinsctl.jenkins.utils import normalize_job_path
8
+
9
+
10
+ def json_handler(session: Session, job_name: str, build_no: Optional[int]):
11
+ job_name = normalize_job_path(job_name)
12
+ build_no = get_last_build_no_if_none(session, job_name, build_no)
13
+ build = get_build(session, job_name, build_no)
14
+ print_json(build)
@@ -0,0 +1,62 @@
1
+ from itertools import islice
2
+
3
+ from rich.console import Console
4
+ from rich.table import Table
5
+
6
+ from jenkinsctl.configs.session import Session
7
+ from jenkinsctl.jenkins.console_util import format_timestamp
8
+ from jenkinsctl.jenkins.job import get_job, get_builds_iter
9
+ from jenkinsctl.jenkins.utils import normalize_job_path
10
+
11
+
12
+ def list_handler(session: Session, job_name: str, number: int):
13
+ job_name = normalize_job_path(job_name)
14
+ job = get_job(session, job_name)
15
+
16
+ console = Console()
17
+ table = Table(show_header=True, header_style="bold cyan", box=None)
18
+
19
+ table.add_column("NUMBER", width=6)
20
+ table.add_column("IN PROGRESS", width=15)
21
+ table.add_column("RESULT", width=10)
22
+ table.add_column("BUILDING", width=8)
23
+ table.add_column("BRANCH", width=15)
24
+ table.add_column("REVISION", width=8)
25
+ table.add_column("STARTED BY", width=15)
26
+ table.add_column("BUILD TIME", width=20)
27
+
28
+ for build in islice(get_builds_iter(session, job), number):
29
+ number = build["number"]
30
+ building = build["building"]
31
+ in_progress = build["inProgress"]
32
+ result = build["result"]
33
+ timestamp = build["timestamp"]
34
+
35
+ actions = build["actions"]
36
+ causes = next((action["causes"] for action in actions if action.get("causes") is not None), None)
37
+ user_id = next((cause["userId"] for cause in causes if cause.get("userId") is not None), None)
38
+
39
+ branch = None
40
+ revision = None
41
+ # fixme: not working below code
42
+ # last_build = next((action["lastBuildRevision"] for action in actions if action.get("lastBuildRevision") is not None))
43
+ last_build = None
44
+ if last_build:
45
+ branch_prefix = "refs/remotes/origin/"
46
+ branch = last_build["branch"][0]["name"]
47
+ if branch.startswith(branch_prefix):
48
+ branch = branch[len(branch_prefix):]
49
+ revision = last_build["SHA1"][:5]
50
+
51
+
52
+ table.add_row(
53
+ str(number),
54
+ str(in_progress),
55
+ str(result),
56
+ str(building),
57
+ branch,
58
+ revision,
59
+ user_id,
60
+ str(format_timestamp(timestamp)))
61
+
62
+ console.print(table)
@@ -0,0 +1,12 @@
1
+ from typing import Optional
2
+
3
+ from jenkinsctl.configs.session import Session
4
+ from jenkinsctl.jenkins.commons import get_last_build_no_if_none
5
+ from jenkinsctl.jenkins.job import progressive_log
6
+ from jenkinsctl.jenkins.utils import normalize_job_path
7
+
8
+
9
+ def logs_handler(session: Session, job_name: str, build_no: Optional[int]):
10
+ job_name = normalize_job_path(job_name)
11
+ build_no = get_last_build_no_if_none(session, job_name, build_no)
12
+ progressive_log(session, job_name, build_no)
@@ -0,0 +1,14 @@
1
+ from typing import Optional
2
+
3
+ from jenkinsctl.configs.session import Session
4
+ from jenkinsctl.jenkins.commons import get_last_build_no_if_none
5
+ from jenkinsctl.jenkins.job import get_build, build_job
6
+ from jenkinsctl.jenkins.utils import get_build_params, normalize_job_path
7
+
8
+
9
+ def rebuild_handler(session: Session, job_name: str, build_no: Optional[int]):
10
+ job_name = normalize_job_path(job_name)
11
+ build_no = get_last_build_no_if_none(session, job_name, build_no)
12
+ build = get_build(session, job_name, build_no)
13
+ location = build_job(session, job_name, get_build_params(build))
14
+ print(location)
File without changes