
To manage credentials, authorization from GitHub for example, or to deploy an application to a supervisor, you need to store a lot of passwords, keys. In Jenkins for this purpose implemented a handy plugin Credentials Plugin
Task:
Install Credentials plugin, generate SSH keys for GitHub. Write the keychains into Jenkins and test the connection.
Used:
Jenikis | Ubuntu | github |
Order of action:
– Installing the plugin on Jenkins
– Generating SSH keys on the server (PRIVATE, PUBLIC)
– Write the keys in the application
– Try to connect
Installing the plugin in Jenkins using the GUI method.
After installation, you must restart Jenkins: your_server:8080/restart
In the menu you will see the installed plugin Credentials.
Now we need to generate SSH keys. Go to the server, in my case Ubuntu.
- ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/mobaxterm/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/mobaxterm/.ssh/id_rsa. Your public key has been saved in /home/mobaxterm/.ssh/id_rsa.pub. The key fingerprint is: SHA256:zn6qZ+ShWjqsmU/cE BS0BFVP The key's randomart image is: +---[RSA 2048]----+ | | |. . | |.. . | |. . o . | |o ....o S E | |.* .+= +o. . | |*oo+o *+o.. | |=B+B.=..+ . | |*+B.*o.+oo | +----[SHA256]-----+ |
Keys generated, 2 pieces, with the extension .pub PUBLIC key and respectively without the extension key PRIVATE.
Setup Jenkins for private GitHub repository.
There is a point here, there are two kinds of repositories on GitHub: public and private, and we will set the keys for the private repository.
You need to copy the PUBLIC (that’s the one with the extension .pub) key from the file on the server and put it on GitHub.
- cat id_rsa.pub |
Next: Settings -> SSH GPG keys -> New SSH key
Insert the copied PUBLIC key and fill inTitle – example: Jenkins
The GitHub part is done, now let’s write the PRIVATE key on the Jenkins server.
Next in plugin Credentials в Jenkins: Global -> Add Credentials
In this example, we are considering an SSH connection with a private key. We fill in the fields.
Kind: Тип Credentials. SSH Username with private key: By using ssh username, keys or passphrase.
Scope: Global/System. Choose Global.
ID: set Id: github-ssh-key
Description: –
Username: name on GitHub
Private Key: In this field, use Add to add the previously generated PRIVATE key.
-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAyPe69uvj97lJEGzif+TteX+U35RJK8KLZ0GTQ2x/FXbQkXp3 r+gLhoLMg+bnhmXRewJeawevQpXh9rWONa+3UVgi2XkIXKeP6jDo8z6hjIkYvRwe 5COmN1ra8w4NvuZ0NofkG5bHvoXRgzcT81gAR7pdxY3awb04A8dQ3cRK0Q/efoja s6Fis2k47BE2R1Y84TMPrewPM8QQGbZ0cbqALofZbjIBj6bTbOVE -----END RSA PRIVATE KEY----- |
You can now add the saved Credentials to projects. Via Credentials -> Add
After using Credential, Jenkins successfully connected to the project on GitHub, as evidenced by the missing red text.