0

I have a freestyle job with Gitea scm. I setted webhook on Gitea but when others branch change, jenkins will rebuilds once. How can I trigger the build on pushed to master branch only?

Hieu Pham
  • 1
  • 5

1 Answers1

1

I may have fallen into the same trap : I configured Gitea with a webhook pointing to https://jenkins/job/myJob/build?token=abcdef... which starts the job whatever the circumstances.

The correct way seems to point to the git notifyCommit URL : https://jenkins/git/notifyCommit?url=git@code.example.org:ltorvalds/kernel.git and use the SCM polling functionnality :

  • On Jenkins, at job/myJob/configure > Build Triggers, uncheck Trigger builds remotely and check Poll SCM, leaving the schedule empty.
  • Be also sure to specify your branch (for example : refs/heads/master) in Source Code Management > Git > Branches to build.

If the Jenkins job is private, you can add the username/token in the webhook URL like that : https://username:ApiToken@jenkins/git/notifyCommit?url=git@code.example.org:ltorvalds/kernel.git. See https://wiki.jenkins.io/display/JENKINS/Remote+access+API

More infos / duplicate of How can I make Jenkins CI with Git trigger on pushes to master?

Chl
  • 401
  • 4
  • 8