# Is that possible to run service conatiner conditionally?

**URL:** <https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944>\
**Category:** Pipeline Workflows\
**Created:** [October 13, 2023, 5:49am UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944 "2023-10-13T05:49:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudheerah](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/sudheerah/32/419_2.png) [@sudheerah](https://community.codefresh.io/u/sudheerah)\
**Post date:** [October 13, 2023, 5:49am UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944/1 "2023-10-13T05:49:38Z")

</div>

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.

```auto
  integration_test:
    title: Integration Test
    stage: test
    type: xxxxx/build-gradle
    fail_fast: false
    working_directory: "${{clone}}"
    arguments:
      RUNNER_IMAGE: xxxxner:v1.1
      BASE_DIR: .
      ARGS: "./gradlew integrationTest"
    when:
      condition:
        any:
          isIntegrationTest: '${{INTEGRATION_TEST}} == true'
    services:
      shared_host_network: true
      composition:
        db_instance:
          image: 'image_name'
          user: oracle

```

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [October 13, 2023, 9:10am UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944/2 "2023-10-13T09:10:37Z")

</div>

Hello

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.

---

<div class="post-metadata">

**Author:** ![sudheerah](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/sudheerah/32/419_2.png) [@sudheerah](https://community.codefresh.io/u/sudheerah)\
**Post date:** [October 13, 2023, 10:43am UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944/3 "2023-10-13T10:43:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [October 13, 2023, 1:27pm UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944/4 "2023-10-13T13:27:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sudheerah](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/sudheerah/32/419_2.png) [@sudheerah](https://community.codefresh.io/u/sudheerah)\
**Post date:** [October 13, 2023, 10:39pm UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944/5 "2023-10-13T22:39:19Z")

</div>

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?

```auto
version: '1.0'
steps:
  myStep:
    image: my-image:latest
    when:
      condition:
        equals:
          - ${{CF_BRANCH}}
          - 'master' # Change this condition to your desired criteria
services:
  myService:
    image: my-service-image:latest

```

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [October 16, 2023, 10:04am UTC](https://community.codefresh.io/t/is-that-possible-to-run-service-conatiner-conditionally/944/6 "2023-10-16T10:04:22Z")

</div>

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](https://codefresh.io/docs/docs/pipelines/conditional-execution-of-steps/)

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.
