All Products
Search
Document Center

Serverless App Engine:Use an SAE plug-in in Jenkins to build a job for application deployment

Last Updated:Nov 22, 2024

SAE incorporates the sae-jenkins-plugin plug-in in Jenkins. This plug-in allows you to use Jenkins to continuously deploy applications to SAE. This topic describes how to build a deployment job in the Jenkins console and apply the configurations to an application in SAE by using one of the following methods: create a Freestyle project, use the pipeline plug-in, use Maven, and use the Job DSL plug-in.

Prerequisites

Before you begin

Step 1: Install the sae-jenkins-plugin plug-in

  1. Download the sae-jenkins-plugin installation package. The latest version is 1.2.4.

  2. Log on to Jenkins. In the left-side navigation pane of the Jenkins homepage, click Manage Jenkins. In the System Configuration section of the Manage Jenkins page, click Manage Plugins. bt_manage_plugins_in_jenkins

  3. On the Plugin Manager page, click the Advanced tab. In the Deploy Plugin section, follow the on-screen instructions to upload the plug-in installation package that you downloaded in Step1, and then click Deploy.

Step 2: Configure the account information

  1. Log on to Jenkins. In the left-side navigation pane of the Jenkins homepage, click Manage Jenkins. In the System Configuration section of the Manage Jenkins page, click Configure System. bt_configure_system_in_jenkins

  2. In the Deploy to SAE section of the Configure System page, click Add, configure the account information, and then click Ping SAE.

    sc_configurate_sae_credentials_in_jenkins

    Parameter

    Description

    Name

    Specify a name for the AccessKey pair.

    AliCloud Access Key Id

    Enter an AccessKey ID. For more information, see Create an AccessKey pair.

    AliCloud Access Key Secret

    Enter an AccessKey secret. For more information, see Create an AccessKey pair.

    Region

    Click Advanced... to configure this parameter.

    Select the region where you want to deploy the application from the drop-down list. Default value: cn-hangzhou. This parameter is used to test the connectivity to the SAE server in the corresponding region and the validity of the account information. This setting does not affect the deployment operation.

    Endpoint

    Click Advanced... to configure this parameter.

    Default value: sae.aliyuncs.com. In most cases, you do not need to change the value. If the server where Jenkins resides is deployed in a virtual private cloud (VPC) but cannot access the Internet, you must use the endpoint of the VPC where the SAE application resides to ensure the connectivity to SAE. For example, if the VPC endpoint is sae-vpc.cn-hangzhou.aliyuncs.com, you must change cn-hangzhou to the region where the VPC resides.

    If success is displayed, the account information is configured.

  3. Click Save.

Use Jenkins to build an application deployment job

You can quickly build application deployment jobs by using the following methods: Freestyle project, pipeline plug-in, Job DSL plug-in, and Maven plug-in.

