Jenkins PipelineSshRepo

Generate SSH key pair

Open git-Bash and execute ssh-keygen. Enter the name of the user ({name}) and follow the instruction.

Git Bash SSH Generation

Once the keys are generated, two files are generated in the folder :

  • {name}
  • {name}.pub

Add to Gogs (Or source Control Manager)

Login to Gogs with the user used by Jenkins. Git Bash SSH Generation

On the left Menu, select the SSH entry, then click on the “Add Key” button. Git Bash SSH Generation

Then give a name to the Key, and paste the whole content of the {name}.pub file generated before. Then click on teh Add Key button below. The Key is now associated to the user in Gogs.

Add to Jenkins User

Now, go in Jenkins, go in the “Manage Jenkins” page, navigate to “Credentials”, then click on the “(global)” Domain, then you have the possibility to “Add Credentials” Jenkins user SSH key Creation

In the next page, the first choice, for the “Kind”, should be set to “SSH Username with private Key”. Select the Scope that fits your usage. Fill-in the ID with clear value (like SSH+Username) it will be usefull when we have to select the key at a later stage. Description is a free text placeholder, it should state what this key is used for. Username should have the exact same value as the username used in Gogs (or any another SCM). Then Check the Enter directly option and copy paste the content of the file generated earlier without extension. The “Passphrase” should be the same value as the one given during the key generation. (This is optional during the keygeneration so if you did not set any passphrase, this field can stay empty)

Once all those information are set, click on Save. Jenkins user SSH key Creation part 2 We now have the private key set in Jenkins and the public key in the SCM.

Create a Project to get check the key is working properly