Integrate Jenkins for continuous integration

Updated at:

This topic describes how to connect a Codeup code repository to Jenkins for continuous integration by linking a code source and configuring build triggers.

Install Jenkins plugins

Manage Plugins

Click Manage Jenkins, then Manage Plugins.

Git source code management

On the Available tab, search for and install the Git plugin.

Webhook plugin

Similarly, search for and install the Generic Webhook Trigger Plugin.

After installation, restart Jenkins.

Configure Jenkins code source

Step 1: Create a Jenkins job

First, create a new Jenkins job.

Step 2: Access job configuration

In the left-side navigation pane of the Jenkins job page, click Configure. Under Source Code Management > Git.

In the Repository URL field, enter the HTTPS clone URL of your Codeup repository. In the Branches to build field, specify the target branch. The default is */master.

Step 3: Configure Source Code Management

Select Git and enter your Codeup repository URL, such as https://codeup.aliyun.com/xxxx/Codeup-Demo.git.

At this point, you need to provide authentication information.

If a red authentication error appears, you need to configure credentials. To create a new one, click Add next to the Credentials dropdown menu.

In the Add Credentials dialog box, set Kind to Username with password and Scope to Global. Fill in the required fields, then click Add.

Use the clone credentials for your Codeup code repository.

On your Codeup code repository page, click Clone/Download in the upper-right corner. On the HTTPS tab, click the View Now link to get your clone username and password.

If the error disappears, authentication succeeds.

Step 4: Configure the build trigger

On the same configuration page, find the Build Triggers section.

Select Generic Webhook Trigger.

Configure request parameters to extract data from the Codeup Webhook payload.

Parameter description

For example, the request body for a Codeup push event is as follows.

To extract the value of the ref key from the request body, enter ref as the Variable and $.ref as the JSONPath Expression. This makes the branch name available as a build variable.

{
  "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": "Learn Alibaba Cloud DevOps Codeup features quickly with this sample repository",
    "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"
}

Step 5: Configure the token

In the Token section, enter a token value.

This token is optional. You can define a custom token for Jenkins to verify incoming requests. If you use a token, you must set the Webhook URL in Codeup to the following format: http:///generic-webhook-trigger/invoke?token=.

If you do not use a token, you must include credentials in the URL to authenticate the request: http://:@/generic-webhook-trigger/invoke.

Step 6: Configure the build script

Configure the Jenkins build script according to your continuous integration requirements.

Step 7: Save

Save the settings:

Click Save at the bottom of the page.

Configure Codeup Webhooks

Step 1: Access Webhook settings

Go to your target code repository. In the navigation pane, click Settings > Webhooks.

In the upper-right corner of the page, click New Webhook.

Step 2: Create the Webhook

Enter the URL from Jenkins, including your custom token.

URL format: http:///generic-webhook-trigger/invoke?token=

Under Trigger, select the events that trigger a build, such as Push events. Then, click OK to create the Webhook.

Important

Note: This method does not support the Secret Token field.