Openshift - trigger Jenkins build on git push - jenkins

I work with Openshift now and I have a problem.
I created an application server with Jenkins and when I push to the master branch of the git repository the Jenkins build is triggered automatically.
The point is that the build isn't triggered when I push to another branch (not master).
I've read topics like this one (How to configure Git post commit hook) and I do realize what the ways to make Jenkins build on git push are.
Unfortunately I haven't found any information about how this is done in the Openshift Jenkins. This mechanism is already implemented there and I simply want to replace the trigger from the "master" branch to another one.
How can I do it?

You can refer to the "Configuring Which Branch to Deploy" section from the following page:
https://developers.openshift.com/en/managing-deployments.html#configuring-which-branch-to-deploy

Related

Jenkins is getting build automatically twice likely because of GIT Scm polling

Problem Statement: Jenkins is getting an automatic build when only one build is pushed.
Project Setup: What I am trying to achieve is Jenkins-Github CI/CD setup. A simple Flask application is built and the same is pushed to Github test branch first. The repository has a webhook setup so that whenever a push event is detected a POST request to the Jenkins URL - this part is working fine. In Jenkins I have a simple Pipeline where I have the Github project configured and for Build option chose "GitHub hook trigger for GITScm polling". The pipeline setup is shown below. The pipeline (scripted) is also very simple -
builds a docker image of the flask application
performs few unit tests on the application
pushes the docker image to docker hub
pushes the code to master branch
sends notification.
What is happening that I observed: Once the github push is triggered and Jenkins build starts running which is expected but as soon as the 4th stage is reached observed that another Jenkins build is automatically started which I think is because of the webhook setup.
Now, I might be absolutely wrong as this is my first try (POC sort of) at Jenkins and also to be fair I was not very sure if I am doing/trying the right thing and also if this is the correct method to do such things. So, I would highly appreciate if I am being corrected here or atleast provided a correct approach. Please let me know if more information (script/code etc..) is required - thanks in advance.
Code used at scripted pipeline for pushing to master branch from test branch -
sh """git remote set-url origin git#github.com:xxxxxxxxxxxxxxx/FlaskApp.git
git checkout test
git pull
git checkout master
git pull origin master
git merge test
git status
git push origin master
"""
Edit:
Screen-grab of github webhook configuration-
Environment: Jenkins 2.249.1

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!

Triggering CI builds using Jenkins on remote build machine

I am trying to implement CICD with Jenkins. I have my code in git repo. The moment I make a change to git repo files, I wish to trigger a Build that should run on remote machine.
This means If I change a file in Git Repo 10 times, I should have 10 Builds, each build corresponding to one change.
Can anyone tell me how this can be done ?
I tried to make use of post-commit hook, but its not working.
What flavor of GIT? Do you use? If you share you config details of webhook and Jenkins additional info can be provided. Per my experience it is a two step process.
Enable the webhook in GIT
Create a job with appropriate configuration to map to the repository and get triggered on commit

jenkins doesn't generate the build automatically using local git repository

In my system i am using local git repository and jenkins server,I clone the bitbucket repository into my local git repository and perform all the operations it does well.
I would like to generate the bulids automatically whenever there is push is going from local git to bitbucket for that i give the git repository url in the source code management and mark the build trigger `when a change is pushed to bitbucket
Later i apply and press save.
Now I did some modifications in local git and pushed it also,it is successfully pushed and data is updated in bitbucket also but in jenkins there is no build
can any one please help to me.
If you do not want to poll, you must configure BitBucket to notify your Jenkins when something happens. These are called "hooks". You can read about them at https://confluence.atlassian.com/display/BITBUCKET/Manage+Bitbucket+hooks and there is a whole section on how to configure a hook for Jenkins.

How to build the new branch pushed to github using Jenkins CI?

I've setup the Jenkins for the rails3 app to build the specs.
One can find many posts via google on how to setup the build trigger on the github push.
But what I want is to build the new remote branch pushed to Github.
e.g.
I've a repo origin/master. I cloned the repo, created a new branch, did some commits and pushed that branch to origin git push -u origin new_branch
Now I want the Jenkins to build this newly pushed branch on the origin.
If the build is successful, then Jenkins should merge it into origin/master automatically.
The Jenkins plugin has github, git plugin. But it requires to put the branch name. Instead I want to build the new_branch dynamically.
How can I setup such process?
If I remember correctly branch name is not a required entry. You need to test it, but I think if you do not fill it, Jenkins tests all new commit in the repo regardless which branch is affected.
But I recommend you do not merge automatically. You do not want that, trust me. :-)
It seems can not do that with only github and gitgub parameter plugin. If you specify branch_regex*** in Branch to build, Jenkins always build the latest commit in the bunch of branches that it saw. Must specify a branch in order Jenkins to build on the latest commit in that branch. I also see some answer with Multi Branch Pipeline but not sure how to deploy that way. There is no specific instruction at all.

Resources