Conditional jobs based on <on> conditions?

I am currently building a workflow that basically does two things in two seperate jobs:

  • Build a custom Docker image and push it to GPR

  • Pull the built Docker image from GPR and use it to compile my software

While this works fine, it seems a bit inefficient to rebuild the entire Docker image each time the workflow is triggered. Instead, it would be a lot cooler if it would only trigger on changes in the docker/ path, where my Dockerfile resides, for example.

The on.<push|pull_request>.paths syntax seems to support such behavior, but it applies to the entire workflow. Is there a way to conditionally execute my “build docker image” workflow step based on the same criteria?

2 Likes

Hi ArondeParon ,

If you want to set some conditions for jobs, you need to use the syntax jobs.<job_id>.if .
current it seems does not support to apply the path filters in the conditions. As workaround, you can try to set some keywords in the comments/titles when pull changes into ‘docker/’ path, then to run the job based on the keywords.
For example when the add the keywords Run first_job in the description of the PR, PR event trigger the workflow, and the first_job in the workflow will run, if not add the keywords, the first_job will not run.

1 Like

Thanks for the reply, but this is a bit too much of a workaround for me, because it would require contributors to be aware of this fact.

The build system should be “as-is” and I prefer not to base conditional logic on the commit messages. Thanks for the thinking with me, though!

Does anyone know if path filters for job conditions are on the roadmap somewhere?

1 Like