credentials_gitlab

Table of Contents

1 GitLab Setup

1.1 Clone the Tutorial Repository on GitLab

To follow this tutorial, you need an account on GitLab. You then need to fork the repository for the code used in this tutorial on your GitHub account. To do so:

1.2 Add buildbot-princeton as a collaborator

You need to add the GitLab user "buildbot-princeton", which is the GitLab id for Jenkins at Princeton, as a collaborator to your fork. Go on the settings (gear symbol in the top right) and select Members. GitLabAddMembers.png

You need to give buildbot-princeton Developers permission.

Your Collaborators and page on GitHub should look like this:

GitLabCollaborator.png

1.3 Generate the ssh public and private keys

Now we are going to give the Jenkins server access to this GitLab repository using an ssh public/private key pair.

  • Create a ssh public/private key pair on any machine that you have access to. On a Linux or Mac machine you can generate those keys with the following command:
    $ ssh-keygen -t rsa -b 4096 -f id_rsa_gitlab -C "punetid@jenkins"
    

    where you should replace punetid with your Princeton University netid. The command line options are:

    • -f specifies the name for the ssh keys, you should pick something meaningful to you.
    • -C option is a comment so you can use what you want.

    You will be asked for a passphrase. You will need this passphrase when you copy the key to the Jenkins server.

  • This command creates two files:
    1. the private key: id_rsa_gitlab
    2. the public key: id_rsa_gitlab.pub

    The private key will be copied on the Jenkins server and the public key will be copied on your GitLab account.

For more help on generating ssh keys, check the GitLab documentation.

1.4 Copy the public key to your GitLab account

Here is a summary:

  • Connect to your GitLab account.
  • Got to your repo (https://gitlab.com/GitLabbID/jenkins_tutorial).
  • Click on the settings button (tmp.png) then Deploy keys (See the figure).
  • Copy the public part (id_rsa_gitlab.pub) of your key. This should look like:
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDIHq5rydARXBMJeUO2ChE//D0p5nWNbBJugCvUmt3Bljf04AkePFiMskGpbn0kZdFkgDhDzjG6ICUGPc6HK-E4jnMrqRPLH6i6ukr3nZ2eV/VNKh6+F2x1u7zbFQQnroDVZ4f8/6LrKo39sY7BpYJZfy+Tk1q+G3EcpC1x8d3SjDQKeyptvdFTxe4BzlkRNVyMplU2hMXtp0/ti1FMSdBw/zTEqgpzjV+UW2QGwJsR9AUMEVKaebb22GVF/0Q90C38qtwRGR6z7Tib8GU78UYpYvuMDlZtLfmVRCIH48mMLon3z0KkbpBmtt9ZIJemYdHj9ldO0o7JscFhn/fhoViDAbRQ3puLCVzBD2Ke6FO9qgHTDPFLAplefAOFc36rCRuRQWlmgf7yvMlTuqmA5sZQCGn//P+NNS23fZya+0kMY3CVGmXNAFoIj5AkxuHG9JuU7P5aNNGtYmqGODkwudcCPbIANLGydn+0sNA+CfyGTEpbD/yTMlAKpCba8kut6Wqz2SjKlWfJW6TCgWRQrYYG2aeOmt4/LFJEf7COF463xbgAv/KCnza61bkIEg7YmeAvV6zvbyxCm6fwdwRkVGiuVEqSYqo+oqqQ+gL+RtxOK89opvpRL5Z/p2m/KJg36WkigmN0H70G2DwD6q0l/S+H9GjJCASkRj7n5vM3U8/qKQ== luet@jenkins
    
  • and paste on your GitLab repository. This should look like this figure.
  • Click Add Key.

SettingDeployKey.png

Figure 3: Menu for setting a deploy ssh key

GitLabDeployKey.png

Figure 4: Adding GitLab deploy key.

1.5 Copy the private key on your Jenkins account

Now we need to copy the private part of the key to your Jenkins account.

  • Connect to https://jenkins.princeton.edu with your Princeton University netid/password. You will see the list of folders assigned to you, in this case there is one folder called tutorial_folder, in your case it will be the folder given to you by the Jenkins administrator.

    JenkinsTutorialFolder.png

  • Click on the folder tutorial_folder
  • Click on Credentials, then Folder on the left-hand sidebar.

JenkinsCredentials_1.png

  • Click on Global credentials (unrestricted)

    JenkinsCredentials_2.png

  • Click on Add Credentials

    JenkinsCredentials_3.png

  • Select:
    • Kind: SSH Username with private key
    • Username: your username on GitLab.
    • Private key: Enter directly. And copy paste the content of the private key file id_rsa_github.
    • Passphrase: Enter the passphrase that you used when generating the ssh key in 1.3.
    • Description: enter something that will make it easy to select the right credentials later. I use jenkins_tutorial deploy.

    The page should look like this:

    JenkinsCredentials_4.png

    • Click Ok.

2 Slave Node Configuration

Now we are going to give Jenkins access to the slave node. The name of the slave node is slave.

The Jenkins system administrator will send you a file containing an ssh public key named id_rsa_slave_punetid.pub that you need to copy on your account on slave. You can do it with the following steps:

  1. copy the ssh public key on slave
    $ scp id_rsa_slave_punetid.pub punetid@slave.princeton.edu:~/.
    
  2. connect onto the slave host
    $ ssh punetid@slave.princeton.edu
    
  3. make sure the directory ~/.ssh exists and that the permissions are correct:
    [punetid@slave] $ mkdir -p ~/.ssh
    [punetid@slave] $ chmod 700 ~/.ssh
    
  4. Append the public key to the file ~/.ssh/authorized_keys and make sure the permissions are correct:
    [punetid@slave] $ cat id_rsa_slave_punetid.pub >> ~/.ssh/authorized_keys
    [punetid@slave] $ chmod 600 ~/.ssh/authorized_keys
    
  5. Create a directory called jenkins in your home directory
    [punetid@slave] $ mkdir ~/jenkins
    

Author: David Luet

Created: 2016-11-23 Wed 16:08

Emacs 24.5.1 (Org mode 8.2.10)

Validate