1
votes

Our Organization has started migrating to Azure. We have Azure pipeline template which runs checkout, build and deploy stages on vmImage: 'ubuntu-18.04'. Our plan is to introduce "Test" stage in the template and run tests in Container.

Question:

  • When the entire pipeline is running on vmImage, is it possible to run one of the stages (Test) in Container?
  • How to copy build artifacts from vmImage to run tests in Container?

Can someone please shed some light on this?

Thanks a lot!

1
Hi @Yamuna. Is there any update about this ticket? Feel free to let me know if the answer could give you some help. Just a remind of this.Kevin Lu-MSFT
Hi @Kevin Lu-MSFT, Thanks a lot for your response. I am trying out the solution that is recommended by you. I'll post as soon as I've update.Yamuna
Hi @Yamuna. To follow up, could you please share the latest information with us? Feel free to let me know if the answer could work.Kevin Lu-MSFT

1 Answers

0
votes

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.