Change jenkins pipeline to use github instead of gitlab

You can configure Jenkins instance with Github with the help of SSH key

You Just have to create SSH public and private keys and past public key in

Github > Settings > SSH/GPC key > Add public key Make sure you will not add any space and new line

Save and exit from Github

Now go to Jenkins * Start to configure your project, or Go to credentials > System > Global credentials > Add credentials a page will open

  • In Kind drop-down select SSH Username with private key
  • Check private key radio button and then press Add key button, a textarea will open paste your private key in that textarea, Make sure you copy the private key and while pasting not adding any space in it. Make sure you select the whole key, Begin and End text of key also.

enter image description here

enter image description here

  • Now Save and while Configuring Project Source Code Management tab, you will find credentials and a drop-down, select the new configured key from that dropdown jenkinsSSH.

  • Make sure your clone your Github repo using SSH not HTTPS

enter image description here

and build the application. this will work

for more reference watch this video tutorial https://www.youtube.com/watch?v=mGXGIOpKAos&list=PLhW3qG5bs-L_ZCOA4zNPSoGbnVQ-rp_dG&index=9

[Update]

To clone git repository using Personal Access Token, you can use following format

https://user:[email protected]/org/repo.git like

git clone https://user:[email protected]/org/repo.git

there is one more question same as this, and he provided one solution, might help you

Git Clone in Jenkins with Personal Access Token idles forever

please have a look


After some intense googling I found the answer, which proved to be a lot easier then I thought:

Apparently a personal access token can be used like a password, as far as jenkins is concerned atleast. I added new credentials to the credential manager, chose type 'username and password', put in a non existing username ('user') and put the personal access token in the password field.

This way I could choose the credentials from the dropdown like I did before, and the project was cloned without issues

Tags:

Github

Jenkins