Github Jenkins plugin with Github Enterprise - jenkins

I have a Jenkins server with the following github plugins:
github-api
github
github-pull-request
I want to trigger a build after a merge (from a PR). This is because I have some build chains that I don't execute when building a PR so after a merge I need to create new deployment packages.
In the enterprise github there doesn't seem to be the same interface (as regular github) for webhooks I don't seem to be able define what events the github plugin (webhook) should listen for so I think its just the default 'push' event. Is this done somewhere else or is it a limitation of the enterprise version?
UPDATE
I have the github plugin working now but its builds for every push if I check the box. This disucssion https://groups.google.com/forum/#!topic/jenkinsci-users/gew5gWVDxw8 suggests that I should be able to use the git scm and github plugin together. Github plugin will register a change, scm plugin will poll server to determine if this change was tho the watched branch. I also tried this suggestion How can I make Jenkins CI with git trigger on pushes to master?
When I try and configure this no branch is ever built!

At least for me it's not exactly clear from your question what you actually exactly want.
It sounds like you only want builds to be triggered if there are some new commits on github on a specific branch.
If this is all you're looking for, you can just setup a webhook (Jenkins (Github Plugin)).
In you Jenkins job, just specify the branch you're tracking (Branches to build).
Assuming you setup github's hoock to jenkins correctly, this should trigger your build job on each commit on github enterprise.
If your hook doesn't seem to work: To check if and what your github server actually would send to your jenkins server, you can temporarily replace the url to your jenkins server in github's webhook with something like requestb.in (this will let you inspect github's hook payload)

Related

Jenkins not triggering build on PR merged in bitbucket

We are using Bitbucket cloud to host our repos and Jenkins for CI/CD.
I have setup a multibranch pipeline which has develop and release branches. I want to trigger develop branch whenever a PR is merged from the feature branches to develop a branch (In fact on any manual webhook edit).
Below are the cases I tried:
Setup Manage hook in Jenkin:
This creates a webhook in bitbucket and when PR is merged, build is triggered.
But when I disable the Repository Push option in the webhook, the build is not triggering on PR merge.
Setup the webhook manually:
In this case, the Jenkins logs show the branch name as PR-XY since not triggering the develop branch.
I have set up a regex to filter branches (only develop and release are allowed) and when I add regex like PR(.*) then build gets triggers from the PR section (not desired case).
I want the build to be triggered from the develop branch, not as the PR branch. I have followed most of the options available in the forums but it's not working. Any help regarding this will be appreciated.
I faced the same issue, it's look like most of jenkins plugins like bitbucket plugin does not trigger the pipeline on merge only. even though i set the bitbucket trigger options like this:
unless you add a check mark next to push option.
to solve this i used another Jenkins plugin called Bitbucket Push and Pull Request
just make sure to uninstall Bitbucket plugin if you have it.
so you can use this one as they mentioned in there docs.
and follow the setup instructions.
note: i only test it with normal pipeline job

How to build Jenkins after each push in any branch?

Is there any way to make Jenkins builds after each commit in any branch ?
Because i found in my project's configuration that Jenkins run build only after detecting commits in specific branch or in the default ( eq to master in git ).
PS: i'm using mercurial and Jenkins file.
Should i change project type ( new item type in Jenkins ) or are there any modifications in configs.
There are two things that you should check for this (I haven't work with Mercurial)
Does Mercurial has the option to create webhooks?
There is a jenkins plugin for Mercurial? (I think there is)
You must configure on the mercurial site the webhook pointing to Jenkins and give the point to the job you want to run, and on which events does it will fire. On the Jenkins side you must configure on the job who it will behave.
For example, with GitLab, the plugin has an option configured on the "Build Trigger" section where you configure the events and the branches that fires the job. In GitLab, in the repository you create the webhook, that is only a URL pointing to the Jenkins job.
I got this solution and it worked for me.
with Mercurial, we can use the "tip" keyword.The tip revision is the most recent changeset in the repository. It is the most recently changed head.

Github not triggering job when pull request is created to branch

I need to run a jenkins job when PR is created to my staging branch in github. The jenkins will run some test cases and return the results to github and after that only we can merge the PR to the staging branch.
I'm using GitHub pull request builder plugin in jenkins. But my job in jenkins is not getting triggered when PR is created. The webhook from github is show 200 status and its working to buid a jenkins job for github push.
I followed https://medium.com/#mreigen/integrate-jenkins-builds-into-github-pull-requests-33bc053d6210 steps.
Can anybody help me with This!
Check the Jenkins logs first.
For example, jenkinsci/ghprb-plugin issue 286 mentioned:
It looks like GitHub is sending the wrong kind of events.
The plugin only accepts pull_request and issue_comment events.
GitHub is sending a push event, so I am not sure but you might have configured the webhook using a different plugin?
Check your master config and make sure you are only telling the job triggers to use webhooks. Also, make sure you have checked the box in each job you want that says to build using webhooks.
Issue 603 involved the option "Use github hooks for build triggering", but mention an Hook URL issue.

Bitbucket webhook to trigger Jenkins job

I'm having trouble getting my webhook in bitbucket server to start a Jenkins job. I've read through the other answered questions on here and can't get it going.
Bitbucket setup:
No special plugins installed
In repository settings I have a webhook set up
URL: http://[my jenkins url]/bitbucket-hook/ (yes I have the trailing slash)
Repo Push event selected
Jenkins setup:
Bitbucket plugin installed
Created new job
Set SCM to Git and added repo details
Set branches to build to either ** or refs/heads/rob-jenkins (a branch in git)
Build when a change is pushed to bitbucket selected
What I do:
I make a change to a file in rob-jenkins branch, push and the job is not started in Jenkins.
What I see:
In bitbucket, repo settings, webhooks I can see the webhook fired as soon as the commit is pushed. It has a 200 http status code, response body is empty.
In Jenkins I've set up a logger for
com.cloudbees.jenkins.plugins.BitbucketHookReceiver
com.cloudbees.jenkins.plugins.BitbucketJobProbe
com.cloudbees.jenkins.plugins.BitbucketPayloadProcessor
com.cloudbees.jenkins.plugins.BitBucketTrigger
And when I look at those logs I can see only 1 entry from com.cloudbees.jenkins.plugins.BitbucketHookReceiver
Received commit hook notification : {"eventKey":"repo:refs_changed","date":"2018-05-22T12:18:11+1000","actor":{"name":"xxxxxx","emailAddress":"xxxxxx#xxxxxx.com","id":53,"displayName":"xxxxxx","active":true,"slug":"xxxxxxx","type":"NORMAL"},"repository":{"slug":"xxxxx","id":1,"name":"xxxxx","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"SS","id":2,"name":"xxxxx","description":"xxxxxx","public":false,"type":"NORMAL"},"public":false},"changes":[{"ref":{"id":"refs/heads/rob-jenkins","displayId":"rob-jenkins","type":"BRANCH"},"refId":"refs/heads/rob-jenkins","fromHash":"1d9ad42fa404c893853094b0072e5b839f787589","toHash":"9bf7dc873f355259e4338ee80afbd246ecbb48a9","type":"UPDATE"}]}
There are no other entries in the log.
In the job itself, the BitBucket Hook Log screen just says "Polling has not run yet."
No idea why it isn't triggering the Jenkins job... what am I missing?
I've tried setting the Poll SCM manually and that didn't make a difference.
I've done a manual build and it works fine
as commented by #tomas-bjerre the resolution was to use a different plugin
I would recommend using thie plugin instead: github.com/jenkinsci/generic-webhook-trigger-plugin – Tomas Bjerre yesterday
No plugin needed. Just add a post-recieve hook under your repo in Bitbucket. On Jenkins, under Build Triggers, Trigger builds remotely (e.g., from scripts) Trigger builds remotely (e.g., from scripts) and specify an Authentication Token. A bash or python script can be used for the hook. Anytime a git push is run (not just a commit), you trigger a build!

Run Jenkins build for whichever branch was checked into on Gitlab

I recently made the transition from Subversion to Git for all my repos at work. However, with svn we had commit hooks in place so that our Jenkins job would run for whichever branch was checked into. Now, I'm trying to set this up using Gitlab and there appears to only be one place to add a web hook. It looks like any time something is checked into ANY branch, the web hook will run. Meaning if I have a branch_A associated with jenkins_job_A, something could be checked into branch_B and the commit hook for jenkins_job_A will still run. Is there a branch by branch way to configure these web hooks? Or is there some kind of script I can check into each branch that will act as a commit hook? Or (my fear) is this feature not supported in Gitlab?
I guess you set up GitLab to do a post commit request to http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>? In theory this should trigger the polling on all jobs that are configured with that URL, and in the polling step the jobs should decide whether they should build or not. In practice this will unfortunately cause all jobs to fire.
We worked around this issue by moving the Job configuration into a Jenkinsfile and then use a Multibranch Pipeline.
As an alternative you could also install the GitLab plugin for Jenkins and use the Jenkins integration in GitLab. This will allow you to trigger the correct jobs when commits are pushed on a branch. The downside is that it requires a per-job configuration.

Resources