We were able to do this on gitlabci but not after we moved to github actions.
We want certain jobs like *building docker images, deploying helm chart etc.,) to be skipped if a variable DEPLOY=false is set for the repository. We are using common reusable workflows across many repositories.
jobs:
dockerbuildpush:
runs-on: [self-hosted, Ubuntu-22.04]
if: env.BUILD != false
I have tried ${{ }} syntax for the same but it is not considered as a valid syntax. It seems I can do the same for actions but not for jobs or workflow. Workflow contains many jobs, jobs contain many actions. I can do env.WHATEVER in if: for actions but not for jobs or workflows?!
2
Answers
The only thing consistently worked for us across other such situations was to just add the repository name to the if condition in the re-usable workflows.
If tomorrow we need to excude more repos from such re usable workflows then we do
If the number of repos to include such re usable workflows is more than the number of repos to exclude then we can always use the
==
condition instead of!=
condition. This also transfers the burden of modification to devops and not devs/contributors/maintainers of the repo which is the way it should be. If in future when one decides to migrate from on prem to off prem github or from one github server to another, then most configuration of workflow is in the yaml's and not as vars in the repo.You can use
If
condition checks both at jobs as well as steps level.sample.yml
reusable-workflow.yml
In
sample.yml
,dockerbuildpush
job will only run ifDEPLOY
variable istrue
and inreusable-workflow.yml
steppush
will only run if inputpush
istrue