Method 1: Use a Freestyle project to build a deployment job

  1. Log on to Jenkins. In the left-side navigation pane of the Jenkins page, click New Item.

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

  3. Click the Post-build Actions tab. On this tab, select Deploy to SAE from the Add post-build action drop-down list. sc_add_deploy_to_sae

  4. In the Deploy to SAE section, select SAE Application from the Add drop-down list. sc_select_SAE_application_from_Application_Setup

  5. In the SAE Application section, configure the parameters.

    In this example, an image is used to deploy an application, as shown in the following figure. The following table describes the parameters. sc_configurate_application_information_via_post_build_action

    Category

    Parameter

    Description

    Basic settings

    SAE Credentials

    Select the name of the specified AccessKey pair from the drop-down list.

    SAE Namespace

    Enter the ID of the namespace to which the application belongs. Format: <RegionId>:<NamespaceId>. Example: cn-hangzhou:test. For information about the regions that are supported by SAE, see Supported regions.

    Application Id

    The ID of the application that you want to deploy.

    Target Object

    The address of the deployment package or image. Supported methods:

    • Deployment package address: You can upload an on-premises or remote deployment package, such as Java JAR package, WAR package, and PHP ZIP package. Examples:

      • On-premises deployment package

        SPRING-CLOUD-CONSUMER.jar

        If the working directory of the project is /var/${jenkins_home}/workspace/test and the full path of the built package is /var/${jenkins_home}/workspace/test/SPRING-CLOUD-CONSUMER.jar, you need to only set the Target Object parameter to SPRING-CLOUD-CONSUMER.jar.

      • Remote deployment package

        http://xx.oss-cn-hangzhou-internal.aliyuncs.com/demo/SPRING-CLOUD-CONSUMER.jar

        If you use a remote deployment package, make sure that the network of the deployed application and the network of the remote file are connected. For example, you can upload a deployment package to Alibaba Cloud Object Storage Service (OSS).

    • Image address: Make sure that the deployed application can pull the specified image. For example, you can specify the address of an image in an Alibaba Cloud image repository. Example:

      registry-vpc.cn-hangzhou.aliyuncs.com/demo/consumer:1.0
    Note

    After you create an application, you must select the same deployment method that you select when you create the application each time you deploy the application.

    Whether target imageUrl

    If you set the Target Object parameter to the address of an image, you must select this parameter.

    Advanced settings

    This section includes multiple settings such as the upgrade strategy, environment variables, and startup command. For example, if you want to upgrade application instances, you can use the canary release or phased release method to upgrade the instances. To upgrade the application, click Update Strategy to configure the parameters. You can click the bt_parameter_tips_for_using_jenkin_to_deploy_application icon next to each parameter to view the corresponding description.

  6. Click Save.

  7. In the left-side navigation pane of the project page, click Build Now to run the job. sc_build_now

    In the Build History section, view the build record. If the bt_build_succeed icon is displayed, the deployment is successful. You can click trend to go to the details page of the build record to view the details. You can also log on to the SAE console. On the Change Records page of the application, view the change record and check whether the Change Status is Executed. For more information, see View change records.

Method 2: Use the pipeline plug-in to create a deployment job

