Mongo

Example Pipeline with Mongo

Example Yaml configuration for a project requiring a Mongo as a pipeline dependency.

Scenario

User is looking to create a pipeline that can integrate with an ephemeral Mongo instance.

Services

Services Yaml block can be used with stages and steps pipelines. This example uses a basic steps configuration.

The following pipeline concepts are being used in the pipeline below:

version: "1"
services:
  - name: mongo
    image: mongo:latest
    pull: always

steps:
  - name: check status
    image: mongo:latest
    pull: always
    commands:
      # sleeping can help ensure the service adequate time to start
+      - sleep 15
      - /bin/mongosh --host mongo --eval 'db.runCommand("ping")'

Detach

If you’re looking for more granular start time for the container you can add a detach flag within stages and steps pipelines.

The following pipeline concepts are being used in the pipeline below:

version: "1"

steps:
  - name: mongo
    image: mongo:latest
    detach: true

  - name: check status
    image: mongo:latest
    commands:
      # sleeping can help ensure the service adequate time to start
+      - sleep 15
      - /bin/mongosh --host mongo --eval 'db.runCommand("ping")'