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

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.

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

Bamboo build tying to undesired BitBucket Commit

Context
I have a BitBucket repo and a Bamboo Plan. The Bamboo Plan is tied to the Bitbucket repo in the "Repository" settings.
The Bamboo Plan "Branch" settings are set to create a new Branch when a new branch is created in the repo.
Issue
When I create a branch, bamboo makes a new branch and starts the build. The first build is tied to the latest commit which came from the original branch. I don't want to associate the new branch build with a commit to the original branch. (It causes more than one build to be associated with the commit.)
Desired Outcome
The build should only tie to new commits in the branch.
Solutions
Pull Request Trigger
I modified my bamboo plan to only trigger new bamboo branches when a Pull Request is created for the repo branch. It did give me the desired outcome. The downside is that commits to the branch will not be executed against the CICD process until a PR is created.
Is there a way to create Bamboo branches only on the first commit to a new repo branch?
No.
I'm sorry there isn't much you can do about this.

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.

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.

Openshift - trigger Jenkins build on git push

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

Resources