使用此任务快速高效地生成映像并将其部署到 Azure IoT Edge。
此任务支持自定义变量。 如果不熟悉如何在 Pipelines 中使用变量,请参阅 定义变量。
语法
# Azure IoT Edge v2
# Build and deploy an Azure IoT Edge image.
- task: AzureIoTEdge@2
  inputs:
    action: 'Build module images' # 'Build module images' | 'Push module images' | 'Generate deployment manifest' | 'Deploy to IoT Edge devices'. Required. Action. Default: Build module images.
    #deploymentFilePath: '$(System.DefaultWorkingDirectory)/config/deployment.json' # string. Required when action == Deploy to IoT Edge devices. Deployment file. Default: $(System.DefaultWorkingDirectory)/config/deployment.json.
    #azureSubscription: # string. Alias: connectedServiceNameARM. Required when action == Deploy to IoT Edge devices. Azure subscription contains IoT Hub. 
    #iothubname: # string. Required when action == Deploy to IoT Edge devices. IoT Hub name. 
    #deviceOption: # 'Single Device' | 'Multiple Devices'. Required when action == Deploy to IoT Edge devices. Choose single/multiple device. 
    #deviceId: # string. Required when deviceOption == Single Device. IoT Edge device ID. 
    #targetcondition: # string. Required when deviceOption == Multiple Devices. IoT Edge device target condition. 
    #containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Generic Container Registry'. Required when action = Push module images. Container registry type. Default: Azure Container Registry.
    #dockerRegistryConnection: # string. Alias: dockerRegistryEndpoint. Required when containerregistrytype = Generic Container Registry. Docker Registry Connection. 
    #azureSubscriptionEndpoint: # string. Optional. Use when containerregistrytype = Azure Container Registry. Azure subscription. 
    #azureContainerRegistry: # string. Required when containerregistrytype = Azure Container Registry. Azure Container Registry. 
    #templateFilePath: 'deployment.template.json' # string. Required when action = Build module images || action = Push module images || action = Generate deployment manifest. .template.json file. Default: deployment.template.json.
    #defaultPlatform: 'amd64' # 'amd64' | 'windows-amd64' | 'arm32v7' | 'arm64v8'. Required when action = Build module images || action = Push module images || action = Generate deployment manifest. Default platform. Default: amd64.
    #fillRegistryCredential: 'true' # 'true' | 'false'. Required when action = Push module images. Add registry credential to deployment manifest. Default: true.
    #deploymentManifestOutputPath: '$(System.DefaultWorkingDirectory)/config/deployment.json' # string. Required when action == Generate deployment manifest. Output path. Default: $(System.DefaultWorkingDirectory)/config/deployment.json.
    #validateGeneratedDeploymentManifest: 'false' # 'true' | 'false'. Required when action = Generate deployment manifest. Validate the schema of generated deployment manifest. Default: false.
  # Advanced
    #deploymentid: '$(System.TeamProject)-devops-deployment' # string. Required when action = Deploy to IoT Edge devices. IoT Edge deployment ID. Default: $(System.TeamProject)-devops-deployment.
    #priority: '0' # string. Required when action = Deploy to IoT Edge devices. IoT Edge deployment priority. Default: 0.
  # Advanced
    #bypassModules: # string. Optional. Use when action = Push module images. Bypass module(s).
# Azure IoT Edge v2
# Build and deploy an Azure IoT Edge image.
- task: AzureIoTEdge@2
  inputs:
    action: 'Build module images' # 'Build module images' | 'Push module images' | 'Generate deployment manifest' | 'Deploy to IoT Edge devices'. Required. Action. Default: Build module images.
    #deploymentFilePath: '$(System.DefaultWorkingDirectory)/config/deployment.json' # string. Required when action == Deploy to IoT Edge devices. Deployment file. Default: $(System.DefaultWorkingDirectory)/config/deployment.json.
    #azureSubscription: # string. Alias: connectedServiceNameARM. Required when action == Deploy to IoT Edge devices. Azure subscription contains IoT Hub. 
    #iothubname: # string. Required when action == Deploy to IoT Edge devices. IoT Hub name. 
    #deviceOption: # 'Single Device' | 'Multiple Devices'. Required when action == Deploy to IoT Edge devices. Choose single/multiple device. 
    #deviceId: # string. Required when deviceOption == Single Device. IoT Edge device ID. 
    #targetcondition: # string. Required when deviceOption == Multiple Devices. IoT Edge device target condition. 
    #containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Generic Container Registry'. Required when action = Push module images. Container registry type. Default: Azure Container Registry.
    #dockerRegistryConnection: # string. Alias: dockerRegistryEndpoint. Required when containerregistrytype = Generic Container Registry. Docker Registry Connection. 
    #azureSubscriptionEndpoint: # string. Optional. Use when containerregistrytype = Azure Container Registry. Azure subscription. 
    #azureContainerRegistry: # string. Required when containerregistrytype = Azure Container Registry. Azure Container Registry. 
    #templateFilePath: 'deployment.template.json' # string. Required when action = Build module images || action = Push module images || action = Generate deployment manifest. .template.json file. Default: deployment.template.json.
    #defaultPlatform: 'amd64' # 'amd64' | 'windows-amd64' | 'arm32v7'. Required when action = Build module images || action = Push module images || action = Generate deployment manifest. Default platform. Default: amd64.
    #fillRegistryCredential: 'true' # 'true' | 'false'. Required when action = Push module images. Add registry credential to deployment manifest. Default: true.
    #deploymentManifestOutputPath: '$(System.DefaultWorkingDirectory)/config/deployment.json' # string. Required when action == Generate deployment manifest. Output path. Default: $(System.DefaultWorkingDirectory)/config/deployment.json.
    #validateGeneratedDeploymentManifest: 'false' # 'true' | 'false'. Required when action = Generate deployment manifest. Validate the schema of generated deployment manifest. Default: false.
  # Advanced
    #deploymentid: '$(System.TeamProject)-devops-deployment' # string. Required when action = Deploy to IoT Edge devices. IoT Edge deployment ID. Default: $(System.TeamProject)-devops-deployment.
    #priority: '0' # string. Required when action = Deploy to IoT Edge devices. IoT Edge deployment priority. Default: 0.
  # Advanced
    #bypassModules: # string. Optional. Use when action = Push module images. Bypass module(s).
