chetra tep
chetra tep

Reputation: 189

Make jenkins auto build one a day but build only when there are source code changed

I have problem in configure jenkins to auto build and deploy java project. I want to build and deploy once a day. However this build only there are changes during the day. IF there is no changes, I don't want jenkins to auto build and deploy. Note: that I used gitlab as source code management. Can you help me with this configuration.?

Upvotes: 3

Views: 3102

Answers (2)

Christopher Orr
Christopher Orr

Reputation: 111555

Firstly, you should configure the Git SCM section at the top of the job config page to point to your GitLab repository.

Then you can use the built-in "Poll SCM" build trigger — this will periodically check whether your source code repository has changed — and if it has, a build of this job will be started.

If the repository has not changed since the last build, then no build will be started.

You can configure this trigger — whether using a cron-like syntax, or a shortcut like @daily or @midnight — so that Jenkins only checks the source repository once a day.

Additionally, you should make sure that the "ignore post-commit hooks" option is enabled. If you're using webhooks from your Git repository to start Jenkins jobs whenever a commit occurs, this option prevents your once-per-day job from being triggered for every Git commit.

Upvotes: 3

Tuan
Tuan

Reputation: 2363

Here's the detail document: "Jenkins CI integration"

http://doc.gitlab.com/ee/integration/jenkins.html


Update to match your comment.

You don't want to trigger the Jenkins build via webhook. It's ok.

You want to check the code change 1 time a day.

Example on Linux, build at 6:00 AM if there's any code change.

Like this

SINCE=`curl http://192.168.0.1:8080/job/MyJava/lastStableBuild/buildTimestamp?format=dd-MMM-yyyy`

cd /opt/code/myjava/

git log --pretty="%h - %s" --author=gitster --since=$SINCE --before=$SINCE --no-merges -- t/
  • Post Build actions

    • Post build task
    • Log text: commit
    • Operation: AND
    • Script: Your script to build your Java
  • Jenkins text finder

    • Also search the console output
    • Regular expression: Could not match
    • Unstable if found

Upvotes: 1

Related Questions