Jenkins Multibranch Pipeline Gitlab WebHook - jenkins

I am trying to setup a multibranch build pipeline that will build each branch with a Jenkinsfile everytime a push occurs. I have set everything up, but the issue is that it works with only one branch. I saw a github thread that you need to use the url generated from gitlab plugins build trigger for the GitLab Webhook:
Build when a change is pushed to Gitlab. GitLab CI Service URL: http://...
I used this but this is provides auto-triggering for only the branch I found it in.
How do I change this so that it builds this for all my branchs?

Related

Jenkins does not run the building process after a push

I have the following initial situation:
I have a Docker container running Jenkins 2.379
This Jenkins has the Bitbucket Server Integration and the Bitbucket Branch Sourch Plugin installed
The connection to the Bitbucket server seems to work
I also set up a multibranch pipeline that listens to the repository in the connected Bitbucket server instance
And I have set the Scan Multibranch Pipeline Trigger to All pushes.
Finally, it seems that Jenkins has correctly implemented the webhook in the corresponding Bitbucket project.
Changes to some configurations of the multibranch pipeline trigger the scan process, which works properly. If there are changes in the code of the corresponding branch during a push, the build is triggered.
Clicking the "Scan Multibranch Pipeline Now" button has the same result.
But if I just push some code changes into a branch, nothing happens. My pipeline does not start automatically and no build process is started with the changes made.
Goal: Every push a developer does in a branch of this project should trigger the scan for new branches in Jenkis and the build process for new branches or those where something has changed.
I have found the problem/solution. As I said, my Jenkins runs in a Docker container and is hosted locally on my PC (localhost:8080).
Through the credentials, the path from Jenkins into Bitbucket worked and so did creating the webhook. However, for this webhook, the Bitbucket server plugin entered its address (localhost:8080). So now when a push into a Bitbucket repo happens, this webhook was triggered on Bitbucket's localhost:8080 (so presumably Bitbucket itself and not Jenkins).
The solution was now quite simple. I used a tool called ngrok to make my localhost:8080 (on which Jenkins runs) accessible via a URL from the internet.
I then only had to store this URL in Jenkis in system configurations and adapt the webhook in my Bitbucket repository.

How to decouple Jenkins CI and gitlab CI pipelines?

I've only been working with Jenkins so far. We have configured a Multibranch Pipeline job to automatically build and test software. The tasks are written in Groovy and stored as Jenkinsfile in the root directory of our git repository.
Recently, we have decided to add another mechanism to automatically generate documentation. The generation of documentation (but this could be any other task) has been realized using GitLab CI.
Both pipelines are practically independent - and both are triggered by a git commit/push. What I do not understand is: why and how is the Jenkins pipeline execution associated with the GitLab CI pipeline? In the following screenshot a new column "External" appears - representing the Jenkins pipeline job.
That's not really a big issue. But as both pipelines should be independent - the results of the runs should not influence each other. However, it seems that when the Jenkins job fails, i.e. "External", the GitLab CI pipeline also fails:
Is there a way to better decouple those pipelines, i.e. let them fail or succeed individually?
This is because the Gitlab Branch Source Plugin automatically notify Gitlab about then Jenkins pipeline status. This allow you to see the result of a build directly in Gitlab. If you want to have only the result of the Gitlab CI pipeline in Gitlab, you can disable this feature :
Additional Traits:
These traits can be selected by selecting Add in
the Behaviours section.
[...]
Skip pipeline status notifications - Disable notifying GitLab server
about the pipeline status.
[...]
So in yout Gitlab group, just go the Configure > Projects > Gitlab Group > Add and select Skip pipeline status notifications.
why and how is the Jenkins pipeline execution associated with the GitLab CI pipeline? In the following screenshot a new column "External" appears - representing the Jenkins pipeline job.
In general, "External" statuses are created using the commit build status API -- Jenkins uses this API to report the Jenkins pipeline build status to GitLab CI.
This external status for Jenkins appears in your GitLab pipeline because you have configured your Jenkins server/project to report build statuses to GitLab or you have setup a webhook integration with Jenkins in GitLab (note these may be set at the group level or by an administrator, not necessarily the project level)
To remove this from your pipeline, you should disable any existing integration configurations and setup your Jenkins project independently of any GitLab integration. e.g. using git polling to trigger jenkins builds and remove any updateGitlabCommitStatus calls in your groovy scripts / build stages.

Failed to trigger pipeline Jenkins build from Bitbucket

I am trying to integrate Jenkins with Bitbucket. For this thing, i have installed on the Jenkins the Bitbucket plugin. In the Bitbucket, i have defined a WebHook. Now i want when a new commit is made in a branch, the Jenkins job to be automatically triggered. But this thing is not working, even if the webhook seems to work and the response is 200.
My webhook:
Jenkins configuration:

How can I trigger a Jenkins pipeline run from a GitHub webhook and still allow manual builds?

I am using GitHub pull request builder to trigger pipeline builds from GitHub webhooks when developers make a PR.
To make sure I pull the pipeline script related to the PR I am using Pipeline script from SCM and specifying ${sha1} as the branch specifier. The issue is that when I trigger the build manually, Jenkins is trying to pull a ${sha1} branch (since the env variable doesn't exist).
Is there a way to default to master when triggering the build manually?

Jenkins multibranch pipeline does not detect pull requests in Bitbucket server

I am having trouble getting Jenkins multibranch pipeline detect pull requests created in the Bitbucket server (private instance). I have setup the "Bitbucket server webhook to Jenkins" which is triggering the build on master, develop and feature branches except pull-requests. I have defined the build steps in Jenkisfile and can confirm the PR branch also includes the Jenkinsfile.
In the Jenkins configuration, I have enabled "Discover branches" under Branch Sources configuration
Pull Request isn’t a branch, it is usually something that is done prior to publishing to a branch. Usually, the pull request is approved, then published to the master branch.
Ok. After multiple trial and error and google search, I have managed to get the Jenkins Multibranch pipeline work with Bitbucket server. The key was to use 'Bitbucket' (from bitbucket branch source plugin) as the Branch source. Also, I had to include a dummy trigger in my Jenkinsfile for the Jenkins webhook to work from bitbucket
triggers {
bitbucketPush()
pollSCM('0 0 1 1 0')
}

Resources