Trigger Jenkins build via push to a specific branch on GitLab - jenkins

If there is the way to trigger Jenkins build via push to a specific branch on GitLab. At this moment I am using GitLab webhooks integration, to run a specific job? Now it starts after the push to any branch, but I need to start a job from push to the specific branch.

It's now possible since Gitlab 11.3 (https://about.gitlab.com/2018/09/22/gitlab-11-3-released/)

Does not appear to be possible currently by selecting a branch in the GitLab webhook. Feel free to watch progress on this new feature in the GitLab issue Filter web hooks by branch.
I did note in the issue comments the following that might help you configure things via Jenkins:
Jenkins GitLab plugin has an option to filter WebHooks by branch. Under Build Triggers --> Build when a change is pushed to GitLab --> Advanced...

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

Jenkins Gitlab integration - build on pushes to master branch only

I have the same question as this one:
Trigger build only on pushes to master
Only the answer there is not correct. Does anybody know a solution? What sense does it even make to build a certain branch on pushes to any other branch than itself? What I mean to say is that this should really be a very common thing...
In the advanced section of Build Triggers, there's this section, that really looks like the thing:
However, it doesn't work for me. Like this, it does not trigger the build at all. I also tried putting there just master (without the asterisk) but that doesn't help.
If I select the first option (Allow all branches...) then it works, but obviously all the pushes to any branch triggers the build on master which makes no sense.
Any help appreciated.
Thanks!
To integrate GitLab with Jenkins I'd suggest using Gitlab Plugin
Install Gitlab plugin on Jenkins and configure Gitlab Connection (Manage Jenkins -> Configure -> Gitlab), for this you need to create new credentials of type GitLab API token.
Select trigger in Jenkins job configuration Build when a change is pushed to GitLab (when you click on advanced options there is Secret token which should be used together with webhook URL in Gitlab Webhooks).
Add webhook (Push Events) in Gitlab project Settings -> Integrations, with url and token from Jenkins job and filter them by branch name.
Update: So my original point was to filter push events on GitLab so Jenkins doesn't need to do it but as you pointed out it should work with Jenkins filter as well.
I tried filtering branch in my job and Jenkins displayed dropdown list with suggested branches after I started typing, then when I choose brach a label appeared Matching 1 branch:
On the other hand in your screenshot there is some ERROR indicator which would suggest that your GitLab connection is improperly configured. I'd suggest to go to test your connection to GitLab and fix it.

Bamboo plan is not starting with Bitucket commit

I have bamboo set up with the testing branch of my Bitbucket repository, and I have set the build plan to trigger when new commits are pushed. Also linked bamboo from Bitbucket as a sevice and link.
Service Link
The problem is that when I push code to testing branch, it won't trigger the build plan. Is there any other thing to do?

Jenkins pipeline automatic branch detection

I am migrating my old Jenkins free-style job to multi-branch pipeline. I also want to use GitLab hook with them.
My problem is the branch detection. I am doing it manually but I want it to be automatic: when a new branch is pushed to git, GitLab trigger a Jenkins job that trigger the branch detection if the branch parameter from GitLab is not known for Jenkins at the moment. Is this possible to do it or doesn't this exist?
FYI: I tried to launch the multi-branch pipeline job but Jenkins says:
ERROR: No parameterized job named XXX found.
Enable "Build Periodcally" in your multibranch job configuration and the branch indexing will automatically started.
What you really need is a branch source plugin for GitLab with webhook integration, which is tracked as an RFE in JIRA.
Failing that, use a plain Git branch source and configure GitLab to send Jenkins notifications to /git/notifyCommit (IIRC) as documented on the Git plugin wiki. Need specify only a url, no other details. The branch indexing this triggers should both detect new or removed branches, and changes to the head of an existing branch, and schedule builds accordingly.
You can set webhook in GitLab for push events and URL like http://<yourserver>/git/notifyCommit?url=<URL of the Git repository>.
See https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Pushnotificationfromrepository
GitLab notifies Jenkins on push events which should trigger branch detection also for multibranch pipeline.
I didn't receive the answer I wanted and I ran into this issue today that answered the question :
https://github.com/jenkinsci/gitlab-plugin/issues/298
TLDR: Multi-branch pipeline are not supported yet to be triggered by gitlab commit easily. There is a workaround. Look at the link above.

Trigger a new build via Codeship API from Jenkins

I have a CI/CD setup with a Jenkins server to manage our internal CI/CD. We have Codeship performing our CI/CD for our AWS work.
I'm looking to setup jobs on our Jenkins server to manage when new builds are triggered on Codeship.
The aim being, we will have our Jira dashboard integrated with Jenkins in such a way that as an issue's status changes, specific jobs are executed.
So I'm trying to create a job that uses Codeship's API to trigger a new build, but it appears that you can only rerun an old build? How do you trigger a fresh build?
From the docs enter link description here you can only retrieve information and restart previous builds.
You want to run specific jobs, but those must be associated with some specific commit on your repository. You can identify the build for that specific commit and restart it.
Builds are always triggered from your git repository (github or bitbucket), and Codeship is highly dependent on that to keep the flow as simple as possible. You don't need to upload anything anywhere and then command Codeship to run a build on that. All you need is specify a repository and push something.
You could create an internal git server where your developers push to and with jenkins you can push changes from there to a repository connected to Codeship. That way you could control indirectly what gets tested and what does not.

Resources