Is that possible to run service conatiner conditionally?

I just want to run service container in the pipeline conditionally similar to using when condtion in pipeline step.
Here basically here I have when condition to the step. In addition I need one for services part, if that make sense.

    title: Integration Test
    stage: test
    type: xxxxx/build-gradle
    fail_fast: false
    working_directory: "${{clone}}"
      RUNNER_IMAGE: xxxxner:v1.1
      BASE_DIR: .
      ARGS: "./gradlew integrationTest"
          isIntegrationTest: '${{INTEGRATION_TEST}} == true'
      shared_host_network: true
          image: 'image_name'
          user: oracle


To the best of my knowledge this is not possible. Could you explain a bit your use case? Why do you want the integration tests to run conditionally?

Ideally you always want your tests to run to verify that the code passes your requirements.

Thanks for your quick turnaround Kostis

The use case would be, I want to use same build pipeline yaml in some builds where we don’t use db container in integration testing but H2 in-memory DBs.
So in those cases services section is not needed.
If that make sense.

Personally I believe that db testing should be as close to production. Is the real application actually using H2 in production? Or does it use Mysql/Postgresql/Oracle?

It is best to always use the same db as production.

To do what you want I would probably use two separate pipelines. Or a parent pipeline that calls a child one.

This is for build pipeline system testing. Due to cloud restriction and costing unable to use prod like db.(Oracle )
So was thinking use same yaml with options like depend on/when/if etc. conditional approach if possible.

BTW, I found this in chat gpt, does this make sense?

version: '1.0'
    image: my-image:latest
          - ${{CF_BRANCH}}
          - 'master'  # Change this condition to your desired criteria
    image: my-service-image:latest

You can run a step conditionally

But I think service containers for the whole pipeline will always run. Service containers for a single step might work as you want. Conditional execution of steps · Codefresh | Docs

I strongly suggest to setup a second “staging” Oracle instance for testing stuff. This would also be useful for SQL updates (and not just source code). Using H2 to “replace” Oracle might work for simple stuff only.

1 Like