skip to Main Content

Is there a way to define the container where your entire pipeline stages and jobs can run, from start to finish, without stopping the container in-between the stages.

I am creating a azure pipeline for building each microservices (which includes stages for mvn deploy, docker build and release, ecr release, mvn release). I tried using the containers in the pipeline that i have written inside microservice to trigger the pipeline for building microservices.

The container seems to initialize and working but it is getting stop after each stage .The builds that is generated in build stage is not there when the docker build and release stage is running.

in trigger pipeline:

  containers:
  - container: dockerContainer
    image: image name
    endpoint: dockerhubcreds
    options: --user 0:0

pipeline for building microservices:

  - stage: Build
    dependsOn: SetupMaven
    jobs:
    - job: Build_job
      displayName: Build
      container: dockerContainer

When I tried the above method, the container is stopping after each stage. Also i am using the ubuntu self hosted agent for testing and Microsoft hosted agent (ubuntu-latest) for production.
enter image description here

2

Answers


  1. You cannot use the same container instance in all jobs in a pipeline. Keep in mind that each job might be picked up by multiple build agents, which might be running in different machines.

    Containers are used at a job level, not a stage. Containers can be used to run a list of tasks within a job, not a stage. If you need fine-grained control at the individual step level, step targets allow you to choose container or host for each step.

    See Define container jobs for more details.

    Login or Signup to reply.
  2. As mentioned by @Rui Jarimba, containers are used at a job level. If you are using a MS-hosted agent, each job gets a fresh agent, and the container will be brand new as well.

    If you want all your stages/jobs run in the same container, you can set up a self-hosted agent in Docker and use this agent to run your pipeline. See Run a self-hosted agent in Docker for the detailed steps.

    Note: When you start the image, ensure DON’T add --once in docker run. Otherwise, with the --once flag, you will get a fresh agent container for every pipeline job.

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