第1章 整合jenkins和阿里云code仓库

1. 整合jenkins和阿里云code仓库

1.1. 为code仓库添加SSH密钥

# 查看服务器公钥
[root@localhost ~]# cat /root/.ssh/id_rsa.pub

# 将服务器公钥添加到阿里云code
阿里云code登录地址: https://code.aliyun.com/
管理控制台 - - 设置 - - SSH公钥 - - 增加SSH密钥

1.2. 为jenkins添加全局凭证

# 查看服务器私钥
[root@localhost ~]# cat /root/.ssh/id_rsa

# 将私钥添加到jenkins全局凭证

2. Code添加webhooks自动触发jenkins

  • 在jenkins的系统设置-全局安全设置中,取消勾选Prevent Cross Site Request Forgery exploits
  • 在jenkins的插件管理中,搜索webhook插件Generic Webhook Trigger Plugin并安装。

2.1. jenkins任务生成token

2.2. 将生成的token添加到Generic Webhook Trigger

(此为一种认证,code根据token将请求发送给jenkins的指定任务)

2.3. 将webhook添加到code上

https://jenkins.xxxxxx.com/generic-webhook-trigger/invoke?token=2cffc099c6c79b5b770092b1951adda7

完成以上操作后,当开发人员提交代码后,code通过webhooks自动触发jenkins指定任务;
Jenkins任务执行可以添加编译\打包\发布等操作,本人偏向于用脚本完成后续打包部署操作;

posted @ 2020-03-16 11:36  黑色利穆  阅读(1903)  评论(0编辑  收藏  举报