Uredi

Deli z drugimi prek


ContainerStructureTest@0 - Container Structure Test v0 task

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.

Syntax

# 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.

Inputs

dockerRegistryServiceConnection - Docker registry service connection
string. Required.

Specify a Docker registry service connection. Required for commands that need to authenticate with a registry.


repository - Container repository
string. Required.

The name of the repository.


tag - Tag
string. Default value: $(Build.BuildId).

The tag is used in pulling the image from docker registry service connection.


configFile - Config file path
string. Required.

The config file path that contains container structure tests, either in .yaml or .json file formats.


testRunTitle - Test run title
string.

Specify a name for the Test Run.


failTaskOnFailedTests - Fail task if there are test failures
boolean. Default value: false.

Fails the task if there are any test failures. Check this option to fail the task if test failures are detected.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

This task helps you run container structure tests and publish test results to Azure Pipelines and provides a comprehensive test reporting and analytics experience.

Note

This is an early preview feature. More upcoming features will be rolled out in upcoming sprints.

The Container Structure Tests provide a powerful framework to validate the structure of a container image. These tests can be used to check the output of commands in an image, as well as verify metadata and contents of the filesystem. Tests can be run either through a standalone binary, or through a Docker image.

Tests within this framework are specified through a YAML or JSON config file. Multiple config files may be specified in a single test run. The config file will be loaded in by the test runner, which will execute the tests in order. Within this config file, four types of tests can be written:

  • Command Tests (testing output/error of a specific command issued)
  • File Existence Tests (making sure a file is, or isn't, present in the file system of the image)
  • File Content Tests (making sure files in the file system of the image contain, or do not contain, specific contents)
  • Metadata Test, singular (making sure certain container metadata is correct)

Build, Test and Publish Test

The container structure test task can be added in the classic pipeline as well as in unified pipeline (multi-stage) & YAML based pipelines.

In the new YAML based unified pipeline, you can search for task in the window.

Container Test in Unified Pipeline

Once the task is added, you need to set the config file path, docker registory service connection, container repository and tag, if required. Task input in the yaml based pipeline is created.

Container Test in YAML based Pipeline

YAML file

YAML file

steps:
- task: ContainerStructureTest@0
  displayName: 'Container Structure Test '
  inputs:
    dockerRegistryServiceConnection: 'Container_dockerHub'
    repository: adma/hellodocker
    tag: v1
    configFile: /home/user/cstfiles/fileexisttest.yaml

View test report

Once the task is executed, you can directly go to test tab to view the full report. The published test results are displayed in the Tests tab in the pipeline summary and help you to measure pipeline quality, review traceability, troubleshoot failures, and drive failure ownership.

Test Reporting Page

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 2.144.0 or greater
Task category Test
Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 2.0.0 or greater
Task category Test