Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build project periodically only if changes are found in the repository

I have the following setup active and working:

  • Jenkins with Git and Sonar plugins
  • One jenkins job ( project ) which polls Git each minute
  • One jenkins job ( project-sonar ) which polls git each 24 hours

Both jobs share the same git repository.

This allows me to build my project for each commit and then each day, only if the project has changed, run the Sonar analysis.

I've recently set up the git repository to send notifications to Jenkins when a project has changed, as per Push notifications from repository . This builds both projects immediately, but I want only the quick ( project ) job to build. If I move the project-sonar to be built periodically, the sonar analysis will be run even if there are no code changes, which is wasteful.

How can I retain

  • immediate build for the project build
  • daily build for for project-sonar build

?

like image 751
Robert Munteanu Avatar asked Aug 12 '12 11:08

Robert Munteanu


2 Answers

I implemented something very much like what you're looking at using the "Run Condition" plugin to jenkins. https://wiki.jenkins-ci.org/display/JENKINS/Run+Condition+Plugin

I made the sonar job a follow-on to the polling/build/test job, with conditions so it only runs once a day.

like image 65
Dennis S. Avatar answered Sep 25 '22 06:09

Dennis S.


I've solved this using the following approach:

  1. All jenkins projects are named after their git repository ( I use gitolite )
  2. I have activated only Trigger builds remotely for the base builds
  3. I have added a post-receive hook in gitolite which does something like

    $CURL --silent --netrc --insecure --connect-timeout 2 "$GIT_REMOTE_TRIGGER_URL/$GL_REPO/build?token=$JENKINS_BUILD_TOKEN" > /dev/null

  4. Scheduled all sonar jobs to poll the SCM every 24 hours

like image 25
Robert Munteanu Avatar answered Sep 22 '22 06:09

Robert Munteanu