freebourn freebourn - 2 months ago 10
Git Question

Scheduling a nightly build in Jenkins with multiple conditions

I would like to trigger a Jenkins build when the following conditions are met:

  • Time is 22:00 PM

  • A commit has occurred since the last build

I have only been able to either run it nightly (whether there has been a commit or not) using the Build periodically trigger, or only after a commit using the Poll SCM trigger or just a webhook from Stash.

I've tried using both Poll SCM and Build periodically but it ends but never running.

Does anyone have a solution for this case?

I would like my nightly to run only if there's been development activity.

Answer Source

See Git Plugin, Environment Variables:

The git plugin sets several environment variables you can use in your scripts:

  • GIT_COMMIT - SHA of the current

  • ...

  • GIT_PREVIOUS_COMMIT - SHA of the previous built commit from the same branch

If these are the same, there was no change. Use them in the Conditional BuildStep Plugin to decide whether your nightly shall run or not.