External Monitor Job Type1.7Minimum Jenkins requirement: 1.609.3ID: external-monitor-job
Adds the ability to monitor the result of externally executed jobs.
Jenkins is useful for monitoring the non-interactive execution of processes, such as cron jobs, procmail, inetd-launched processes. Often those tasks are completely unmonitored (which makes it hard for you to notice when things go wrong), or they send e-mails constantly regardless of the success or failure (which results into the same situation as you'll quickly start ignoring them anyway.) Using Jenkins enables you to monitor a large number of such tasks with little overhead.
Setting up a project
Create a new job and choose "Monitor an external job" as the job type.
Monitoring an execution
For Debian / Ubuntu:
Once you set up a project, you can monitor an execution by running a command like this:
If your webserver extracts the
jenkins.war file when it deploys Jenkins then you may use the path directly to the
WEB-INF/lib directory and all other required jars will be found there. Otherwise you may extract these from the war file:
All are found in the
WEB-INF/lib path inside the war file. As long as they are all in the same directory, the
java -jar /path/to/jenkins-core-*.jar command will find the other required jars.
- Note: Older versions of Jenkins (before 1.324) also require
winstone.jarin order to run this command. This jar is found at the top level directory inside the war file, and must be manually added to the classpath (with
-cp) in the java command.
The JENKINS_HOME variable is used to locate the server Jenkins is running, so this must be set. Unless your Jenkins job has build permission for guest users, include the
username:password@ portion of the URL, as seen in the examples above.
- Note: Authentication via username:password in JENKINS_HOME is added in Jenkins 1.324; with previous versions either grant anonymous build permission on the job, or use
curlto post XML to Jenkins (see below).
You can copy
jenkins-core-*.jar and the other required jars to other machines if you want to monitor jobs that are run on a different machine.
stdout and stderr of the program will be recorded, and a non-zero exit code will be considered as a failure.
Monitoring cron jobs
To monitor a cron job, simply run the above set up from your cron script. To avoid receiving e-mails from cron daemon, you might want to write something like:
Note that you can also move the cron job itself to Jenkins by using free-style software project, which would also allow you to manually execute the job outside the scheduled executions.
Submit a run programatically
The above command submits the execution and its result by sending XML to HTTP. This means you can submit an execution record from any program, as long as you follow the same XML format.
The format is explained below:
duration element is optional, since 1.429
description can also optionally be appended, these three elements can be in any order, but must appear after log and result in that order. Console output is hexBinary encoded so that you can pass in any control characters that are otherwise disallowed in XML.
The above XML needs to be sent to
A simple example using curl would be (using no real data; the sequence
4142430A encodes a console output of
ABC plus a trailing line feed symbol):
Submit a run per CLI
The easiest option is for the execution can be submitted per CLI/ssh command. The gzipped log file can be transported through pipe:
Sometimes build number is needed, as the calling program might need to put an URL to the submitted build. The CLI command above returns the new build number. The command above can be called programatically from an Java application. You can find a sample for it here.
Version 1.7 (Jan 06, 2017)
- Allowing non-administrators to configure or delete jobs, given appropriate permissions.
- Japanese localization update.
Version 1.6 (July 26, 2016)
Version 1.5 (July 12, 2016)
- JENKINS-35284 Updated to the new Parent POM and fixed findbugs warnings.
- JENKINS-31162 Item categorization.
Version 1.4 (Nov 18, 2014)
- Updated item label to match new noun-oriented convention.
Version 1.3 (Nov 14, 2014)
- Refined where Build permission was checked to cover also the CLI command.
Version 1.2 (Aug 29, 2013)
- new CLI command (pull #5)
- JENKINS-19377 workaround for log rotation failure
- NPE fix