Jonathan Ö
Jonathan Ö

Reputation: 141

Jenkins CLI List-Jobs with folders

While using the Jenkins Folders Plugin, is there a way to get a list of all jobs (including jobs in folders and possible the folder path) simular to how list-jobs in the default CLI works?

I have made a small PowerShell script to get info for the last build of every job in the default dashboard and export relevant info to excel. But now we started using folders, and it doesnt work for folders and the jobs in them.

My old import code:

java -jar jenkins-cli.jar -s http://localhost:8080 list-jobs --username $username --password $password > jobs.csv

http://pastebin.com/raw/rcj99rjx for my full code with comments

Upvotes: 5

Views: 14570

Answers (2)

yoyo
yoyo

Reputation: 8708

The list-jobs command can show the jobs in a folder (or "view"). So you can iterate the top-level list (assuming it is a list of views) and then list the jobs in each of those views.

In a Windows cmd shell, that looks like this:

for /f "usebackq" %F in (`java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobs`) do java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobs %F

Upvotes: 0

Jonathan Ö
Jonathan Ö

Reputation: 141

Solved it by running a groovy script.

import jenkins.model.*
import hudson.model.*
Jenkins.instance.getAllItems(AbstractProject.class).each { println(it.fullName) };

and this cli code to call for the script.

java -jar jenkins-cli.jar -s http://localhost:8080 groovy all_jobs.gsh --username $username --password $password > jobs.csv

Upvotes: 6

Related Questions