Tim
Tim

Reputation: 389

"Build only if SCM changes" is set to true in jenkins job but doesn't build with the latest commit

I have a job BuildApp with a build (MultiJob Phase) that calls another job BuildAppJar to build a jar. In job BuildApp, "Build only if SCM changes" is set to true. I am expecting the job BuildAppJar will build a jar file with the latest commit because Job BuildApp is configured to build when SCM changes. But this is not happening. Instead I am getting this log saying "subjob has no changes since last build." Why is it so? Any idea? Isn't Jenkins supposed to build with the latest code commit? I am using Git.

[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
    >> Job status: [BuildAppJar] subjob has no changes since last build. 

Thanks.

Upvotes: 2

Views: 8509

Answers (2)

Oleksandr Bodashko
Oleksandr Bodashko

Reputation: 131

It works! The problem is - Jenkins can't detect changes of subjob branch. You must perform, for each subjob, poll SCM or notify Jenkins by using WebHook.

Example of my usage with WebHook:

  1. Install SCM Skip Plugin (https://github.com/jenkinsci/scmskip-plugin) to avoid automatic building after push to your branch.
  2. In your subjob projects Configs:

    section Build Triggers:

    • check "Build when a change is pushed to GitLab. GitLab webhook URL:"
    • check "Poll SCM" (without schedule).
    • click on "Advanced" button and verify if option "Enable [ci-skip]" is checked (must be checked by default).

    section Build Environment:

    • check "SCM Skip".
  3. Into GIT project, add WebHook located at Settings -> WebHooks.

    • put URL: <jenkins_url>/gitlab/notify_commit
    • check "Push events"
  4. In Multijob Configs:

    section Multijob specific configuration :

    • check "Poll subjobs in addition to multijob when polling"

    section Build Triggers:

    • check "Poll SCM" (without schedule).
  5. Commit you changes with message that contains word [ci-skip] to skip automatic build.

Now you can push changes to your branch, Jenkins will be notified and build skipped. After that, run your MultiJob.

Upvotes: 0

andrew lorien
andrew lorien

Reputation: 2688

This may be because of this bug (I believe both are the same problem):

https://issues.jenkins-ci.org/browse/JENKINS-50168

https://issues.jenkins-ci.org/browse/JENKINS-55524

The symptom is that Jenkins is polling two repositories, but doesn't check the correct one for changes. Add your "git polling log" (or, depending on your plugin, whatever log appears at the bottom of the list above your build history) for confirmation. I have not found a workaround.

Webhooks (gitlab, bitbucket, or whatever) don't actually cause Jenkins to build a particular commit - the webhook just notifies Jenkins that something has changes, and Jenkins polls the repository to see whether that change should trigger a build. In my case, Jenkins receives the hook, polls the repo, then polls another repo (also used by that job, but rarely updated) and checks it for changes. So you need to have "Build when a change is pushed to GitLab" and "Poll SCM" both checked.

For a long list of other possibilities, check https://issues.jenkins-ci.org/browse/JENKINS-17614

Upvotes: 1

Related Questions