预配云资源

TeamsFx 与 Azure 和 Microsoft 365 云集成,后者允许使用单个命令将应用置于 Azure 中。 TeamsFx 与 Azure 资源管理器 (ARM) 集成,以便预配应用程序代码方法所需的 Azure 资源。

在 Microsoft Visual Studio Code中使用 Microsoft Teams 工具包进行预配

可以在 Teams 工具包或 TeamsFx CLI 中触发预配命令,为应用程序创建或更新资源。 预配命令的步骤在 teamsapp.yml 文件中的 属性下 provision 定义。 可以查看文件以了解创建了哪些资源。

注意

Azure 服务在订阅中产生成本。 有关成本估算的详细信息,请参阅 定价计算器

预配操作

以下列表显示了设计用于预配的操作。

teamsApp/create

它是什么

如果存储 Teams 应用 ID 的环境变量为空或未从 Teams 开发人员门户找到应用 ID,则此操作将创建新的 Teams 应用。

它所操作的资源

Teams 开发人员门户中的 Teams 应用。

如何使用

  - uses: teamsApp/create
    with:
      # #required. Name of Teams app
      name: <your-preferred-app-name>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The id for Teams app
      teamsAppId: <your-preferred-env-var-name>

teamsApp/update

它是什么

将应用清单 (以前称为 Teams 应用清单) 应用到 Teams 开发人员门户中的现有 Teams 应用。 它使用 manifest.json 文件中的应用 ID 来确定要更新的 Teams 应用。

它所操作的资源

Teams 开发人员门户中的 Teams 应用。

如何使用

- uses: teamsApp/update
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/validateManifest

它是什么

此操作使用环境变量呈现应用清单模板,并使用其架构验证应用清单文件。

它所操作的资源

不适用

如何使用

  - uses: teamsApp/validate
    with:
      # Required. Relative path to the yaml file. Path to app manifest file
      manifestPath: <path-to-manifest-file>

teamsApp/validateAppPackage

它是什么

此操作使用验证规则验证 Teams 应用包。

它所操作的资源

不适用

如何使用

  - uses: teamsApp/validateAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/zipAppPackage

它是什么

此操作使用环境变量呈现应用清单模板,并将具有两个图标的应用清单文件压缩为 zip 文件。

它所操作的资源

不适用

如何使用

- uses: teamsApp/zipAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for app manifest file. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml file. This is the path for built zip file.
      outputZipPath: <path-to-generated-zip-file>
      # Required. Relative path to the yaml file. This is the path for built manifest json file.
      outputJsonPath: <path-to-generated-json-file>

teamsApp/publishAppPackage

它是什么

此操作会将生成的 Teams 应用 zip 文件发布到租户应用目录。

它所操作的资源

Microsoft 365 租户应用目录中的 Teams 应用。

如何使用

- uses: teamsApp/publishAppPackage
    with:
      # Required. Relative path to this file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The Teams app id in tenant app catalog.
      publishedAppId: <your-preferred-env-var-name>

aadApp/create

它是什么

如果存储 clientId 的环境变量为空,此操作会创建新的Microsoft Entra应用程序来对用户进行身份验证。

它所操作的资源

Microsoft 365 租户中的Microsoft Entra ID。

如何使用

- uses: aadApp/create
    with:
      # Required. The Microsoft Entra app's display name. When you run aadApp/update, the Microsoft Entra app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in Microsoft Entra app manifest is the same with the name defined here.
      name: <your-application-name>
      # Required. If the value is false, the action will not generate client secret for you
      generateClientSecret: true
      # Required. Specifies what Microsoft accounts are supported for the current application. Supported values are: `AzureADMyOrg`, `AzureADMultipleOrgs`, `AzureADandPersonalMicrosoftAccount`, `PersonalMicrosoftAccount`.
      signInAudience: "AzureADMyOrg"
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # Required. The client (application) ID of Microsoft Entra application. The action will refer the environment variable defined here to determine whether to create a new Microsoft Entra app.
      clientId: <your-preferred-env-var-name>
      # Required when `generateClientSecret` is `true`. The action will refer the environment variable defined here to determine whether to create a new client secret. It's recommended to add `SECRET_` prefix to the environment variable name so it will be stored to the .env.{envName}.user environment file.
      clientSecret: <your-preferred-env-var-name>
      # Required. The object ID of Microsoft Entra application
      objectId: <your-preferred-env-var-name>
      # Optional. The tenant ID of Microsoft Entra tenant
      tenantId: <your-preferred-env-var-name>
      # Optional. The Microsoft Entra authority
      authority: <your-preferred-env-var-name>
      # Optional. The host name of Microsoft Entra authority
      authorityHost: <your-preferred-env-var-name>

aadApp/update

它是什么

