Package: jenkins-jobs
Jenkins JobsListing all jobs on a Jenkins server with more information than their
respective names.Free software: GNU General Public License v3FeaturesImplements thejenkins_jobsCLI 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 thejenkins_exporterCLI that allows the exporting of jobs
information to a file in aShelve format,
which allows to export this information and use it locally for development or
even withjenkins_jobsCLI.RationaleSome 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, nothing was available to use at that time.Listing with Jenkins CLIMy first attempt was to use the official Jenkins CLI to extract that
information.If you are curious, you can useVagrantwith the
followingVagrantfileand download the Vagrant 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'
endThese are the credentials already setup:user:adminpassword:admintoken:116f3e55f677416a7c054faa20fbbcf0beFinally, fire up the VM:$ vagrant upAfter 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-sampleNot a very exciting output. You will get the job names and that’s it.Listing with the REST APISo then I tried the JenkinsREST APIwith thesample.pyPython 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.SolutionWhat the jenkins-jobs project tries to do is to map desired information from
the XML format based on the Python classes underjenkins_jobs.jobsmodule.ReferencesTheJenkinsAPIproject.Thepython-jenkinsproject.Stackoverflow question:Groovy to list all jobs.Stackoverflow question:Determining the type of Jenkins project.CreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.0.1 (2021-02-14)First release on PyPI.