skip to Main Content

I have a working azure pipeline, something like this:

trigger: none

jobs:
- job: RunTest
  workspace:
    clean: all
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - task: Docker@2
    displayName: Login to ACR
    inputs:
      command: login
      containerRegistry: my-acr
  - script: |
      docker run my-registry.azurecr.io/somerepo/rnd-hello:latest 

How to run now multiple shell scripts on the docker image?
For example, how to do the following now :

  • cmake -DCMAKE_BUILD_TYPE=Release -Bbuild;
  • cmake –build build –config Release
  • … run some shell scripts already included in the docker image

My Problems are :
The Azure Container Instance does not support parameters like docker -it and –rm.
And if I use docker exec, I think it will start in every line a new instance and I can not use the results of the previous line.

Any Ideas on how to run multiple shell scripts on one instance of a docker image in a azure pipeline

2

Answers


  1. Chosen as BEST ANSWER

    Integrating the info of @Miao Tian-MSFT I ended with the following solution:

    jobs:
    - job: RunTest
      workspace:
        clean: all
      pool:
        vmImage: 'ubuntu-latest'
      steps:
      - task: Docker@2
        displayName: Login to ACR
        inputs:
          command: login
          containerRegistry: my-acr
      - script: |
          docker run --name=mycontainer my-registry.azurecr.io/somerepo/rnd-hello:latest 
          docker exec mycontainer bash -c 'cmake -DCMAKE_BUILD_TYPE=Release -Bbuild;'
          docker exec mycontainer bash -c 'cmake --build build --config Release'
          docker exec mycontainer bash -c './scripts/run_tests.sh'
          docker cp mycontainer:/app/build $(Build.ArtifactStagingDirectory)
    

  2. if I use docker exec, I think it will start in every line a new instance and I can not use the results of the previous line.

    For this question, in fact, the docker exec command does not start a new instance of the container. The confusion might arise from the fact that each docker exec command starts a new shell session in the running container, and these sessions are independent of each other. If you have a Docker container already running, you can use docker exec to run commands in that same container. If you are modifying data that are stored on the container, those changes will persist between docker exec commands, as they all interact with the same container.

    You can also write your commands in a script.sh file and run the script inside the running Docker container, when you have multiple commands that need to be run in sequence or depend on each other.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search