此操作基于提供Microsoft Entra应用清单更新Microsoft Entra应用程序。 它引用Microsoft Entra应用清单中的 ID 属性,以确定要更新Microsoft Entra应用。

它所操作的资源

Microsoft 365 租户中的Microsoft Entra ID。

如何使用

- uses: aadApp/update
    with:
      # Required. Relative path to the yaml file. Path to the Microsoft Entra app manifest. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml folder. This action will output the final Microsoft Entra app manifest used to update Microsoft Entra app to this path.
      outputFilePath : <path-to-output-file>

botAadApp/create

它是什么

此操作会为机器人创建新的或重用现有Microsoft Entra应用程序。

它所操作的资源

Microsoft 365 租户中的Microsoft Entra ID。

如何使用

- uses: botAadApp/create
    with:
      # Required. The Microsoft Entra app's display name
      name: <your-app-name>
    writeToEnvironmentFile:
      # The Microsoft Entra app's client id created for bot.
      botId: <your-preferred-env-var-name>
      # The Microsoft Entra app's client secret created for bot. 
      botPassword: <your-preferred-env-var-name>

arm/deploy

它是什么

此操作将并行部署给定的 ARM 模板。

它所操作的资源

Azure 订阅。

如何使用

- uses: arm/deploy
    with:
      # Required. You can use built-in environment variable `AZURE_SUBSCRIPTION_ID` here. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select subscription if it's empty in this case.
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      # Required. You can use built-in environment variable `AZURE_RESOURCE_GROUP_NAME` here. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select or create resource group if it's empty in this case.
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      # Required. The ARM templates to be deployed.
      templates:
        # Required. Relative path to the yaml file.
      - path: <path-to-arm-template>
        # Optional. Relative path to the yaml file. TeamsFx will replace the environment variable reference with real value before deploy ARM template.
        parameters: <path-to-arm-template-parameter>
        # Required. Name of the ARM template deployment.
        deploymentName: <arm-deployment-name>
      # Optional. Teams Toolkit will download this bicep CLI version from github for you, will use bicep CLI in PATH if you remove this config.
      bicepCliVersion: v0.9.1

azureStorage/enableStaticWebsite

它是什么

此操作在 Azure 存储中启用静态网站设置。

它所操作的资源

Azure 存储。

如何使用

- uses: azureStorage/enableStaticWebsite
    with:
      # Required. The resource id of Azure Storage
      storageResourceId: ${{<env-name-of-azure-storage-resource-id>}}
      # Required. The path to index page.
      indexPage: <path-to-index-page>
      # Required. The path to error page.
      errorPage: <path-to-error-page>

azureStaticWebApps/getDeploymentToken

它是什么

此操作从 Azure Static Web Apps 检索部署令牌。

版本信息

v1.4

它所操作的资源

Azure Static Web Apps。

如何使用

- uses: azureStaticWebApps/getDeploymentToken
    with:
      resourceId: ${{AZURE_STATIC_WEB_APPS_RESOURCE_ID}}
    writeToEnvironmentFile:
      deploymentToken: SECRET_TAB_SWA_DEPLOYMENT_TOKEN

脚本

它是什么

此操作执行用户定义的脚本。

它所操作的资源

不适用

如何使用

- uses: script
    with:
     # Required. Command to run or path to the script. Succeeds if exit code is 0. '::set-teamsfx-env key=value' is a special command to generate output variables into .env file, in this case, "mykey=abc" will be added the output in the corresponding .env file.
     run: $my_key="abc"; echo "::set-teamsfx-env mykey=${my_key}"
     # Optional. Available values are: bash, sh, powershell(Powershell Desktop), pwsh(powershell core), cmd. If omitted, it defaults to bash on Linux/MacOS, defaults to pwsh on windows.
     shell: <shell-name>
     # Optional. Current working directory. Defaults to the directory of this file.
     workingDirectory: <working-directory>
     # Optional. Timeout in ms.
     timeout: <timeout-in-ms>
     # Optional. Redirect stdout and stderr to a file.
     redirectTo: <path-to-output-file>

自定义资源预配

预配步骤在 teamsapp.yml 文件中的 属性下 provision 定义。 可以向 属性添加、删除或更新操作 provision ,以定义要在预配期间执行的预期操作。

在参数文件中引用环境变量

Teams 工具包支持引用 、应用清单、Microsoft Entra应用清单和 Azure 参数文件中环境变量teamsapp.yml中的值。 可以使用语法 ${{ENV_VARIABLE_NAME}} 来引用环境变量。

以下示例将环境变量 MY_AZURE_SUBSCRIPTION_ID 的值设置为 subscriptionId

subscriptionId: ${{MY_AZURE_SUBSCRIPTION_ID}}

自定义 ARM 模板文件

