2

I set up the Github webhook in Jenkins and I created a job with the following configuration:

enter image description here

enter image description here

enter image description here

However, every time I push something from any branch, the job build a new version (using the branch which I specified).

I set up the job by reading some related questions on Stackoverflow but all those questions are quite old and without a clear solution:

GitHub WebHooks triggered globally instead of per branch

Trigger Jenkins job on GitHub PUSH to specific branch

Is it possible to trigger Push only from a specific branch?

Jose Antonio
  • 578
  • 1
  • 8
  • 34

2 Answers2

3

You are using a GitHub Webhook to trigger a preconfigured job. Your Job has the Branch "JENKINS-TEST-AUTODEPLOYMENT" hardcoded, so it will always build this branch only, no matter which branch you are pushing on GitHub.

How about using GitHub Branch Source Plugin? With this Plugin, Hooks will be auto-created in github for the corresponding repos. Each Branch will have a job in jenkins, which is also auto-created as long as you have a Jenkinsfile inside your Repo. With this your desired state should be easily achievable.

LeonG
  • 430
  • 3
  • 14
0

Finally I did it by using Multibranch Pipeline.

  • In Branch Sources:

    1. Add credentials and repository URL.
    2. In Behaviours add: Discover branches: all branches.
    3. Filter by name (with regular expression): for example, ^master|dev|release.$*
  • In Build Configuration add the path to the Jenkinsfile.

So the job will scan for all the branches of the repository that match with the regular expression.

Jose Antonio
  • 578
  • 1
  • 8
  • 34
  • It still doesn't solve the problem you mentioned in the question, just this config will trigger build for any commit to any branch. – Ajay Sharma Dec 23 '20 at 05:03
  • your self answer does not make sense or does not solve your initial issue. – Libert Mar 10 '21 at 15:08