Skip to main content

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

jenkins_log_scanner-0.0.4.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jenkins_log_scanner-0.0.4-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file jenkins_log_scanner-0.0.4.tar.gz.

File metadata

  • Download URL: jenkins_log_scanner-0.0.4.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.5

File hashes

Hashes for jenkins_log_scanner-0.0.4.tar.gz
Algorithm Hash digest
SHA256 fc43f0cae491c6ec1ac948303e16e7b409477dbd2397df2898aab9a1e654850b
MD5 0f8d1c0febea63ddf29382e5f62fba4d
BLAKE2b-256 45d92af81436eeae74406173013a4b04c43c9fe7c7c4d9adcec573c6a4a36e1a

See more details on using hashes here.

File details

Details for the file jenkins_log_scanner-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for jenkins_log_scanner-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3734febefebb3070eb77f620f55a5a71e424127aca2b5930da9dcf4c07e81eff
MD5 e0df67e79a68775438de24a280a62f24
BLAKE2b-256 04ee69447528a3af88390486ea14dba31bd9213735feb94bbcb97c2db8c099db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page