Tuesday, November 22, 2016

GitLab and Jenkins Integration using SSH Keys

Setting up SSH Keys to connect GitLab and Jenkins

Follow the below Steps: 
1) Generate Public Key & Private Key(SSH Keys) of the user.
       Command : ssh-keygen -t rsa -C "your_email@example.com",
       Just press <Enter> to accept the default location and file name. ..
       Enter, and re-enter, a passphrase when prompted. or Just Press Enter to leave 
       it as blank

      There are other ways too to generate SSH Keys.

2) GitLab : (GitLab is installed on On-Premise Server in my case)
      Login to gitlab server with your user ID.
      Click on "profile settings" on the left bottom & "SSH Keys" on right top corner.


Copy User Public Key(id_rsa.pub) to GitLab : SSH Keys of the 
     Specific User or Service Account ID.

3) Jenkins:
    Copy User Private Key(id_rsa) & add it to Jenkins : 
     Credentials -> System -> Global Credentials -> Add Credentials.
     Select Kind : SSH Username with private key & provide username.
     & Enter directly section : Copy and paste the Private key or use other options.
      & Leave passphrase & ID as blank.
     & Provide a name description as "UserName_PrivateKey", 
     so you can select that during the job configuration drop down.

4) In the Jenkins Job Configuration @ GIT Section 
Provide the GitLab Repo URL : SSH option URL
           Ex : git@server:locationoftheRepo.git
& Select "UserName_PrivateKey" from Dropdown, 

This will authenticate the User with GitLab using SSH Keys & 
we will be able to connect Jenkins to GitLab successfully.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.