All Products
Search
Document Center

EventBridge:Use an API destination to integrate Jenkins with EventBridge

Last Updated:Nov 01, 2024

This topic describes how to use an API destination to integrate Jenkins with EventBridge.

Background information

An API destination allows you to call the API operations of a third-party Software as a Service (SaaS) system or a self-managed system that is connected over HTTP in a low-code way and without extra architectures. You can use API destinations to easily build and connect to SaaS applications. This helps prevent data silos. In addition, a connection can be shared among multiple API operations to provide convenient and pluggable authentication capabilities.

An API operation in a third-party SaaS system or a self-managed system includes an API destination and a connection.

An API destination defines the metadata of an API operation. When you create an event rule, you can reference different API destinations to access different third-party SaaS systems or self-managed systems. You can also reference the same API destination for different event rules. Assume that you deliver events to an API operation of a service by using multiple event rules, and you want to change a specific parameter in the event rules. If an API destination is not defined, you must change the specific parameter in all event rules one by one. However, if an API destination is defined, you need to modify only the configurations of the API destination, and the specific parameter is automatically updated in all event rules that reference the API destination.

A connection is used to connect a third-party SaaS system or a self-managed system with the current API destination. The configurations of a connection consist of network configurations and authentication configurations. A network configuration specifies whether a third-party SaaS system or a self-managed system connects to the current API destination over the Internet or over a private network. In EventBridge, you can select one of the following authentication methods: basic authentication, OAuth authentication, and API key.

  • Basic authentication: Your username and password must be verified before you access data resources. The username and password are Base64-encoded and are prefixed with Basic and a space before they are sent to the destination service. If the username and password are decoded and pass the verification, the server responds to the request from EventBridge. Otherwise, the request is sent back.

  • OAuth authentication: This authentication method is secure and reliable. OAuth authentication allows you to authorize a third-party application by using an authorization code, an implicit authorization code, a password, or a client credential. In event-driven scenarios, client credentials are commonly used. If you use a client credential to authorize a third-party application, you must configure the information that is required to obtain a client credential in EventBridge, including the IP address of the OAuth service, client ID, and client password. EventBridge allows you to obtain a client credential by using the GET or POST method.

  • API key: This authentication method is relatively easy. Users can use a custom key name and key value to call an API operation. EventBridge sends the key name and key value to the server for authentication by using an HTTP header.

API destination

Jenkins is a Java-based tool for continuous integration. You can use Jenkins to build and test software projects in a continuous and automatic manner, and monitor the status of external tasks. The following sections use Jenkins as an example to describe how to use an API destination to integrate other applications with EventBridge.

Prerequisites

Step 1: Add an API token

  1. Log on to Jenkins and click your account in the upper right corner of the home page.

  2. In the left-side navigation pane, click Configure. Then, click Add new Token in the API Token section.

    Add new Token

  3. Enter a token name in the field and click Generate.

    A password string is automatically generated by Jenkins. Click the Copy icon to copy the password string. Then, save the password string. Copy a password

Step 2: Create a connection

  1. Log on to the EventBridge console. In the left-side navigation pane, choose Integration Center > API Destination.

  2. In the top navigation bar, select the region where you want to configure the connection. Then, click the Connection Configuration tab.

  3. On the Connection Configuration tab, click Create. In the Create Connection panel, configure the following parameters and click OK.

    • Name: the name of the connection.

    • Description: the description of the connection.

    • Authentication: Select Basic. Then, set the Username parameter to the username of the Jenkins account and the Password parameter to the password string that you save in Step 1.

    • Network: Internet is selected by default.

Step 3: Create an API destination

  1. After you create a connection, click the API Destination tab. Then, click Create.

  2. In the Create Connection panel, configure the following parameters and click OK.

    1. In the Basic Information section, set the Method parameter to Custom. Then, specify the name and description of the API destination.

    2. In the API Configuration section, set the URL parameter to the API URL of Jenkins. In this example, http://XX.XX.XX.XX:8080/job/test/build is used to call the Jenkins project. Then, set the HTTP Method parameter to POST.

    3. In the Connection Configuration section, click Select Existing Connection and select the connection that you created in step 2.

Step 4: Create a custom event bus

  1. In the left-side navigation pane, click Event Buses. On the page that appears, click Create in the Custom Event Buses section.

  2. In the Create Custom Event Bus panel, configure the following parameters and click Create.

    1. In the Event Bus step, configure the Name and Description parameters. Then, click Next Step.

    2. In the Event Source step, configure the Event Source Name and Description parameters, set the Event Provider parameter to Custom Application, and then click Next Step.

    3. In the Event Rule step, configure the Event Rule Name and Description parameters. Then, click Next Step.

    4. In the Event Target step, configure the following parameters:

      • Service Type: Select Triggered by API operation.

      • Method: Select Use Existing Item.

      • HTTP Parameter: Specify the parameter that is passed when the event is pushed to Jenkins and the content of the parameter.

Step 5: Publish an event

  1. On the Event Buses page, find the custom event bus that you created in step 4 and click Publish Event in the Actions column.

  2. In the Publish Event to Custom Event Bus panel, select the custom event source that you created from the Custom Event Source drop-down list and click OK.

Verify an event

  1. Go back to the home page of Jenkins and click the project that is defined by the URL that you configured when you created the API destination.

  2. In the Build History section, click the most recent build history.

    View the build history

  3. In the left-side navigation pane, click Console Output to view log details.

    View log details

    You can see that Jenkins has received the event that is published by EventBridge and started the build project.