Jenkins and bitbucket web hooking - jenkins

I'm trying to configure webhook between Jenkins and Bit bucket for a particular branch.
After this, Jenkins job should start if any changes happen in that specific branch, but the first job is triggering when changes happen for any branch.
After that, webhook is working as expected. It will create a problem to copy the existing job as new and forget to check the job trigger.
Is there anyone who faced any issues like this or am I doing any wrong configuration to setup webhook?

By using this Bitbucket Plugin you can specify the branch name as an option in your job configuration.

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 trigger Jenkins job by code change on Perforce automatically

I have one job on Jenkins and its source repo is Perforce. Use P4 plugin to configure source repo and want to trigger this job automatically. There is one Polling SCM but still cannot find change on Perforce but actually there are changes. If build this job manually, code changes can be sync and job works well. So why polling cannot find the changes? Do I miss some configuration?
Thank you in advance.
You can try it the other way around.
Define a webhook in Jenkins (e.g. Generic Webhook Trigger Plugin) and configure the git server to call that on changes.
The other way you generate unnecessary traffic.

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.

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.

Jenkins and GitLab: How to setup SCM aware job which is not triggered by the hook?

To give some context the question is about GitLab and Jenkins setup.
I know how to setup a web hook, I know how to setup a job to be triggered by the hook. The problem is that I need to have multiple jobs and only a single entry-point (parent job) trigger for them.
The downstream jobs at the same time need to be git repo aware so I have to set repo url for them. This causes them to be triggered independently by the hook and I don't want that as this means that they are triggered twice.
On the other hand if I don't configure repo url on a downstream job and the parent job triggers it, it fails as it is not able to do a checkout.
I may try to hack around with some 'execute shell' build step, I believe it's not a valid way to go. Has anybody a good tip how to solve that?
For the reference here is the GitLab Jenkins plugin documentation according to which:
Plugin will parse the GitLab payload and extract the branch for which
the commit is being pushed and changes made. It will then scan all Git
projects in Jenkins and start the build for those that:
match url of the GitLab repo
match the configured refspec pattern if any
and match committed GitLab branch
I tried playing around with different settings, without a great result though.
For the project you want to get only local triggers, just enable Don't trigger a built on commit notification in the Additional behaviours of git plugin.
(https://github.com/elvanja/jenkins-gitlab-hook-plugin/issues/11#issuecomment-35385032, as you actually have discovered).
But a better solution could be to make your downstream jobs reference the repository locally cloned by main job (not sure if actually possible), so the plugin will never consider them for schedule a build, as the git url don't match.

Resources