如果预定义模板不符合应用要求,则可以创建自己的 ARM 模板或更新现有 ARM 模板,并提供操作路径, arm/deploy 如以下模板所示:

- uses: arm/deploy
    with:
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      templates:
      - path: <path-to-your-arm-template>
        parameters: <path-to-your-parameter-file>
        deploymentName: <arm-deployment-name>
      bicepCliVersion: <bicep-cli-version>

arm/deploy 操作支持以 bicep 和 json 格式编写的 ARM 模板。 如果使用 json 格式,则可以省略 bicepCliVersion 参数。 需要具备 Azure 资源管理器的基础知识。 可以在 Azure 资源管理器 文档中开始使用 Azure 资源管理器

自定义 Teams 应用

可以通过添加环境变量来自定义机器人或 Teams 应用,以使用你创建的Microsoft Entra应用。 执行以下方法来自定义 Teams 应用:

将现有Microsoft Entra应用用于 Teams 应用

可以按照步骤将环境变量添加到 .env 文件,以使用为 Teams 应用创建的Microsoft Entra应用。 如果你还没有Microsoft Entra应用,或者已经有一个应用,但不知道在哪里可以找到正确的值,请参阅如何在 TeamsFx 项目中使用现有的 Microsoft Entra 应用

  1. 打开 teamsapp.yml 并查找操作 aadApp/create

  2. 在 属性中writeToEnvironmentFile查找存储Microsoft Entra应用的信息的环境变量名称。 如果使用 Teams 工具包创建项目,则默认 writeToenvironmentFile 定义如下:

     writeToEnvironmentFile:
      clientId: AAD_APP_CLIENT_ID
      clientSecret: SECRET_AAD_APP_CLIENT_SECRET
      objectId: AAD_APP_OBJECT_ID
      tenantId: AAD_APP_TENANT_ID
      authority: AAD_APP_OAUTH_AUTHORITY
      authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST
    
  3. 为步骤 2 中的每个环境变量添加值。

    1. 将以下环境变量及其值添加到 env\.env.{env} 文件中。

       AAD_APP_CLIENT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OBJECT_ID=<value of Microsoft Entra application's object id> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_TENANT_ID=<value of Microsoft Entra's tenant id>> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OAUTH_AUTHORITY=<value of Microsoft Entra's authority> # example: https://login.microsoftonline.com/<Directory (tenant) ID>
       AAD_APP_OAUTH_AUTHORITY_HOST=<host of Microsoft Entra's authority> # example: https://login.microsoftonline.com
       AAD_APP_ACCESS_AS_USER_PERMISSION_ID=<id of access_as_user permission> # example: 00000000-0000-0000-0000-000000000000
      
    2. 如果应用程序需要Microsoft Entra应用客户端密码,请将以下环境变量及其值添加到env\.env.{env}.user文件中。

      SECRET_AAD_APP_CLIENT_SECRET=<value of Microsoft Entra application's client secret>
      

注意

  • 如果在 中使用不同的名称,请记住更新示例中的环境变量名称 writeToEnvironmentFile
  • 如果不使用aadApp/create操作创建Microsoft Entra应用程序,则可以使用首选名称添加必要的环境变量,而无需执行上述步骤。
  • 确保不要在多个环境中共享相同的Microsoft Entra应用。

为机器人使用现有Microsoft Entra应用

可以按照步骤将环境变量添加到 .env 文件,以使用为 Teams 应用创建的Microsoft Entra应用。 如果还没有适用于机器人的Microsoft Entra应用,或者已有一个应用,但不知道在何处查找正确的值,请参阅在 TeamsFx 项目中使用现有Microsoft Entra应用

  1. 打开 teamsapp.yml 并查找操作 botAadApp/create

  2. 在 属性中writeToEnvironmentFile查找存储Microsoft Entra应用的信息的环境变量名称。 如果使用 Teams 工具包创建项目,则默认 writeToEnvironmentFile 定义如下:

     writeToEnvironmentFile:
       botId: BOT_ID
       botPassword: SECRET_BOT_PASSWORD
    
  3. 为步骤 2 中的每个环境变量添加值。

    1. 将以下环境变量及其值添加到 env\.env.{env} 文件中。

      BOT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000    
      
    2. 将以下环境变量及其值添加到 env\.env.{env}.user 文件中。

      SECRET_BOT_PASSWORD=<value of Microsoft Entra application's client secret>
      

注意

  • 如果在 中使用不同的名称,请记住更新示例中的环境变量名称 writeToEnvironmentFile
  • 如果不使用botAadApp/create操作创建Microsoft Entra应用程序,则可以使用首选名称添加必要的环境变量,而无需执行上述步骤。
  • 确保不要在多个环境中共享相同的Microsoft Entra应用。

另请参阅

将 Teams 应用部署到云