0

I have several jobs running periodically on Jenkins. They are set up using the graphical interface:

enter image description here

Now I need to write a script that will pull information about when/how often does job run. How can I find this information?

I tried looking for this information using Remote Access API in XML, but to no avail.

Edit: Because some people find it hard to read such a short post, I would like to point out that I'm asking(literally) How to check how often is Jenkins building job? for script. Question means more or less how to get cron schedule for the job, not how to get Build number + Status[success/failed etc] + Duration from Jenkins.

Honestly, I can't see how one could even think that these are duplicates.

MatthewRock
  • 1,071
  • 1
  • 14
  • 30
  • possible duplicate of [Jenkins—get "Build Time Trend" values using "Remote Access API"](http://stackoverflow.com/questions/13799652/jenkins-get-build-time-trend-values-using-remote-access-api) – Dave Bacher Sep 22 '15 at 23:39
  • could you explicitly state what you want? Do you want to get the cron schedule for the job if it exists or do you want to get the approximate time between the job runs? Or do you want to get an approximate estimate on at which hours of the day the job is run based on N previous runs? – Zloj Sep 23 '15 at 09:46
  • @Zloj I mean cron schedule. Updated question to provide this information. – MatthewRock Sep 23 '15 at 10:08
  • @MatthewRock, fair enough, I misunderstood your question -- to me, "when/how often does a job run" sounds like you want to find the actual time. The editorial comments are unnecessary. – Dave Bacher Sep 23 '15 at 15:34
  • @DaveBacher Yeah, sorry for that - some problems can be frustrating. – MatthewRock Sep 23 '15 at 15:41

1 Answers1

1

Here you go:

SCHEDULE=$(cat ${JENKINS_HOME}/jobs/${JOB_NAME}/config.xml | grep -A 1 ' <hudson.triggers.TimerTrigger>' | tail -1 | awk -F'[<>]' '{print $3}') if [ -z "${SCHEDULE}" ]; then echo "${JOB_NAME} isn't configured to run periodically" fi

You need access to filesystem on which Jenkins has it's home.

If this approach does not suit you - you can use token authentication or password/LDAP/whatever to download the job config xml to your working directory and parse it the same way. This might be helpful if you decide to do so.

Zloj
  • 2,235
  • 2
  • 18
  • 28