This topic describes how to use the command-line interface (CLI) of Web App Service (Web+) to deploy an ASP.NET Core application in Jenkins.

Background information

This topic uses the eShopOnWeb sample application of ASP.NET Core. This sample application demonstrates several principles and running modes of e-books.

Prerequisites

Step 1: Prepare the environment

  1. Install Git.
    1. Log on to the Elastic Compute Service (ECS) instance where Jenkins runs as the root user. Run the following command to install Git:
      yum install -y git
      Note Unless otherwise specified, run all commands on the ECS instance where Jenkins runs as the root user.
    2. After Git is installed, run the following command:
      which git
      Record the command output.
  2. Run the following commands to install the SDK for .NET:
    sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
    sudo yum install -y dotnet-sdk-3.1
  3. Run the following command to install the Entity Framework Core CLI:
    dotnet tool install --global dotnet-ef
    After the installation is complete, exit the current session as prompted and log on again.
  4. Run the following command to install the Web+ CLI:
    eval "$(curl -s -L https://webplus-cn-shenzhen.oss-cn-shenzhen.aliyuncs.com/cli/install.sh)"
  5. Configure the Web+ CLI.
    1. Log on to the ECS instance where Jenkins runs as the root user. Run the following command to switch to the admin user:
      su - admin
    2. Run the following command to configure the Web + CLI:
      wpctl configure --access-key-id <ACCESS_KEY_ID> --access-key-secret <ACCESS_KEY_SECRET> --region <REGION> --profile webplus
      Note
      • For more information about how to obtain the values of the ACCESS_KEY_ID and ACCESS_KEY_SECRET parameters, see Create an AccessKey.
      • The REGION parameter indicates the region where you deploy applications in Web+. For more information about regions supported by Web+, see Supported regions.

Step 2: Use Jenkins to deploy an ASP.NET Core application

  1. Log on to Jenkins.
  2. In the left-side navigation pane of the Jenkins page, click Manage Jenkins. On the Manage Jenkins page, click Global Tool Configuration.
  3. In the Git section, enter the output of the which git command in the Path to Git executable field. Then click Apply.
  4. In the left-side navigation pane of the Jenkins page, click New Item to create a task.
  5. Enter a task name in the Enter an item name field, select Pipeline, and then click OK.
  6. Click the Pipeline tab.
  7. Enter the following command script on the Pipeline tab and click Save:
    pipeline {
        agent any
    
        stages {
            stage('Prepare') {
                steps {
                    // Clean Jenkins workspace.
                    cleanWs()
                    // Clone eShopOnWeb repository.
                    git 'https://github.com/dotnet-architecture/eShopOnWeb'
                }
            }
    
            stage('Build') {
                steps {
                    // Build this project.
                    sh 'dotnet restore src/Web/Web.csproj'
                    sh 'dotnet tool restore --configfile src/Web/.config/dotnet-tool.json'
                    sh 'dotnet publish src/Web/Web.csproj -c Release -o out -r linux-x64 --self-contained'
                    // Tell Web+ how to start this application.
                    sh 'echo "Web: ASPNETCORE_ENVIRONMENT=Development . /Web" > out/Procfile'
                    // Package this project.
                    sh 'cd out && zip -qr webplus-dotnet-demo.zip .'
                }
            }
    
            stage('Deploy') {
                steps {
                    sh 'wpctl env:apply -y --package out/webplus-dotnet-demo.zip --category "ASP.NET Core" --app webplus-dotnet-demo --env test-env --create-on-absent'
                }
            }
        }
    }
  8. In the left-side navigation pane, click Build Now to start the pipeline.
  9. After the pipeline is deployed, access the deployed application.
    1. Log on to the Web+ console and select the target region in the upper-left corner of the page.
    2. On the Applications and Deployment Environments page, click the plus sign + on the left side of the target application to show the list of deployment environments.
    3. Click the ID of the target deployment environment to go to the Overview page. Click the URL on the right side of Public Address to access the deployed application.