Use the EDAS plugin in Jenkins to create application deployment tasks

Updated at:

After you integrate the edas-jenkins-plugin into your Jenkins environment, you can use the plugin to continuously deploy applications to Enterprise Distributed Application Service (EDAS). This topic describes how to deploy applications from the Jenkins console, use a pipeline for deployment, and use a Job DSL template to quickly generate deployment tasks.

Prerequisites

The Job DSL plugin is installed.

Install the edas-jenkins-plugin

  1. Download the edas-jenkins-plugin installation package.

  2. Log in to the Jenkins home page. Click Manage Jenkins. On the Manage Jenkins page, click Manage Plugins.

  3. On the Plugin Manager page, select the Advanced tab. In the Upload Plugin section, click Choose File, select the downloaded plugin, and then click Upload.

  4. On the Installing Plugins/Upgrades page, wait for the plugin to install.

Configure account information

  1. Log in to the Jenkins home page. Click Manage Jenkins. On the Manage Jenkins page, click Configure System.

  2. In the Deploy to EDAS section, configure the account information. Click Add and then Advanced to enter the region information.

    Deploy into EDAS

    Parameter

    Description

    EDAS credentials name

    Set a name for the AccessKey.

    EDAS Access Key ID

    Enter the AccessKey ID for your account. For more information, see Create an AccessKey.

    EDAS Access Key Secret

    Enter the AccessKey secret for your account. For more information, see Create an AccessKey.

    EDAS Region

    Enter the region ID where you want to deploy the application, such as cn-hangzhou.

    Endpoint (Apsara Stack)

    Before using Jenkins in Apsara Stack, enter the EDAS Endpoint in this configuration item. Contact EDAS technical support to obtain the Endpoint.

    Note

    You do not need to configure this parameter when using Jenkins in the public cloud.

  3. After you complete the configuration, click Ping EDAS in the Deploy to EDAS section. If the message success is displayed, the account information is correct.

    Note

    Click Add to set up multiple EDAS accounts.

Create a Freestyle project task in Jenkins to deploy an application

  1. Log in to the Jenkins home page and click New Item.

  2. In the Enter an item name field, enter a project name. Select Freestyle project and then click OK.

  3. In the Post-build Actions section, click Add post-build actions and select Deploy to EDAS from the drop-down list.

  4. In the Deploy to EDAS section, click Add and select a cluster for deployment from the drop-down list.

    添加部署任务

    Parameter

    Description

    EDAS ECS Application

    Upgrade and deploy an application that is already deployed in an ECS cluster using the Jenkins plugin. For detailed parameter settings, see Deploy an application in an ECS cluster.

    Create EDAS ECS Application

    Create and deploy an application in an ECS cluster using the Jenkins plugin. For detailed parameter settings, see Create and deploy an application in an ECS cluster.

    EDAS K8s Application

    Upgrade and deploy an application that is already deployed in a Container Service for Kubernetes cluster using the Jenkins plugin. For detailed parameter settings, see Deploy an application in a Container Service for Kubernetes cluster.

    Create EDAS K8s Application

    Create and deploy an application in a Container Service for Kubernetes cluster using the Jenkins plugin. For detailed parameter settings, see Create and deploy an application in a Container Service for Kubernetes cluster.

  5. After you complete the settings, click Save or Apply at the bottom of the page.

  6. On the project task page, click Build Now in the navigation pane on the left to run the task.

    运行构建任务

    You can view build records in the Build History section. Click a build record to view its details.构建详情

Use the Pipeline plugin to deploy an application to EDAS

The edas-jenkins-plugin supports the pipeline snippet generator. You can build a pipeline in Jenkins to deploy applications to EDAS.

  1. Log in to the Jenkins home page and click New Item.

  2. In the Enter an item name field, enter a project name. Select Pipeline and then click OK.

  3. In the Pipeline section, click Pipeline Syntax.

    Note

    If you have an existing pipeline, click its name in the project list to open the pipeline management page. In the navigation pane on the left, click Pipeline Syntax to open the Snippet Generator page.

  4. On the Snippet Generator page, select edasClient: Deploy into EDAS from the Sample Step drop-down list. Next to Application Setup, click Add, and then select a cluster and application deployment type from the drop-down list.

  5. Configure the deployment parameters. For more information, see Parameter settings for deploying applications using the edas-jenkins-plugin in Jenkins.

  6. After you configure the parameters, click Generate Pipeline Script and copy the generated pipeline script.

    Generate Pipeline Script

  7. In the navigation pane on the left, click Back to return to the pipeline management page. In the navigation pane, click Configure. Then, in the Pipeline section, paste the script that you copied, as shown in the following figure.

    Note

    Replace the content in the orange box in the figure with the script that you generated in the previous step.

    pipeline

  8. After you complete the settings, click Save or Apply at the bottom of the page.

  9. On the project task page, click Build Now in the navigation pane on the left to run the task.

    You can view build records in the Build History section. Click a build record to view its details.

