1. 程式人生 > 實用技巧 >jenkins:配置 github credentials

jenkins:配置 github credentials

以 GitHub 為例,演示配置 jenkins 不同的 credentials types:

  • Secret Text
  • Username and password
  • SSH Username with private key

Secret Text

GitHub

Secret Text 需要預先在Github 上配置 Personal Token Key

配置 Personal Token Key 的路徑為:【GitHub 使用者影象】-> 【Setttings】-> 【Developer Settings】-> 【Personal access Token】

Note:配置好後重新整理Token會消失,因此要立即儲存

Jenkins

版本:2.249.1

得到 Key 後,在 jenkins 上進行配置:【people】-> 【admin】-> 【Credentials】->【Store from Parent(jenkins)】-> 【System:Global credentials(unrestricted)】->【Add Credentials】

Kind 選擇 Secret Text

Scope 預設 ID 預設

Secret 貼上上一步 GitHub 的 Token Key

  Description:可以填入一些描述,如 GitHub with token


Username and Password

不需要在 github 上進行配置

Jenkins

Jenkins 的配置和上面的 Secret Text 一樣,只是:

Kind 選擇 Username and paasword

Username 填入 Github使用者名稱

Password 填入 Github密碼

Description 填入描述性資訊,如 Github with password

其他預設即可


SSH Username with private key

Linux

生成公鑰和私鑰對

root使用者為:/root/.ssh

非root使用者為:/home/user_name/.ssh

ssh-keygen -t rsa

Jenkins

Jenkins 的配置和上面一樣,選擇 ssh Username with private key

將私鑰貼上到 private key(Enter directly)

GitHub

將公鑰貼上到某個倉庫或者全域性的(settings -> ssh and gpg key)