When the entire pipeline is running on vmImage, is it possible to run one of the stages (Test) in Container?
In Azure Devops Yaml Pipeline, you could specify the container
at the job level.
Then the job could run on the target container.
Here is a doc about the detailed information.
How to copy build artifacts from vmImage to run tests in Container?
In the previous stage, you could publish the build artifacts with the Publish Build Artifacts task
.
In the stage (running job in the container), you could use the Download Build Artifacts
task to download the artifacts to the container.
Finally, you could add the steps to test it.
Here is my sample:
resources:
containers:
- container: python
image: python:3.8
trigger:
- none
stages:
- stage: artifacts
pool:
vmimage: ubuntu-latest
jobs:
- job: test123
steps:
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.Sourcesdirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- script: echo $(System.ArtifactsDirectory)
- stage: testcontainer
jobs:
- job: test123
container: python
steps:
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- script: |
echo $(System.ArtifactsDirectory)
displayName: 'Run a multi-line script'
Note: The container image is from Docker Hub, Azure Container Registry or another private container registry.