使用容器结构测试(https://github.com/GoogleContainerTools/container-structure-test)基于四类测试(命令测试、文件存在测试、文件内容测试和元数据测试)验证映像的结构。
语法
# Container Structure Test v0
# Uses container-structure-test (https://github.com/GoogleContainerTools/container-structure-test) to validate the structure of an image based on four categories of tests - command tests, file existence tests, file content tests and metadata tests.
- task: ContainerStructureTest@0
inputs:
# Container Repository
dockerRegistryServiceConnection: # string. Required. Docker registry service connection.
repository: # string. Required. Container repository.
#tag: '$(Build.BuildId)' # string. Tag. Default: $(Build.BuildId).
configFile: # string. Required. Config file path.
#testRunTitle: # string. Test run title.
#failTaskOnFailedTests: false # boolean. Fail task if there are test failures. Default: false.
输入
dockerRegistryServiceConnection
-
Docker 注册表服务连接
string
。 必填。
指定 Docker 注册表服务连接。 需要使用注册表进行身份验证的命令。
repository
-
容器存储库
string
。 必填。
存储库的名称。
tag
-
标记
string
。 默认值:$(Build.BuildId)
。
标记用于从 docker 注册表服务连接拉取映像。
configFile
-
配置文件路径
string
。 必填。
包含容器结构测试的配置文件路径,采用 .yaml 或 .json 文件格式。
testRunTitle
-
测试运行游戏
string
。
指定测试运行的名称。
如果测试失败,failTaskOnFailedTests
- 失败任务
boolean
。 默认值:false
。
如果有任何测试失败,则任务失败。 如果检测到测试失败,请选中此选项以失败任务。
任务控制选项
除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性。
输出变量
没有。
注解
此任务可帮助你运行容器结构测试并将测试结果发布到 Azure Pipelines,并提供全面的测试报告和分析体验。
注释
这是一项早期预览功能。 即将推出的更多功能将在即将推出的冲刺中推出。
容器结构测试提供强大的框架来验证容器映像的结构。 这些测试可用于检查映像中命令的输出,以及验证文件系统的元数据和内容。 测试可以通过独立二进制文件或 Docker 映像运行。
此框架中的测试是通过 YAML 或 JSON 配置文件指定的。 可以在单个测试运行中指定多个配置文件。 配置文件将由测试运行程序加载,它将按顺序执行测试。 在此配置文件中,可以编写四种类型的测试:
- 命令测试(测试发出的特定命令的输出/错误)
- 文件存在测试(确保文件在映像的文件系统中存在或不存在)
- 文件内容测试(确保映像文件系统中的文件包含或不包含特定内容)
- 元数据测试(确保某些容器元数据正确)
生成、测试和发布测试
容器结构测试任务可以添加到经典管道以及统一管道(多阶段)& 基于 YAML 的管道中。
在基于 YAML 的新统一管道中,可以在窗口中搜索任务。
统一管道容器测试
添加任务后,如果需要,需要设置配置文件路径、docker registory 服务连接、容器存储库和标记。 创建基于 yaml 的管道中的任务输入。
在基于 YAML 的管道容器测试
YAML 文件
steps:
- task: ContainerStructureTest@0
displayName: 'Container Structure Test '
inputs:
dockerRegistryServiceConnection: 'Container_dockerHub'
repository: adma/hellodocker
tag: v1
configFile: /home/user/cstfiles/fileexisttest.yaml
查看测试报告
执行任务后,可以直接转到“测试”选项卡查看完整报表。 已发布的测试结果显示在管道摘要中的“测试”选项卡中,并帮助你衡量管道质量、查看可跟踪性、排查故障以及驱动故障所有权。