Gitlab jenkins integration - jenkins

I am using jenkins as CI server and Gitlab as Codebase both are running into two serpent docker containers.
I have created CICD pipeline into jenkins and gitlab repo. also setup webhook which working fine. Now I want to integrate jenkins from gitlab and inserted required details but it showing 401 error while test. please note entered details are verified and credentials are working.
enter image description here
enter image description here

401 indicates that the request is unauthorized. So, stated another way: your credentials are correctly set, but the credentials do not have the appropriate permission needed.
You should make sure your API keys are generated with appropriate scope and/or that the user account associated with the keys have appropriate permission.

Related

gitlab plugin test connection issue on jenkins

Im having issue with gitlab plugin test connection on jenkins. it gives error when I hit the "test connection" button with the given values.
GitLab user is maintainer and has full access on it. GitLab API token belongs to this user.
unfortunately it seems no way to track this error. I checked the logs files in jenkins machine as well.
GitLab Plugin Version is -> 1.5.27
you may see screenshot of the page here
alternative link:
https://gyazo.com/2b81c4310c7a144651fda54c6b1462c1

Bitbucket Webhook is not triggering Jenkins job even webhook returns 200

I am using bitbucket cloud and jenkins is running on ec2 instance on the private network.
Connection is well established between bitbucket and jenkins as when i run the job manually, the job shows the green status. However when i made the changes in the repo and it gets merged the webhook is not using my app password and as a result the job is getting failed.
I am getting authentication failed and It's basically asking me to use the app password. I have already created it but still webhook is not using it. I am getting the response 200 now in webhook means my webhook is able to reach the jenkins server but i am not sure why i am getting authentication failed.
Can you confirm that:
Your credentials are correctly placed under the credentials section of Jenkins. The username should be the username of the account you are using, and the password should be the app password. It should be present like this:
The ID of the credentials should be used within your pipeline script anywhere you want access to the Bitbucket repository.
Ensure that Bitbucket has access to your EC2 instance that runs Jenkins.
Basically, these are the 3 points where authentication can fail. Checking each point should reveal the problem.

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.

BitBucket Webhook - Unable to connect to Jenkins URL

I am trying to create a webhook in BitBucket to trigger a build in Jenkins, but when I enter my Jenkins URL, and I test the connection, I get the error "Unable to connect to the URL specified, check the host and port are correct." I am using the URL http://localhost:8080/bitbucket-hook/ (with the last back slash included) and I can confirm that in Jenkins, my "Jenkins URL" is set to http://localhost:8080/. In Jenkins, I have installed the plugin "BitBucket Server Integration", and under Configure System -> Bitbucket Server Integration, I have connected to the Bitbucket server (and when I test the connection, it says "Jenkins can connect with the Bitbucket Server", so I am pretty sure Jenkins is configured correctly). I don't have credentials set up in Jenkins for the Bitbucket Server configuration, is this necessary even though when I test the connection, it seems to be able to connect? Is my url for the BitBucket webhook correct?? Is there anything else you can think of that I might not have configured correctly so when I test the connection on BitBucket, it will connect properly?
I just ran through a similar setup, to answer to your questions:
yes, I think you will have to use credentials of a user having admin permissions on the repository upon which you want to create the webhook.
Read below, anyway the Webhook URL I got is in the form < jenkins-url >/bitbucket-server-webhook/trigger
The pipeline
According to my experience, the creation of the Webhook is demanded to Jenkins, you don't have to do anything on your own other than creating a new Pipeline object.
Having set the Bitbucket Server Integration configuration up in fact is not enough for the creation of the Webhook, to do that you have to
create a new Pipeline
flag the Build Trigger "Bitbucket Server trigger build after push"
in the Pipeline section, use as Definition "Pipeline Script from SCM" and fill the other fields according to the configuration you have set before.
Point 3 is saying you are retrieving your Pipeline definition from a file stored in Bitbucket itself, you can also customise the name of the file Jenkins is going to look for (by default this should be Jenkinsfile), and use the "Pipeline Syntax" option to get the snippet of code you will use as step in your Jenkinsfile.
Once you have created your Pipeline in Jenkins, the webhook should appear in the right section in your Bitbucket Server repository.

Webhook for Jenkins without credentials in URL

I've got a webhook setup in GitLab to detect whenever changes are pushed to the project repo. This works as needed, however the URL in use contains my Jenkins credentials and I'd like to make this more secure. e.g.:
https://username:password#jenkins.url.com/project/git-project
Is there a way to generate a token of sorts in Jenkins instead of providing my username and password?
There are access tokens in GitLab, you can use it. From Jenkins part, you can install GitLab plugin and then add new credentials for SSH and GitLab API Token. Please see this and this for more details.

Resources