输入
              action
               - 
              操作
              string。 必填。 允许的值:Build module images、Push module images、Generate deployment manifest、Deploy to IoT Edge devices。 默认值:Build module images。
选择 Azure IoT Edge作。
              Build module images 仅生成模块(可用于检查编译错误)。
              Push module images 将模块推送到容器注册表。
              Deploy to IoT Edge devices 将生成的部署文件部署到 IoT 中心。 (建议将 Deploy 任务置于发布管道中。
              deploymentFilePath
               - 
              部署文件
              string。 
              action == Deploy to IoT Edge devices时是必需的。 默认值:$(System.DefaultWorkingDirectory)/config/deployment.json。
选择部署 json 文件。
如果此任务位于 release pipeline中,则需要在项目中设置部署文件的位置。 (默认值适用于大多数条件。如果此任务位于生成管道中,则必须指定部署清单输出路径。
              azureSubscription
               - 
              Azure 订阅包含 IoT 中心
              输入别名: connectedServiceNameARM. 
              string。 
              action == Deploy to IoT Edge devices时是必需的。
选择包含 IoT 中心的 Azure 订阅。
              iothubname
               - 
              IoT 中心名称
              string。 
              action == Deploy to IoT Edge devices时是必需的。
选择 IoT 中心。
              deploymentid
               - 
              IoT Edge 部署 ID
              string。 
              action = Deploy to IoT Edge devices时是必需的。 默认值:$(System.TeamProject)-devops-deployment。
输入 IoT Edge 部署 ID。 如果 ID 已存在,将重写它。
这最多有 128 个小写字母和数字,并且允许以下字符:-:+%_#*?!(),=@;'。
有关详细信息,请参阅 Azure IoT Edge 部署。
              priority
               - 
              IoT Edge 部署优先级
              string。 
              action = Deploy to IoT Edge devices时是必需的。 默认值:0。
将 priority 设置为正整数,以解决部署冲突。  当此任务针对多个部署时,设备将使用优先级最高的部署,或者,如果两个部署具有相同优先级,则使用最新创建时间。
有关详细信息,请参阅 Azure IoT Edge 部署。
              deviceOption
               - 
              选择单个/多个设备
              string。 
              action == Deploy to IoT Edge devices时是必需的。 允许的值:Single Device、Multiple Devices。
根据标记,选择部署到单个或多台设备。
              deviceId
               - 
              IoT Edge 设备 ID
              string。 
              deviceOption == Single Device时是必需的。
输入 IoT Edge device ID。
              targetcondition
               - 
              IoT Edge 设备目标条件
              string。 
              deviceOption == Multiple Devices时是必需的。
输入要部署的设备 target condition。 不要使用双引号。 示例:tags.building=9 和 tags.environment='test'。
有关详细信息,请参阅 Azure IoT Edge 部署。
              containerregistrytype
               - 
              容器注册表类型
              string。 
              action = Push module images时是必需的。 允许的值:Azure Container Registry、Generic Container Registry。 默认值:Azure Container Registry。
选择 Container Registry Type。
              Azure Container Registry 适用于 ACR,Generic Container Registry 用于包括 docker 中心的通用注册表。
              dockerRegistryConnection
               - 
              Docker 注册表连接
              输入别名: dockerRegistryEndpoint. 
              string。 
              containerregistrytype = Generic Container Registry时是必需的。
选择通用 Docker 注册表连接。 这是生成和推送所必需的。
              azureSubscriptionEndpoint
               - 
              Azure 订阅
              string。 可选。 当 containerregistrytype = Azure Container Registry时使用。
选择 Azure 订阅。
              azureContainerRegistry
               - 
              Azure 容器注册表
              string。 
              containerregistrytype = Azure Container Registry时是必需的。
指定 Azure 容器注册表。 此值应以 json 格式指定。
azureContainerRegistry: '{"loginServer": "contoso.azurecr.io"}
              templateFilePath
               - 
              .template.json 文件
              string。 
              action = Build module images || action = Push module images || action = Generate deployment manifest时是必需的。 默认值:deployment.template.json。
Azure IoT Edge 解决方案的路径 .template.json。 此文件定义 Azure IoT Edge 解决方案中的模块和路由。 文件名必须以 .template.json结尾。
              defaultPlatform
               - 
              默认平台
              string。 
              action = Build module images || action = Push module images || action = Generate deployment manifest时是必需的。 允许的值:amd64、windows-amd64、arm32v7、arm64v8。 默认值:amd64。
在 .template.json中,可以将模块平台保留为未指定。 对于这些模块,将使用默认平台。
              defaultPlatform
               - 
              默认平台
              string。 
              action = Build module images || action = Push module images || action = Generate deployment manifest时是必需的。 允许的值:amd64、windows-amd64、arm32v7。 默认值:amd64。
在 .template.json中,可以将模块平台保留为未指定。 对于这些模块,将使用默认平台。
              fillRegistryCredential
               - 
              将注册表凭据添加到部署清单
              string。 
              action = Push module images时是必需的。 允许的值:true、false。 默认值:true。
将用于将 docker 映像推送到部署清单的注册表凭据。
              deploymentManifestOutputPath
               - 
              输出路径
              string。 
              action == Generate deployment manifest时是必需的。 默认值:$(System.DefaultWorkingDirectory)/config/deployment.json。
生成的部署清单的输出路径。
              validateGeneratedDeploymentManifest
               - 
              验证生成的部署清单的架构
              string。 
              action = Generate deployment manifest时是必需的。 允许的值:true、false。 默认值:false。
如果生成的部署清单未通过架构验证,则此步骤失败。 在 Azure IoT Edge deployment 中搜索  以查找最新的架构。
              bypassModules
               - 
              绕过模块
              string。 可选。 当 action = Push module images时使用。
选择不需要在 .template.json中生成或推送的模块名称,并用逗号分隔它们。
示例:如果在 SampleModule1 中有 SampleModule2 和 .template.json,并且只想生成或推送 SampleModule1,则将绕过模块设置为 SampleModule2。 如果要在 .template.json中生成所有模块,请将此保留为空。
任务控制选项
除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性。
输出变量
此任务定义以下 输出变量,可以在下游步骤、作业和阶段中使用。
DEPLOYMENT_FILE_PATH
               这是生成的部署文件的路径。
注解
使用此任务可快速高效地生成、测试和部署应用程序到 Azure IoT Edge。
此任务支持自定义变量。 如果不熟悉如何在 Pipelines 中使用变量,请参阅 定义变量。
例子
生成模块映像
以下 YAML 示例生成模块映像:
- task: AzureIoTEdge@2
  displayName: AzureIoTEdge - Build module images
  inputs:
    action: Build module images
    templateFilePath: deployment.template.json
    defaultPlatform: amd64  
推送模块映像
以下 YAML 示例推送模块映像:
variables:
  azureSubscriptionEndpoint: Contoso
  azureContainerRegistry: contoso.azurecr.io
steps:    
- task: AzureIoTEdge@2
  displayName: AzureIoTEdge - Push module images
  inputs:
    action: Push module images
    containerregistrytype: Azure Container Registry
    azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
    azureContainerRegistry: {"loginServer":"$(azureContainerRegistry)"}
    templateFilePath: deployment.template.json
    defaultPlatform: amd64
    fillRegistryCredential: true
生成部署清单
以下 YAML 示例基于模板文件创建部署清单:
steps:    
- task: AzureIoTEdge@2
  displayName: AzureIoTEdge - Generate deployment manifest
  inputs:
    action: Generate deployment manifest
    templateFilePath: deployment.template.json
    defaultPlatform: amd64
    deploymentManifestOutputPath: $(System.DefaultWorkingDirectory)/config/deployment.json
    validateGeneratedDeploymentManifest: false
部署到 IoT Edge 设备
以下 YAML 示例部署模块映像:
steps:
- task: AzureIoTEdge@2
  displayName: 'Azure IoT Edge - Deploy to IoT Edge devices'
  inputs:
    action: 'Deploy to IoT Edge devices'
    deploymentFilePath: $(System.DefaultWorkingDirectory)/config/deployment.json
    azureSubscription: $(azureSubscriptionEndpoint)
    iothubname: iothubname
    deploymentid: '$(System.TeamProject)-devops-deployment'
    priority: '0'
    deviceOption: 'Single Device'
    deviceId: deviceId
更多示例
有关如何在 Azure Pipelines 中使用这些作的分步示例,请参阅以下文章: