Setting up the cron jobs in Jenkins using “Build periodically” – scheduling the jenins Job

cron-jobs-in-jenkins

Setting up the cron jobs in Jenkins using “Build periodically” – scheduling the jenins Job

Examples –
To schedule your build every 5 minutes, this will do the job : */5 * * * * OR H/5 * * * *

To the job every 5min past every hour(5th Minute of every Hour) 5 * * * *

To schedule your build every day at 8h00, this will do the job : 0 8 * * *

To schedule your build for 4, 6, 8, and 10 o’clock PM every day – 0 16,18,20,22 * * *

To schedule your build at 6:00PM and 1 AM every day – 0 1,18 * * *

To schedule your build start daily at morning – 03 09 * * 1-5

To schedule your build start daily at lunchtime – 00 12 * * 1-5

To schedule your build start daily in the afternoon – 00 14 * * 1-5

To schedule your build start daily in the late afternoon – 00 16 * * 1-5

To schedule your build start at midnight – 59 23 * * 1-5 OR @midnight

To run a job on 9.30p.m. (at night) on 3rd of May then I ll write or 21.30 on 3/5/2011 – 21 30 3 5 *

Every fifteen minutes (perhaps at :07, :22, :37, :52) 0 – H/15 * * * *

Every ten minutes in the first half of every hour (three times, perhaps at :04, :14, :24) – H(0-29)/10 * * * *

Once every two hours every weekday (perhaps at 10:38 AM, 12:38 PM, 2:38 PM, 4:38 PM) – H 9-16/2 * * 1-5

Once a day on the 1st and 15th of every month except December – H H 1,15 1-11 *

CRON expression

A CRON expression is a string comprising five or six fields separated by white space that represents a set of times, normally as a schedule to execute some routine.

Format

Field name

Mandatory?

Allowed values

Allowed special characters

Remarks

Minutes Yes 0-59 * / , –
Hours Yes 0-23 * / , –
Day of month Yes 1-31 * / , – ? L W
Month Yes 1-12 or JAN-DEC * / , –
Day of week Yes 0-6 or SUN-SAT * / , – ? L #
Year No 1970–2099 * / , – This field is not supported in standard/default implementations.

In some uses of the CRON format there is also a seconds field at the beginning of the pattern. In that case, the CRON expression is a string comprising 6 or 7 fields.

Special characters

Support for each special character depends on specific distributions and versions of cron
Asterisk ( * )
The asterisk indicates that the cron expression matches for all values of the field. E.g., using an asterisk in the 4th field (month) indicates every month.
Slash ( / )
Slashes describe increments of ranges. For example 3-59/15 in the 1st field (minutes) indicate the third minute of the hour and every 15 minutes thereafter. The form “*/…” is equivalent to the form “first-last/…”, that is, an increment over the largest possible range of the field.
Comma ( , )
Commas are used to separate items of a list. For example, using “MON,WED,FRI” in the 5th field (day of week) means Mondays, Wednesdays and Fridays.
Hyphen ( – )
Hyphens define ranges. For example, 2000-2010 indicates every year between 2000 and 2010 AD, inclusive.
Percent ( % )
Percent-signs (%) in the command, unless escaped with backslash (\), are changed into newline characters, and all data after the first % are sent to the command as standard input.[7]

Non-Standard Characters

