Trigger Jenkins Multi-Branch Pipeline from GitLab push - jenkins

I run a Gitlab and a Jenkins server locally. I connected those two using the gitlab-branch-source plugin. For every repository in gitlab i create a multibranch-pipeline job in jenkins. When a user pushes code, I want the corresponding job to be executed.
I'v tried a solution suggestend in this post and this one. Both of them don't seem to work.
In the gitlab server settings on the jenkins server I've set the check at "Manage Web Hooks". The personal access token which is used for the integration has the scopes "api, sudo".
What else could I try?

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.

Sending gitlab webhooks from local instance of gitlab to local instance of jenkins

I have a local instance of Jenkins.
What i need isto launch a jenkins pipeline triggered by a local commit or push on a gitlab instance.
For several reasons of testing, i need to keep all in localhost.
So, what i'm struggling with is:
It's possible to install a local instance of gitlab on windows 10 (I've heard about gitlab runner, could it be suitable for sending webhooks?)?
How to set the webhooks from gitlab to my localhost jenkins?
Thanks anyone
Following might help you.
You need to integrate the Jenkins Job with the Gitlab Instance.
In Gitlab Instance you have to activate the Jenkins Integration
and
Decide on the trigger you want to use to trigger the
jenkins pipeline. (In my case only Push Trigger is active)
Then you need to provide details
Jenkins instance URL
Jenkins Pipeline Job Name
Authentication with a jenkins account user id and password.
Once you do this each you do the trigger action in the gitlab the pipeline will be triggered.

Jenkins freestyle project using Gitlab API Token never clone the repository, no error, build always succeed

I've followed this gitlab tutorial link, to connect my jenkins server to Gitlab.
Everyting went fine, and I've :
created a personnal access token in my GitLab profile
created a GitLab API Token using the my GitLab access token in jenkins system configuration as stated in the tutorial
create a freestyle jenkins job and Choose my GitLab connection from the dropdown
checked the Build when a change is pushed to GitLab checkbox.
checked the Accepted Merge Request Events and Closed Merge Request Events checkboxes
generated a secret token from the above freestyle project
use the freestyle jenkins project secret token to create a webhook in the GitLab project repository integration settings
Till there everything went fine.
Then I added and push code including a jenkinsFile to my GitLab repository, and get to the Jenkins WebUI to view the build status, but the pipeline shown green saying build success, while nothing happened, no code has been retrieved from GitLab (as shown in the attached console output screenshot), thus no jenkinsFile executed nor error message shown.
I tried to run the buils manually from WebUI but same result, no way to trigger my pipeline on git push events from GitLab
I thought may be I should select Git in Source Code Management section (I left it to None as the tutorial doesn't mention it) but if I choose Git as SCM I cannot select my GitLab API Token credentials, seeming like we cannot use GitLab plugin (API Token) and Git plugin for the same build project.
SO how should I proceed to be able build my jenkins project from GitLab with a jenkinsFile, using GitLab API Token?
Does the GitLab tutorial miss some useful steps?
OK, I think I understand the issue now.
There are two sets of credentials: GitLab API token for access to GitLab Webhooks and a separate one for cloning the git repo during builds.
So we can't use the GitLab API token for cloning the repository. For this you have to use either a SSH key or a Username/Password combination. Furthermore this dropdown is part of the git plugin not the gitlab plugin.
So the gitlab plugin can't tell which credentials are available as credentials for this dropdown.

Trigger Jenkins job on code commit to Azure repository

I have a Jenkins job running on my localhost:8080. I want to trigger this job automatically whenever there is a commit on Azure repos (Azure DevOps).
Any advise on how I can achieve this?
Thanks
Since Jenkins job running on your localhost:8080. You need to create your self-hosted agents on the local machine which your jenkin server can communicate to. Then you need to create a azure pipeline to be triggered on Azure repos commit and run this azure pipeline on your self-hosted agent. You can check out below workarounds:
Enable Trigger builds remotely on Jenkins
Go the the Build Triggers Tab of your jenkins pipeline configure page--> Then check Trigger builds remotely--> Specify a Token (will be used in the URL)
Define a secret variable to host your jenkins password(eg. password) in azure devops pipeline:
Add a bash task in your azure devops pipeline to run the below curl command
#token must be the same with the token you entered in above step
curl -u $(username):$(password) http://localhost:8080/job/myproject/build?token=anytoken
Targeting your self-hosted agent pool to run your azure devops pipeline on self-hosted agent.
There is another workaround using Jenkins queue job task.
Create a API Token in your Jenkin server.
Go your jenkin account configure page. To create a API token.
Add Jenkins queue job task in azure devops pipeline
Click the Manage link to create a jenkins service connection--> In the newly opened page-->Create Service connection-->Select Jenkins--> Next
Enter the required information. Note: url is your local jenkin server. username is your user account for jenkin server, the Password is the API Token You generated in above step.
Another workaround is to configure the Poll SCM build triggers on your jenkins job. So that the jenkin server will periodically poll the source code and queue the job if there is new commit.
See this thread for more information.

integrating gitlab with jenkins using webhooks does not work

I am trying to trigger jenkins pipeline on gitlab push to branch and tag.
Using Jenkins ver. 2.176.2 and gitlab version 10.7.3-ee.
Although I have supposedly set up the webhooks properly, I do not see the jenkins job being triggered.
I have installed the gitlab plugin for jenkins, and configured the gitlab server, including the Personal Access Token for GitLab APIs access generated in gitlab.
I have defined the webhook (currently requesting trigger on all events). (for testing, ssl verification is off).
When testing the webhook in gitlab, I consistently receive HTTP error 500.
In jenkins pipeline job, I have selected "build when change is pushed to gitlab. gitlab webhook..." - this is the URL I used when defining the webhook in gitlab, under "integrations" section.
When pushing to gitlab, I see no event listed under "integrations -> recent deliveries",
I see no log under jenkins logs "com.dabsquared.gitlabjenkins" logger (set to log level "FINEST".
And lastly, the pipeline job is not triggered as I expected.
Any leads will be very helpful.
Adding printscreen of the Jenkins configuration of the gitlab for reference to the comment I added on possibility this is issue with the personal access token
Jenkins gitlab server configuration
Go to Settings of Gitlab Project -> Integrations and type in the Jenkins Job project url in 'URL'. URL should take either form:
http://JENKINS_URL/project/PROJECT_NAME
http://JENKINS_URL/project/FOLDER/PROJECT_NAME
Notice that the url does not contain "job" within it and instead uses "project".
Make sure under Triggers, you have "Push Events" checked as well if you want the job to trigger whenever someone pushes a commit.
Finally, run a build against your Jenkinsfile first before testing the webhook so Jenkins will pick-up the trigger settings for Gitlab.
Please refer the link for more details.

Resources