Webhook for Jenkins without credentials in URL - 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.

Related

setup GitLab SSH key for Jenkins

Having issues creating an ssh credential in Jenkins that allows access to GitLab. I have 2 AWS instances, one with GitLab and one with Jenkins. I would like to setup a multibranch pipeline in Jenkins to run a GitLab repo. I am able to create the pipeline and can access GitLab if I use a username/password credential (using "root"/initial password) but would like to use the more secure route of using a username/SSH credential. I have generated the SSH (of the ed25519 variety) in the GitLab instance (while in root). Then, in GitLab, supplied the public key to the root user. Then, in Jenkins, provided the private SSH key and set username as "root" in a username/SSH credential. When I try to run the pipeline using the username/SSH credential I get an error indicating that it is not authorized. Should I be using a different username? Should I be generating the SSH key in a different location?
Well, I figured it was something small I was missing. I was configuring the pipeline job for the http url of the repo rather than the SSH url. Once I changed that, it worked right away.

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.

Gitlab jenkins integration

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.

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.

Working with jenkins credentials

I want to know how to Create the credentials that can be used by Jenkins and by jobs running in Jenkins to connect to 3rd party services.
You should specify which 3rd party service you will work on.
Below is an example of credentials with bitbucket
I am now working with Jenkins ver. 1.568.
By default, there's Credentials feature. So, if you want to add a credential, just click on Add Credentials. For example, I'd like to add SSH Username with password, so I can use it in checking out code from bitbucket
Credentials plugin - provides a centralized way to define credentials that can be used by your Jenkins instance, plugins and build jobs.
Credentials Binding plugin - allows you to configure your build jobs to inject credentials as environment variables.
The third party plugins need to be installed in your Jenkins instance. For example, Assembla Auth Plugin allows you to authenticate to an Assembla repository.
Which 3rd party services are you working with?
Instead of using SSH Username with private key you can simply use username with password option

Resources