jenkins-jobs


Namejenkins-jobs JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/glasswalk3r/jenkins-jobs
SummaryListing all jobs on a Jenkins server with more information than jenkins-cli.jar
upload_time2024-04-09 00:10:47
maintainerNone
docs_urlNone
authorAlceu Rodrigues de Freitas Junior
requires_python>=3.8
licenseGNU General Public License v3
keywords jenkins jobs
VCS
bugtrack_url
requirements xmltodict python-jenkins
Travis-CI
coveralls test coverage No coveralls.
            ============
Jenkins Jobs
============


.. image:: https://img.shields.io/pypi/v/jenkins_jobs.svg
        :target: https://pypi.python.org/pypi/jenkins_jobs

.. image:: https://github.com/glasswalk3r/jenkins-jobs/actions/workflows/main.yml/badge.svg
        :target: https://github.com/glasswalk3r/jenkins-jobs/actions/workflows/main.yml

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 <https://docs.python.org/3/library/shelve.html>`_,
  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 <https://www.vagrantup.com>`_ 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 <https://python-jenkins.readthedocs.io/en/latest/>`_ 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
----------

* The `JenkinsAPI <https://jenkinsapi.readthedocs.io/en/latest/using_jenkinsapi.html>`_ project.
* The `python-jenkins <https://python-jenkins.readthedocs.io/en/latest/index.html>`_ project.
* Stackoverflow question: `Groovy to list all jobs <https://support.cloudbees.com/hc/en-us/articles/226941767-Groovy-to-list-all-jobs>`_.
* Stackoverflow question: `Determining the type of Jenkins project <https://stackoverflow.com/questions/45064038/determining-the-type-of-jenkins-project>`_.

Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


=======
History
=======

0.0.1 (2021-02-14)
------------------

