Skip to main content

Jenkins Jobs

https://img.shields.io/pypi/v/jenkins_jobs.svg https://github.com/glasswalk3r/jenkins-jobs/actions/workflows/main.yml/badge.svg

Listing all jobs on a Jenkins server with more information than just their respective names.

  • Free software: GNU General Public License v3

Features

  • Implements the jenkins_jobs CLI that allows the reporting of jobs in a Jenkins server.

  • The reports includes information of job name, job type, job description, if the job is executed through a schedule and the schedule itself.

  • Implements the jenkins_exporter CLI that allows the exporting of jobs information to a file in a Shelve format, which allows to export this information and use it locally for development or even with jenkins_jobs CLI.

Rationale

Some time ago I got to migrate jobs from three Jenkins servers with about 800 jobs included among them and the need to migrate those jobs to somewhere else.

I will not discuss the reasons for such humongous amount, but anyway I would need to understand what those jobs were, how they were built and other details, so I could come up with a better strategy of migration.

For my surprise, no tooling was available to use at that time.

Listing with Jenkins CLI

My first attempt was to use the official Jenkins CLI to extract that information.

If you are curious, you can use Vagrant with the following Vagrantfile and download the Vagrant VirtualBox box I created with a sample Jenkins server and some examples jobs over there:

Vagrant.configure("2") do |config|
  config.vm.box = "arfreitas/jenkins-centos7"
  config.vm.box_version = "0.0.1"
  config.vm.network 'forwarded_port', guest: 8080, host: 8080, id: 'jenkins'

  config.vm.provider 'virtualbox' do |vb|
    vb.gui = false
    vb.memory = '2048'
    vb.cpus = '2'
    vb.name = 'jenkins-sample'
end

These are the credentials already setup:

  • user: admin

  • password: admin

  • token: 116f3e55f677416a7c054faa20fbbcf0be

Finally, fire up the VM:

$ vagrant up

After the setup is complete, fire up the commands below:

$ vagrant ssh
$ java -jar jenkins-cli.jar -s http://localhost:8080/ -webSocket -auth admin:116f3e55f677416a7c054faa20fbbcf0be list-jobs
freestyle-sample
pipeline-sample

Not a very exciting output. You will get the job names and that’s it.

Listing with the REST API

So then I tried the Jenkins REST API with the sample.py Python 3 program:

$ cd /vagrant
$ ./sample.py
{'_class': 'hudson.model.FreeStyleProject', 'name': 'freestyle-sample', 'url': 'http://localhost:8080/job/freestyle-sample/', 'color': 'notbuilt', 'fullname': 'freestyle-sample'}
XML information:
OrderedDict([('project',
              OrderedDict([('keepDependencies', 'false'),
                           ('properties', None),
                           ('scm',
                            OrderedDict([('@class', 'hudson.scm.NullSCM')])),
                           ('canRoam', 'false'),
                           ('disabled', 'false'),
                           ('blockBuildWhenDownstreamBuilding', 'false'),
                           ('blockBuildWhenUpstreamBuilding', 'false'),
                           ('triggers', None),
                           ('concurrentBuild', 'false'),
                           ('builders', None),
                           ('publishers', None),
                           ('buildWrappers', None)]))])
{'_class': 'org.jenkinsci.plugins.workflow.job.WorkflowJob', 'name': 'pipeline-sample', 'url': 'http://localhost:8080/job/pipeline-sample/', 'color': 'notbuilt', 'fullname': 'pipeline-sample'}
XML information:
OrderedDict([('flow-definition',
              OrderedDict([('@plugin', 'workflow-job@2.40'),
                           ('keepDependencies', 'false'),
                           ('properties', None),
                           ('triggers', None),
                           ('disabled', 'false')]))])

If you take in consideration this is almost raw output, it’s an improvement because of the additional details, but far from enough.

First because part of the output is XML. Second, it is not exactly easy to understand the output.

Worst, the XML specification depends on the job underline mechanism: if the job is based on a plugin, the XML format will depend on that plugin, not on Jenkins.

Getting documentation about the XML format is another challenge.

Solution

What the jenkins-jobs project tries to do is to map desired information from the XML format based on the Python classes under jenkins_jobs.jobs module.

References

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.0.1 (2021-02-14)

  • First release on PyPI.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jenkins_jobs-0.1.2.tar.gz (34.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_jobs-0.1.2-py2.py3-none-any.whl (23.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file jenkins_jobs-0.1.2.tar.gz.

File metadata

  • Download URL: jenkins_jobs-0.1.2.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for jenkins_jobs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ee0edf0b1bc97bad2617856e5fff7db70f23be04550b77de7cfd794dc43cbf66
MD5 51d7583d28c7d9a52f7c75f8be02a5fc
BLAKE2b-256 db0d8ac1423f3db32c6ac0b81f7500476b18e6ee2fbf63555ffe702b1d0e4bd8

See more details on using hashes here.

File details

Details for the file jenkins_jobs-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: jenkins_jobs-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for jenkins_jobs-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c294d059467f560bb6d3b7abc14fcdc7e83732489f3c8b68b6425e15a37f9ac3
MD5 b4697407819aa1d2f1d9a1e6ecac698b
BLAKE2b-256 f85170e21e506be768e2e72dbe563d86f1360ae65fc2347591889cfeee31cc13

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page