The sae-jenkins-plugin plug-in supports the built-in Snippet Generator of Jenkins Pipeline. This allows you to build a pipeline in Jenkins and deploy an application to SAE.

  1. Log on to Jenkins. On the Jenkins homepage, click New Item.

  2. Enter a project name in the Enter an item name field, select Pipeline, and then click OK.

  3. On the Pipeline tab, click Pipeline Syntax. f_configurate_pipeline syntax

    Note

    If you have created a pipeline, you can click the pipeline name in the project list to go to the pipeline management page. In the left-side navigation pane, click Pipeline Syntax to go to the Snippet Generator page.

  4. On the Snippet Generator page, select saeClient: Deploy into SAE from the Sample Step drop-down list, and then select SAE Application from the Add drop-down list. sc_select_sae_application_via_snippet_generator

  5. In the SAE Application section, configure the parameters.

    sc_configurate_application_information_via_snippet_generator

    In this example, an image is used to deploy an application, as shown in the following figure. The following table describes the parameters. sc_configurate_application_information_via_post_build_action

    Category

    Parameter

    Description

    Basic settings

    SAE Credentials

    Select the name of the specified AccessKey pair from the drop-down list.

    SAE Namespace

    Enter the ID of the namespace to which the application belongs. Format: <RegionId>:<NamespaceId>. Example: cn-hangzhou:test. For information about the regions that are supported by SAE, see Supported regions.

    Application Id

    The ID of the application that you want to deploy.

    Target Object

    The address of the deployment package or image. Supported methods:

    • Deployment package address: You can upload an on-premises or remote deployment package, such as Java JAR package, WAR package, and PHP ZIP package. Examples:

      • On-premises deployment package

        SPRING-CLOUD-CONSUMER.jar

        If the working directory of the project is /var/${jenkins_home}/workspace/test and the full path of the built package is /var/${jenkins_home}/workspace/test/SPRING-CLOUD-CONSUMER.jar, you need to only set the Target Object parameter to SPRING-CLOUD-CONSUMER.jar.

      • Remote deployment package

        http://xx.oss-cn-hangzhou-internal.aliyuncs.com/demo/SPRING-CLOUD-CONSUMER.jar

        If you use a remote deployment package, make sure that the network of the deployed application and the network of the remote file are connected. For example, you can upload a deployment package to Alibaba Cloud Object Storage Service (OSS).

    • Image address: Make sure that the deployed application can pull the specified image. For example, you can specify the address of an image in an Alibaba Cloud image repository. Example:

      registry-vpc.cn-hangzhou.aliyuncs.com/demo/consumer:1.0
    Note

    After you create an application, you must select the same deployment method that you select when you create the application each time you deploy the application.

    Whether target imageUrl

    If you set the Target Object parameter to the address of an image, you must select this parameter.

    Advanced settings

    This section includes multiple settings such as the upgrade strategy, environment variables, and startup command. For example, if you want to upgrade application instances, you can use the canary release or phased release method to upgrade the instances. To upgrade the application, click Update Strategy to configure the parameters. You can click the bt_parameter_tips_for_using_jenkin_to_deploy_application icon next to each parameter to view the corresponding description.

  6. Click Generate Pipeline Script and copy the generated pipeline script.

    bt_generate_pipeline_script

  7. In the left-side navigation pane, click Back to return to the pipeline management page. In the left-side navigation pane, click Configure. Then, enter the script that you copied in the previous step in the Pipeline section.

    In this example, a simple pipeline is configured and only specific parameters are modified, as shown in the following figure. The following table describes the parameters. sc_modify_pipeline_script

    Label No.

    Description

    Select Hello World from the drop-down list on the right side of the Script field.

    Replace the value with deploy to sae.

    Replace the value with the script that is generated in Step6.

  8. Click Save.

  9. In the left-side navigation pane of the project page, click Build Now to run the job. sc_build_now

    In the Build History section, view the build record. If the bt_build_succeed icon is displayed, the deployment is successful. You can click trend to go to the details page of the build record to view the details. You can also log on to the SAE console. On the Change Records page of the application, view the change record and check whether the Change Status is Executed. For more information, see View change records.

Method 3: Use Maven to build a deployment job

After you use a Maven plug-in to build an application, you can use the sae-jenkins-plugin plug-in to deploy the application. Before you use this method, you must install Maven. For more information, see Downloading Apache Maven 3.9.1.

  1. Use a Maven plug-in to build a Java application.

    For more information, see Build a Java app with Maven.

  2. Use the sae-jenkins-plugin plug-in to deploy the Java application.

    1. Log on to Jenkins. On the Jenkins homepage, click the name of an existing project to go to the details page.

    2. In the left-side navigation pane, click Pipeline Syntax.

    3. On the Snippet Generator page, select saeClient: Deploy into SAE from the Sample Step drop-down list, and then select SAE Application from the Add drop-down list.

    4. In the SAE Application section, configure the parameters.

      sc_configurate_application_information_via_snippet_generator_for_maven

      Category

      Parameter

      Description

      Basic settings

      SAE Credentials

      Select the name of the specified AccessKey pair from the drop-down list.

      SAE Namespace

      Enter the ID of the namespace to which the application belongs. Format: <RegionId>:<NamespaceId>. Example: cn-hangzhou:test. For information about the regions that are supported by SAE, see Supported regions.

      Application Id

      The ID of the application that you want to deploy.

      Target Object

      Enter the address of the deployment package. You can upload an on-premises or remote deployment package, such as Java JAR package, WAR package, and PHP ZIP package. Examples:

      • On-premises deployment package

        SPRING-CLOUD-CONSUMER.jar

        If the working directory of the project is /var/${jenkins_home}/workspace/test and the full path of the built package is /var/${jenkins_home}/workspace/test/SPRING-CLOUD-CONSUMER.jar, you need to only set the Target Object parameter to SPRING-CLOUD-CONSUMER.jar.

      • Remote deployment package

        http://xx.oss-cn-hangzhou-internal.aliyuncs.com/demo/SPRING-CLOUD-CONSUMER.jar

        If you use a remote deployment package, make sure that the network of the deployed application and the network of the remote file are connected. For example, you can upload a deployment package to Alibaba Cloud OSS.

      Note

      After you create an application, you must select the same deployment method that you select when you create the application each time you deploy the application.

      Whether target imageUrl

      You do not need to configure this parameter. This parameter must be selected if you set the Target Object parameter to the address of an image.

      Advanced settings

      The advanced settings include the following parameters: Update Strategy, ACR, Application Environment, Startup Command, Storage And Log, and Application Lifecycle Management. Click the required text box to configure the parameters. You can click the bt_parameter_tips_for_using_jenkin_to_deploy_application icon next to each parameter to view the corresponding description.

    5. Click Generate Pipeline Script and copy the generated pipeline script.

      bt_generate_pipeline_script

    6. In the left-side navigation pane, click Back to return to the pipeline management page. In the left-side navigation pane, click Configure. Then, enter the script that you copied in the previous step in the Pipeline section.

      In this example, a simple pipeline is configured and only specific parameters are modified. Select Hello World from the drop-down list on the right side of the Script field and change the original parameter values. sc_modify_pipeline_script

    7. Click Save.

    8. In the left-side navigation pane of the project page, click Build Now to run the job. sc_build_now

    In the Build History section, view the build record. If the bt_build_succeed icon is displayed, the deployment is successful. You can click trend to go to the details page of the build record to view the details. You can also log on to the SAE console. On the Change Records page of the application, view the change record and check whether the Change Status is Executed. For more information, see View change records.

