本文介绍如何使用Codeup代码库关联Jenkins进行持续集成。主要涉及内容包括关联代码源、配置触发器的过程。
Jenkins插件安装
插件管理
单击①处系统管理,接着点击②处插件管理:

Git 源码管理
在③处可选插件中输入“Git plugin”找到代码源管理的插件并安装:

WebHook插件
同理,在可选插件中搜索 “Generic Webhook Trigger Plugin”,并安装:

安装后需重启Jenkins。
Jenkins 代码源配置
步骤一:新建 Jenkins 任务
首先,新建期望的 Jenkins 任务,然后准备配置代码源。
步骤二:进入任务配置页面
 选择:
选择:

步骤三:源码管理配置
选择Git,填入Codeup仓库地址,例如:https://codeup.aliyun.com/xxxx/Codeup-Demo.git
此时需要填写认证信息:
 选择Credentials,如果没有,需要新建:
选择Credentials,如果没有,需要新建:

这里需要填写的用户名和密码,即Codeup代码仓库的克隆用户名和密码。获取位置如下图所示:

配置完成后如页面不再报错,则鉴权通过。
步骤四:配置触发器
继续在设置页中找到构建触发器:
 选择Generic Webhook Trigger:
选择Generic Webhook Trigger:

配置获取Codeup Webhook的请求参数:

参数说明:
以Codeup Push事件为例,push webhook请求body如下。
如上在Variable中填ref,表示获取post请求body中ref字段,Expression中填$.ref表示获取body中ref的value值。
{
  "after": "f9e10a78d6ddd897e522aac418c60c742250cxxx",
  "before": "b509e74e75a56026b6650c7d902474d1eaa7bxxx",
  "checkout_sha": "f9e10a78d6ddd897e522aac418c60c742250cxxx",
  "commits": [
    {
      "author": {
        "email": "test@example.net",
        "name": "test"
      },
      "id": "f9e10a78d6ddd897e522aac418c60c742250cxxx",
      "message": "init\n",
      "timestamp": "2021-08-31T18:03:33.000Z",
      "url": "https://codeup.aliyun.com/612a21eaadb2703b38cd6xxx/Codeup-Demo/commit/f9e10a78d6ddd897e522aac418c60c742250cxxx"
    }
  ],
  "object_kind": "push",
  "project_id": 1179553,
  "ref": "refs/heads/master",
  "repository": {
    "description": "进入示例代码库快速了解云效 Codeup 功能",
    "git_http_url": "https://codeup.aliyun.com/612a21eaadb2703b38cd6xxx/Codeup-Demo.git",
    "git_ssh_url": "gi*@codeup.aliyun.com:612a21eaadb2703b38cd6xxx/Codeup-Demo.git",
    "homepage": "https://codeup.aliyun.com/612a21eaadb2703b38cd6xxx/Codeup-Demo",
    "name": "Codeup-Demo",
    "url": "git@codeup.aliyun.com:612a21eaadb2703b38cd6xxx/Codeup-Demo.git",
    "visibility_level": 10
  },
  "total_commits_count": 1,
  "user_email": "test@example.net",
  "user_extern_uid": "5f969843cd2214ba0e243xxx",
  "user_id": 96867,
  "user_name": "test"
}步骤五:配置Token值

这里Token项可选,支持用户自定义,用于接收方验证请求合法性,需要在Codeup的Webhook里按照以下格式设置触发的 URL :http://jenkins地址/generic-webhook-trigger/invoke?token=(上述生成的token)。
如果此处不使用Token的形式,触发的URL需要如下格式设置 ,否则无法验证身份:http://user:passsword@jenkins/generic-webhook...。
步骤六:配置构建脚本
根据您的持续集成需求,配置对应Jenkins脚本。
步骤七:保存
保存设置:

Codeup侧配置Webhook
步骤一:配置webhook
进入目标代码库,选择,进行新建webhook:

步骤二:创建Webhook
填入上方Jenkins提供的Hook URL + 自定义的Token。
URL设置:http://jenkins地址/generic-webhook-trigger/invoke?token=(上方步骤五中设置的 token值:XXXXXXX)

注意:此方式暂不支持Secret Token字段。