runner
runner copied to clipboard
Support for starting job service on condition is met
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 }}
....
That would be very helpful if you have a shared workflow. We could turn on/off services based on workflow inputs
Couldn't agree more, we add steps to run docker run
manually because we don't have conditions on services.
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.
Yes this would be a cool feature, we have the same problem on a shared workflow
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.
this would be very useful when reusing workflows, please consider implementing it
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.
thanks a lot, I was trying something similar. not nice aesthetically but if it works it's great.
That would be very helpful for my organization as well
Almost 3 years passed
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) || '' }}
Workaround works perfectly for me
Best GH can do is update the docs with this workaround.
The workaround is not ideal as the image names specified in expressions will fall off from automated updates via Renovate.