A package for efficiently scanning logs in Jenkins projects
Project description
JenkinsLogScanner - A fast utility for scanning Jenkins logs efficiently.
JenkinsLogScanner is a utility for recursively scanning every build log within a Jenkins project (whether it is top level org or a single job). Its power is in its ability to scan many build logs in parallel, but it can be used just as well to scan individual builds.
Environment Setup
The library only expects two environment variables to be defined: JENKINS_USER and JENKINS_PASSWORD.
Make sure these credentials are set in these environment variables and this user has access to the target Jenkins projects.
Installation
Install with pip:
pip install jenkins-log-scanner
Basic Usage:
from jenkins_log_scanner.scan_jenkins import JenkinsLogScanner, Operation
import jenkins_log_scanner.log_operations as logops
url = 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2/'
scanner = JenkinsLogScanner(url)
ops = [
Operation('head', logops.head),
Operation('tail', logops.tail),
]
for s in scanner.scan_jenkins(ops):
print(s)
Output:
{'jobUrl': 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2', 'buildNumber': 3, 'head': 'Started by user Adeiron Barolli\n', 'tail': 'Finished: FAILURE\n'}
{'jobUrl': 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2', 'buildNumber': 2, 'head': 'Started by user Adeiron Barolli\n', 'tail': 'Finished: SUCCESS\n'}
{'jobUrl': 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2', 'buildNumber': 1, 'head': 'Started by user Adeiron Barolli\n', 'tail': 'Finished: SUCCESS\n'}
...
To scan a single build, simply give the url to that build:
url = 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2/1'
# or
url = 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2/2'
# or
url = 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2/3'
# etc...
The Operation Class
Operation represents a callable that's not expected to be called until some unknown time. At initialization, optional kwargs can be
provided and these will be passed to the callable when the call method is invoked at a later time.
This allows the user to bind certain arguments to the callable in advance. In the example above, the head and tail log operations
both take optional lineCount parameters. So if the user was interested in seeing the last 2 lines instead of the default of 1, ops in
the snippet above can be changed to the following:
ops = [
Operation('head', logops.head),
Operation('tail', logops.tail, lineCount = 2),
]
Output:
{'jobUrl': 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2', 'buildNumber': 3, 'head': 'Started by user Adeiron Barolli\n', 'tail': 'Build step "Execute shell" marked build\nFinished: FAILURE\n'}
{'jobUrl': 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2', 'buildNumber': 2, 'head': 'Started by user Adeiron Barolli\n', 'tail': 'Build step "Execute shell" marked build\nFinished: SUCCESS\n'}
{'jobUrl': 'http://localhost:8081/jenkins/job/testfolder1/job/testjob2', 'buildNumber': 1, 'head': 'Started by user Adeiron Barolli\n', 'tail': 'Build step "Execute shell" marked build\nFinished: SUCCESS\n'}
...
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
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 jenkins_log_scanner-0.0.3.tar.gz.
File metadata
- Download URL: jenkins_log_scanner-0.0.3.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcbea8af813c292a1f8d600d40c40142ae84f6edbbd97fd41f23811e6b0bdf79
|
|
| MD5 |
ac22a69c728568a50a90f9e14a4bb475
|
|
| BLAKE2b-256 |
5131ec0974db43e3f99019e72e80680f46eae1778a7d4cc3e59100e59ddb4992
|
File details
Details for the file jenkins_log_scanner-0.0.3-py3-none-any.whl.
File metadata
- Download URL: jenkins_log_scanner-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49429b3b2a85600fa8b9e0db28940af83c499d1f5f3d14f4adb0f0e17b02b15a
|
|
| MD5 |
1863c6be4124cc2d4e682cd0405bf78c
|
|
| BLAKE2b-256 |
b115198ed3d89a4ee50285f2ad4b4d72fec82fe3e0d7bf1d48d99e593c6be900
|