Method 4: Use the Job DSL plug-in to create a deployment job

In Jenkins, you can use the Job DSL plug-in to build a job template and quickly build and deploy jobs based on the template. Before you use this method, you must install the Job DSL plug-in. For more information, see Job DSL.

  1. Log on to Jenkins. On the Jenkins homepage, click New Item.

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

  3. On the Build tab, select Process Job DSLs from the Add build step drop-down list. sc_select_process_job_dsls_from_add_build_step

  4. In the Process Job DSLs section, click Use the provided DSL script. In the DSL Script field, enter the configuration script.

    job('sae') {                                        // The name of the job that you want to build. 
      publishers {                                      // The type of the SAE plug-in. 
        saeClient {                                     // The name of the client that calls the SAE plug-in. 
          deploySAEApplication('', '', '', '', '', ...) // The method that is used to call the application that you want to deploy to SAE. 
        }
      }
    }

    The following deployment methods are supported:

    void deploySAEApplication(
        String namespace,
        String credentialsString,
        String appId,
        String targetObject,
        Boolean image,
        String edasContainerVersion,
        String webContainer,
        String jdk,
        String packageVersion,
        String envs,
        String startupCommand,
        String args,
        Integer minReadyInstances,
        Integer minReadyInstanceRatio,
        Boolean autoEnableApplicationScalingRule,
        Boolean enableGreyTagRoute,
        String acrInstanceId,
        String acrAssumeRoleArn,
        String imagePullSecrets,
        Boolean enableImageAccl,
        String customHostAlias,
        String timezone,
        String configMapMountDesc,
        String jarStartOptions,
        String jarStartArgs,
        String warStartOptions,
        String tomcatConfig,
        String nasId,
        String mountHost,
        String mountDesc,
        String ossMountDesc,
        String ossAkId,
        String ossAkSecret,
        String slsConfigs,
        String kafkaConfigs,
        String postStart,
        String preStop,
        Integer terminationGracePeriodSeconds,
        String readiness,
        String liveness,
        Boolean enableAhas,
        Boolean associateEip,
        String updateStrategy) ;
  5. Click Save.

  6. In the left-side navigation pane of the project page, click Build Now to run the job. sc_build_now

    In the Build History section, view the build record. If the bt_build_succeed icon is displayed, the deployment is successful. You can click trend to go to the details page of the build record to view the details. You can also log on to the SAE console. On the Change Records page of the application, view the change record and check whether the Change Status is Executed. For more information, see View change records.