This walkthrough should give you an overview of the Freestyle Project.
Our first Jenkins job we will set up is to run Drupal Cron every hour, with a 1 hour throttle.
Jenkins — Drupal Cron
- From the main menu select New Item
- Enter a Name for the job and select Freestyle Project, click OK at the bottom of the form. You should now be on the config screen.
- Check Discard Old Builds, cleaning up older builds will help the admin interface perform better. You can choose between Days or Number of Jobs to keep.
- Check Build periodically, this sets the schedule for the build. Jenkins cron system adds a ‘H’ symbol. This is a hashed value based on the job name.
H * * * *Would once an hour
H H * * *Would once a day
H H(0-7) * * *means some time between 12:00 AM (midnight) to 7:59 AM.
- In the Build section choose Add build step and Execute shell
- On your Drupal site navigate to /admin/config/system/cron and copy the cron URL
- End the command text box enter the
wget -O - -q -t 1 https://example.com/cron.php?cron_key=drupalkey7hSsc7QtW3lpANY9VxP2O
- Save and Build now. If all went well the job will be successful.
While curl works for cron, you will need ssh for more robust remote work. Using SSH Agent Pluginyou can add ssh keys per project, folder or globally. If you have access to ssh in to the server it’s best to add the trusted_hosts via
sudo su -l jenkins (setup is beyond the scope of this article).
If you do not have shell access you can use
-o StrictHostKeyChecking=no for the first run of the job. Removing the flag after you have verified connection will ensure the remote server has not changed.
ssh -o StrictHostKeyChecking=no -t [email protected] "/usr/local/bin/drush cron -y --root=/var/www/www.example.com"
Once you have ssh access setup and working you can perform other functions; here are a few examples.
Back up the database
ssh -t [email protected] "/usr/local/bin/drush cr -y --root=/var/www/www.example.com"
ssh -t [email protected] "/usr/local/bin/drush cim -y --root=/var/www/www.example.com"
ssh -t [email protected] "/usr/local/bin/wp cron event run --all --path=/var/www/www.example.com"
Wordpress Flush Cache
ssh -t [email protected] "/usr/local/bin/wp cache flush --path=/var/www/www.example.com"
These examples are just the start of what Jenkins can do for you. If you have questions please leave them in the comments.