什么是凭证?

Jenkins经常与第三方插件如git,docker等交互,需要提供第三方的凭证,比如access token,用户名和密码等
可以使用插件Credentials Binding Plugin来管理这些凭证

jenkins凭证类型

jenkins可以管理以下凭证
Secret text -------- a token such as an API token (e.g. a GitHub personal access token),
Username and password -------- which could be handled as separate components or as a colon separated string in the format username:password (read more about this in Handling credentials),git使用https方式拉取代码时可以使用用户名和密码这种凭证
Secret file --------- which is essentially secret content in a file,
SSH Username with private key -------- an SSH public/private key pair,
Certificate - --------a PKCS#12 certificate file and optional password, or
Docker Host Certificate Authentication credentials.

下面以gitee为例来说明,jenkins如何使用凭证和第三方插件交互

环境准备

(1)Linux安装git
yum -y install git

(2)jenkins安装git插件

使用username和password凭证来拉取git代码

添加凭证–》输入gitee的用户名和密码,并保存
在这里插入图片描述
创建一个自由风格的项目,repo的URL采用https方式,选择刚创建的用户名和密码这种凭证
在这里插入图片描述
(2)Secret text
Secret text是gitee的私人令牌access token,但是git不支持这种凭证来拉取代码

(3)SSH公钥和私钥
SSH是电脑和gitee建立安全连接,首先要生成账号的公钥和私钥

在Linux终端输入

#以当前登录的Linux用户root来生成私钥和公钥
ssh-keygen -t rsa

生成的私钥和公钥保存在/root/.ssh文件夹中
在这里插入图片描述
将公钥id_rsa复制粘贴到gitee的ssh公钥管理中
在这里插入图片描述
将私钥id_rsa.pub复制到jenkins的凭证中,username是使用的Linux用户生成的key的用户名
在这里插入图片描述
再次创建一个自由风格的项目,使用ssh这种方式来拉取代码
在这里插入图片描述

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