The following are non-standard characters and exist only in some cron implementations, such as Quartz java scheduler.
L – ‘L’ stands for “last”. When used in the day-of-week field, it allows you to specify constructs such as “the last Friday” (“5L”) of a given month. In the day-of-month field, it specifies the last day of the month.
W – The ‘W’ character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify “15W” as the value for the day-of-month field, the meaning is: “the nearest weekday to the 15th of the month.” So, if the 15th is a Saturday, the trigger fires on Friday the 14th. If the 15th is a Sunday, the trigger fires on Monday the 16th. If the 15th is a Tuesday, then it fires on Tuesday the 15th. However if you specify “1W” as the value for day-of-month, and the 1st is a Saturday, the trigger fires on Monday the 3rd, as it does not ‘jump’ over the boundary of a month’s days. The ‘W’ character can be specified only when the day-of-month is a single day, not a range or list of days.
Hash ( # )
‘#’ is allowed for the day-of-week field, and must be followed by a number between one and five. It allows you to specify constructs such as “the second Friday” of a given month.[8]
Question mark ( ? )
In some implementations, used instead of ‘*’ for leaving either day-of-month or day-of-week blank. Other cron implementations substitute “?” with the start-up time of the cron daemon, so that ? ? * * * * would be updated to 25 8 * * * * if cron started-up on 8:25am, and would run at time every day until restarted again.

In addition, @yearly, @annually, @monthly, @weekly, @daily, @midnight, and @hourly are supported as convenient aliases. These use the hash system for automatic balancing. For example, @hourly is the same as H * * * * and could mean at any time during the hour. @midnight actually means some time between 12:00 AM and 2:59 AM.

Reference:
https://en.wikipedia.org/wiki/Cron#CRON_expression

Tagged : / / / / / / / / / / / /

Know About Jenkins CLI | Jenkins CLI Guide

jenkins-cli

Running CLI
java -jar jenkins-cli.jar [-s JENKINS_URL] command [options…] [arguments…]

Getting help
java -jar jenkins-cli.jar -s yourserver.com help [command]

How to download jenkins-cli.jar?
The best place to download the Jenkins CLI jar is from your own Jenkins server. This means you’ll have the matching CLI version. Visit the /cli endpoint, such as http://yourserver.com/cli, and it will give you a link to download the jar (the /jnlpJars/jenkins-cli.jar endpoint). Download that jar.

Running commands against a secure Jenkins (basic auth or ssh keys)

If your Jenkins is secured, and it probably is so that you control who can create jobs, run jobs, view results, then the command above may fail and ask for credentials.
You have two options: provide –username & –password options to every command or provide -i option and provide the path to the ssh private key that matches the public key you provided to your user account.
For example:

$ java -jar jenkins-cli.jar -s http://myjenkins help –username me –password mypassword
$ java -jar jenkins-cli.jar -s http://myjenkins help -i ~/.ssh/id_rsa

Passing parameters when triggering a job build
To pass those same parameters via the CLI? You use the -p key=value flag for each parameter you want to pass.

So our finished product might look like:

$ java -jar jenkins-cli.jar -s http://myjenkins build ‘Deploy XYZ App’ -i ~/.ssh/id_rsa -s -v -p target_env=api.cloudfoundry.com -p branch=master

How to get all commands for Jenkins CLI-
Run > http://yourserver.com/cli

java -jar jenkins-cli.jar -s http://fmsscm.corp.intuit.net/qbo-qa/ help

Available Commands

  • build: Builds a job, and optionally waits until its completion.
  • cancel-quiet-down: Cancel the effect of the “quiet-down” command.
  • clear-queue: Clears the build queue
  • connect-node: Reconnect to a node
  • console: Retrieves console output of a build
  • copy-job: Copies a job.
  • create-job: Creates a new job by reading stdin as a configuration XML file.
  • create-node: Creates a new node by reading stdin as a XML configuration.
  • delete-builds: Deletes build record(s).
  • delete-job: Deletes a job
  • delete-node: Deletes a node
  • disable-job: Disables a job
  • disconnect-node: Disconnects from a node
  • enable-job: Enables a job
  • get-job: Dumps the job definition XML to stdout
  • get-node: Dumps the node definition XML to stdout
  • groovy: Executes the specified Groovy script.
  • groovysh: Runs an interactive groovy shell.
  • help: Lists all the available commands.
  • install-plugin: Installs a plugin either from a file, an URL, or from update center.
  • install-tool: Performs automatic tool installation, and print its location to stdout. Can be only called from inside a build.
  • keep-build: Mark the build to keep the build forever.
  • list-changes: Dumps the changelog for the specified build(s).
  • list-jobs: Lists all jobs in a specific view or item group.
  • list-plugins: Outputs a list of installed plugins.
  • login: Saves the current credential to allow future commands to run without explicit credential information.
  • logout: Deletes the credential stored with the login command.
  • mail: Reads stdin and sends that out as an e-mail.
  • offline-node: Stop using a node for performing builds temporarily, until the next “online-node” command.
  • online-node: Resume using a node for performing builds, to cancel out the earlier “offline-node” command.
  • quiet-down: Quiet down Jenkins, in preparation for a restart. Don’t start any builds.
  • reload-configuration: Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.
  • restart: Restart Jenkins
  • safe-restart: Safely restart Jenkins
  • safe-shutdown: Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins.
  • session-id: Outputs the session ID, which changes every time Jenkins restarts
  • set-build-description: Sets the description of a build.
  • set-build-display-name: Sets the displayName of a build
  • set-build-parameter: Update/set the build parameter of the current build in progress
  • set-build-result: Sets the result of the current build. Works only if invoked from within a build.
  • set-external-build-result: Set external monitor job result.
  • set-next-build-number: Set build number to be used for next build.
  • shutdown: Immediately shuts down Jenkins server
  • update-job: Updates the job definition XML from stdin. The opposite of the get-job command
  • update-node: Updates the node definition XML from stdin. The opposite of the get-node command
  • version: Outputs the current version.
  • wait-node-offline: Wait for a node to become offline
  • wait-node-online: Wait for a node to become online
  • who-am-i: Reports your credential and permissions

Reference –
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
http://stackoverflow.com/questions/18199355/jenkins-cli-authentication
http://stackoverflow.com/questions/16617232/jenkins-cli-public-key-authentication-where-to-put-my-public-key-in-jenkins

Tagged : / / / / / / / / / /

How to Integrate Jenkins with SVN ? | Jenkins Integration with SVN Guide

jenkins-with-svn

Hi Rajesh,

Can you please help me to configure LDAP in SVN,i checked with some of my friends but i am not able to understand that.If you having any document related to LDAP configuration please send to me or you replay here also.
Thanks & Regards
Sujeet Sahu
M:09741939212
Mail id: sahusujeet@ymail.com
Tagged : / / / / / / / / / / / / / /