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.2.tar.gz (7.2 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.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jenkins_log_scanner-0.0.2.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

Hashes for jenkins_log_scanner-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e4a814ab90ec1c9053b09718efe5e63fb0c70da10ce0218c513d8dd80a820622
MD5 309487d60a494c0c22abe95b609ecce8
BLAKE2b-256 822b7c74001b90af49f04b33ac421113a9465360020f3f63528b43d2639784db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jenkins_log_scanner-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 962d3dcb8853e556250e88fa58ea6f14d57f3e3d0b5dd9258383c943b21f3256
MD5 67289a547c6e907194a0ef31846e8afd
BLAKE2b-256 1e36ab55cb3df944ca85b79c7500b1af85f11d38e1473d44c3ffba395256526d

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