适用于 Azure Spring Cloud 的 CI/CDCI/CD for Azure Spring Cloud

通过持续集成和持续交付工具,你可以快速地将更新部署到现有应用程序,工作量较少且风险较低。Continuous integration and continuous delivery tools let you quickly deploy updates to existing applications with minimal effort and risk. Azure DevOps 可帮助你组织和控制这些关键作业。Azure DevOps helps you organize and control these key jobs. 目前,Azure Spring Cloud 不提供特定的 Azure DevOps 插件。Currently, Azure Spring Cloud does not offer a specific Azure DevOps plugin. 但是,可以使用 Azure CLI 任务将 Spring Cloud 应用程序与 DevOps 集成。However, you can integrate your Spring Cloud applications with DevOps using an Azure CLI task.

本文介绍如何将 Azure CLI 任务与 Azure Spring Cloud 结合使用以便与 Azure DevOps 集成。This article shows you how to use an Azure CLI task with Azure Spring Cloud to integrate with Azure DevOps.

创建 Azure 资源管理器服务连接Create an Azure Resource Manager service connection

阅读本文,了解如何将 Azure 资源管理器服务连接创建到 Azure DevOps 项目。Read this article to learn how to create an Azure Resource Manager service connection to your Azure DevOps project. 请确保选择用于 Azure Spring Cloud 服务实例的同一订阅。Be sure to select the same subscription you are using for your Azure Spring Cloud service instance.

Azure CLI 任务模板Azure CLI task templates

部署项目Deploy artifacts

你可以使用一系列 tasks 来构建和部署项目。You can build and deploy your projects using a series of tasks. 此代码片段首先定义生成应用程序的 Maven 任务,接下来定义使用 Azure Spring Cloud Azure CLI 扩展部署 JAR 文件的第二个任务。This snippet first defines a Maven task to build the application, followed by a second task that deploys the JAR file using the Azure Spring Cloud Azure CLI extension.

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
- task: AzureCLI@1
  inputs:
    azureSubscription: <your service connection name>
    scriptLocation: inlineScript
    inlineScript: |
      az extension add -y --name spring-cloud
      az spring-cloud app deploy --resource-group <your-resource-group> --service <your-spring-cloud-service> --name <app-name> --jar-path ./target/your-result-jar.jar
      # deploy other app

从源进行部署Deploy from source

无需单独的生成步骤便可直接部署到 Azure。It is possible to deploy directly to Azure without a separate build step.

- task: AzureCLI@1
  inputs:
    azureSubscription: <your service connection name>
    scriptLocation: inlineScript
    inlineScript: |
      az extension add -y --name spring-cloud
      az spring-cloud app deploy --resource-group <your-resource-group> --service <your-spring-cloud-service> --name <app-name>

      # or if it is a multi-module project
      az spring-cloud app deploy --resource-group <your-resource-group> --service <your-spring-cloud-service> --name <app-name> --target-module relative/path/to/module

后续步骤Next steps