* First release on PyPI.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/glasswalk3r/jenkins-jobs",
    "name": "jenkins-jobs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "jenkins jobs",
    "author": "Alceu Rodrigues de Freitas Junior",
    "author_email": "arfreitas@cpan.org",
    "download_url": "https://files.pythonhosted.org/packages/ff/e5/76ffeba32f4cf99e21813dabda7407256ac07d3f57948125cc7c6f192eee/jenkins_jobs-0.1.1.tar.gz",
    "platform": null,
    "description": "============\nJenkins Jobs\n============\n\n\n.. image:: https://img.shields.io/pypi/v/jenkins_jobs.svg\n        :target: https://pypi.python.org/pypi/jenkins_jobs\n\n.. image:: https://github.com/glasswalk3r/jenkins-jobs/actions/workflows/main.yml/badge.svg\n        :target: https://github.com/glasswalk3r/jenkins-jobs/actions/workflows/main.yml\n\nListing all jobs on a Jenkins server with more information than just their\nrespective names.\n\n\n* Free software: GNU General Public License v3\n\n\nFeatures\n--------\n\n* Implements the ``jenkins_jobs`` CLI that allows the reporting of jobs in a\n  Jenkins server.\n* The reports includes information of job name, job type, job description, if\n  the job is executed through a schedule and the schedule itself.\n* Implements the ``jenkins_exporter`` CLI that allows the exporting of jobs\n  information to a file in a `Shelve format <https://docs.python.org/3/library/shelve.html>`_,\n  which allows to export this information and use it locally for development or\n  even with ``jenkins_jobs`` CLI.\n\nRationale\n---------\n\nSome time ago I got to migrate jobs from three Jenkins servers with about 800\njobs included among them and the need to migrate those jobs to somewhere else.\n\nI will not discuss the reasons for such humongous amount, but anyway I would\nneed to understand what those jobs were, how they were built and other details,\nso I could come up with a better strategy of migration.\n\nFor my surprise, no tooling was available to use at that time.\n\nListing with Jenkins CLI\n========================\n\nMy first attempt was to use the official Jenkins CLI to extract that\ninformation.\n\nIf you are curious, you can use `Vagrant <https://www.vagrantup.com>`_ with\nthe following ``Vagrantfile`` and download the Vagrant VirtualBox box I\ncreated with a sample Jenkins server and some examples jobs over there:\n\n::\n\n  Vagrant.configure(\"2\") do |config|\n    config.vm.box = \"arfreitas/jenkins-centos7\"\n    config.vm.box_version = \"0.0.1\"\n    config.vm.network 'forwarded_port', guest: 8080, host: 8080, id: 'jenkins'\n\n    config.vm.provider 'virtualbox' do |vb|\n      vb.gui = false\n      vb.memory = '2048'\n      vb.cpus = '2'\n      vb.name = 'jenkins-sample'\n  end\n\nThese are the credentials already setup:\n\n* user: admin\n* password: admin\n* token: 116f3e55f677416a7c054faa20fbbcf0be\n\nFinally, fire up the VM:\n\n::\n\n  $ vagrant up\n\n\nAfter the setup is complete, fire up the commands below:\n\n::\n\n  $ vagrant ssh\n  $ java -jar jenkins-cli.jar -s http://localhost:8080/ -webSocket -auth admin:116f3e55f677416a7c054faa20fbbcf0be list-jobs\n  freestyle-sample\n  pipeline-sample\n\n\nNot a very exciting output. You will get the job names and that's it.\n\nListing with the REST API\n=========================\n\nSo then I tried the Jenkins\n`REST API <https://python-jenkins.readthedocs.io/en/latest/>`_ with the ``sample.py`` Python 3 program:\n\n::\n\n  $ cd /vagrant\n  $ ./sample.py\n  {'_class': 'hudson.model.FreeStyleProject', 'name': 'freestyle-sample', 'url': 'http://localhost:8080/job/freestyle-sample/', 'color': 'notbuilt', 'fullname': 'freestyle-sample'}\n  XML information:\n  OrderedDict([('project',\n                OrderedDict([('keepDependencies', 'false'),\n                             ('properties', None),\n                             ('scm',\n                              OrderedDict([('@class', 'hudson.scm.NullSCM')])),\n                             ('canRoam', 'false'),\n                             ('disabled', 'false'),\n                             ('blockBuildWhenDownstreamBuilding', 'false'),\n                             ('blockBuildWhenUpstreamBuilding', 'false'),\n                             ('triggers', None),\n                             ('concurrentBuild', 'false'),\n                             ('builders', None),\n                             ('publishers', None),\n                             ('buildWrappers', None)]))])\n  {'_class': 'org.jenkinsci.plugins.workflow.job.WorkflowJob', 'name': 'pipeline-sample', 'url': 'http://localhost:8080/job/pipeline-sample/', 'color': 'notbuilt', 'fullname': 'pipeline-sample'}\n  XML information:\n  OrderedDict([('flow-definition',\n                OrderedDict([('@plugin', 'workflow-job@2.40'),\n                             ('keepDependencies', 'false'),\n                             ('properties', None),\n                             ('triggers', None),\n                             ('disabled', 'false')]))])\n\n\n\nIf you take in consideration this is almost raw output, it's an improvement\nbecause of the additional details, but far from enough.\n\nFirst because part of the output is XML. Second, it is not exactly easy to\nunderstand the output.\n\nWorst, the XML specification depends on the job underline mechanism: if the\njob is based on a plugin, the XML format will depend on that plugin, not on\nJenkins.\n\nGetting documentation about the XML format is another challenge.\n\nSolution\n========\n\nWhat the jenkins-jobs project tries to do is to map desired information from\nthe XML format based on the Python classes under ``jenkins_jobs.jobs`` module.\n\nReferences\n----------\n\n* The `JenkinsAPI <https://jenkinsapi.readthedocs.io/en/latest/using_jenkinsapi.html>`_ project.\n* The `python-jenkins <https://python-jenkins.readthedocs.io/en/latest/index.html>`_ project.\n* Stackoverflow question: `Groovy to list all jobs <https://support.cloudbees.com/hc/en-us/articles/226941767-Groovy-to-list-all-jobs>`_.\n* Stackoverflow question: `Determining the type of Jenkins project <https://stackoverflow.com/questions/45064038/determining-the-type-of-jenkins-project>`_.\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n\n\n=======\nHistory\n=======\n\n0.0.1 (2021-02-14)\n------------------\n\n* First release on PyPI.\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3",
    "summary": "Listing all jobs on a Jenkins server with more information than jenkins-cli.jar",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/glasswalk3r/jenkins-jobs"
    },
    "split_keywords": [
        "jenkins",
        "jobs"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51c3efb56b7c9ae417f27862d226b229c280df0b63ba4077838186a5a7cb3ea2",
                "md5": "100e77eb617d930ef234540c8a82c535",
                "sha256": "c5607763685998be4341d54fc39cff6cb57a52d42fdcf85f6fcb8b02df6f3840"
            },
            "downloads": -1,
            "filename": "jenkins_jobs-0.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "100e77eb617d930ef234540c8a82c535",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 23047,
            "upload_time": "2024-04-09T00:10:45",
            "upload_time_iso_8601": "2024-04-09T00:10:45.410190Z",
            "url": "https://files.pythonhosted.org/packages/51/c3/efb56b7c9ae417f27862d226b229c280df0b63ba4077838186a5a7cb3ea2/jenkins_jobs-0.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ffe576ffeba32f4cf99e21813dabda7407256ac07d3f57948125cc7c6f192eee",
                "md5": "be28951463b7ecc33fff462ef48fe1f4",
                "sha256": "b23b538a7a00c64a9f1b9af4fc2cb527f0ee6ec93eb6b984d2d664b15ab5b441"
            },
            "downloads": -1,
            "filename": "jenkins_jobs-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "be28951463b7ecc33fff462ef48fe1f4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 34254,
            "upload_time": "2024-04-09T00:10:47",
            "upload_time_iso_8601": "2024-04-09T00:10:47.553755Z",
            "url": "https://files.pythonhosted.org/packages/ff/e5/76ffeba32f4cf99e21813dabda7407256ac07d3f57948125cc7c6f192eee/jenkins_jobs-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-09 00:10:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "glasswalk3r",
    "github_project": "jenkins-jobs",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "xmltodict",
            "specs": [
                [
                    "==",
                    "0.13.0"
                ]
            ]
        },
        {
            "name": "python-jenkins",
            "specs": [
                [
                    "==",
                    "1.8.2"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "jenkins-jobs"
}
        
Elapsed time: 0.21981s