runner icon indicating copy to clipboard operation
runner copied to clipboard

Support for starting job service on condition is met

Open igagis opened this issue 4 years ago • 3 comments

Describe the enhancement Add support of if: property to jobs.<job-id>.services.<service-id> to start services only in case a condition is met.

Code Snippet

jobs:
  my_job:
    services:
      my_service:
        if: ${{ some expression }}
        ....

igagis avatar Nov 25 '20 01:11 igagis

That would be very helpful if you have a shared workflow. We could turn on/off services based on workflow inputs

tanguyantoine avatar Sep 12 '22 14:09 tanguyantoine

Couldn't agree more, we add steps to run docker run manually because we don't have conditions on services.

imclem avatar Dec 21 '22 09:12 imclem

leaving service.<service-name>.image empty does not start the service, this is the output:

The service 'postgres' will not be started because the container definition has an empty image.

This can be used to build a basic conditional, it is a workaround, a proper solution should be implemented.

thobianchi avatar Jan 16 '23 10:01 thobianchi

Yes this would be a cool feature, we have the same problem on a shared workflow

bvtk avatar Jan 26 '23 16:01 bvtk

Got here searching for the solution of our problem with shared workflows :) Hope this feature will be implemented as it would increase the utility of shared workflows dramatically.

vyacheslav-korneev avatar Feb 15 '23 09:02 vyacheslav-korneev

this would be very useful when reusing workflows, please consider implementing it

flozano avatar Apr 26 '23 13:04 flozano

I think the following is supported, since https://github.com/actions/runner/commit/3e196355deb87ff9f4c0c0b4643f512e62257bf8 aka v2.299.0 or later

jobs:
  my_job:
    services:
      my_service:
        image: ${{ (some expression) && 'image:tag' || '' }}

It's very similar to an if, just not so nice to write.

ChristopherHX avatar Apr 27 '23 06:04 ChristopherHX

thanks a lot, I was trying something similar. not nice aesthetically but if it works it's great.

flozano avatar Apr 27 '23 08:04 flozano

That would be very helpful for my organization as well

cezar-tech avatar Jun 06 '23 21:06 cezar-tech

Almost 3 years passed

keramblock avatar Oct 19 '23 14:10 keramblock

I think the following is supported, since 3e19635 aka v2.299.0 or later

jobs:
  my_job:
    services:
      my_service:
        image: ${{ (some expression) && 'image:tag' || '' }}

It's very similar to an if, just not so nice to write.

In my example it works as designed. If database_name input not provided (is empty) skip the installation and if it's provided then use postgres image with the version as provided in the postgres_version input.

    services:
      postgres:
        image: ${{ ( inputs.database_name != '' ) && format('postgres:{0}', inputs.postgres_version) || '' }}

sergbar avatar Nov 29 '23 09:11 sergbar

Workaround works perfectly for me

Cyberboss avatar Nov 29 '23 20:11 Cyberboss

Best GH can do is update the docs with this workaround.

Cyberboss avatar Nov 29 '23 20:11 Cyberboss

The workaround is not ideal as the image names specified in expressions will fall off from automated updates via Renovate.

knu avatar Mar 04 '24 07:03 knu