Use the Job DSL plugin to create deployment tasks

In Jenkins, you can use the Job DSL plugin to create a task template. This lets you quickly create deployment tasks based on the template.

  1. Log in to the Jenkins home page and click New Item.

  2. In the Enter an item name field, enter a project name. Select Freestyle project and then click OK.

  3. In the Build section, click Add build step, and then select Process Job DSLs from the drop-down list.

    Note

    If you have created a pipeline, click its name in the project list to open the pipeline management page. Then, in the left navigation pane, click Pipeline Syntax to open the Snippet Generator page.

    Process Job DSLs

  4. In the Process Job DSLs section, select Use the provided DSL script and enter your configuration script in the text box.

    job('edas') {    // Name of the target task
      publishers { // Type of the EDAS plugin
        edasClient { // Name used to call the EDAS plugin
          deployApplication('', '', '', '', '') // EDAS method to call
        }
      }
    }

    Supported method examples are as follows:

    // Deploy an application in an ECS cluster
    void deployApplication(
            String namespace,
            String credentialsString,
            String group,
            String appId,
            String targetObject);
    
    void deployApplication(
            String namespace,
            String credentialsString,
            String group,
            String appId,
            String targetObject,
            String versionLabelFormat,
            String versionDescriptionFormat,
            String batch,
            String batchWaitTime,
            String releaseType);
    
    // Create and deploy an application in an ECS cluster
    void insertApplication(
            String namespace,
            String credentialsString,
            String applicationName,
            String packageType,
            String clusterId,
            String targetObject,
            String ecuInfo);
    
    void insertApplication(
            String namespace,
            String credentialsString,
            String applicationName,
            String packageType,
            String clusterId,
            String targetObject,
            String ecuInfo,
            String versionLabelFormat,
            String versionDescriptionFormat,
            String buildPackId,
            String healthCheckUrl);
    
    // Deploy an application in a Container Service for Kubernetes cluster
    void deployK8sApplication(
            String namespace,
            String credentialsString,
            String appId,
            String targetObject,
            Boolean image);
    
    void deployK8sApplication(
            String namespace,
            String credentialsString,
            String appId,
            String targetObject,
            Boolean image,
            String edasContainerVersion,
            String webContainer,
            String jdk,
            String versionLabelFormat,
            String envs,
            String startupCommand,
            String args,
            String cpuLimit,
            String memoryLimit,
            String cpuRequest,
            String memoryRequest,
            String replicas,
            String postStart,
            String preStop,
            String readiness,
            String liveness,
            String updateStrategy);
    
    // Create and deploy an application in a Container Service for Kubernetes cluster
    void insertK8sApplication(
            String namespace,
            String credentialsString,
            String applicationName,
            String packageType,
            String clusterId,
            String targetObject,
            String k8sNamespace,
            String jdk);
    
     void insertK8sApplication(
            String namespace,
            String credentialsString,
            String applicationName,
            String packageType,
            String clusterId,
            String targetObject,
            String k8sNamespace,
            String jdk,
            String descFormat,
            String edasContainerVersion,
            String webContainer,
            String versionLabelFormat,
            String envs,
            String startupCommand,
            String args,
            String cpuLimit,
            String memoryLimit,
            String cpuRequest,
            String memoryRequest,
            String replicas,
            String postStart,
            String preStop,
            String readiness,
            String liveness);
  5. After you complete the settings, click Save or Apply at the bottom of the page.

  6. On the project task page, click Build Now in the navigation pane on the left to run the task.

    You can view build records in the Build History section. Click a record to view its details.

More information

For more information, see Parameter settings for deploying applications using the edas-jenkins-plugin in Jenkins.