I have been struggling to figure out whether reusable commands can have an output.
In our monorepo, we are trying to implement a workflow where a service only gets deployed when they got changed. The logic is fairly simple: we run git diff $BASE_SHA $HEAD_SHA | grep '^service1/.*$'
, and if it has any output, then service1 will needs to be deployed. However, we’ve been struggling on implementing this in circleci.
So ideally, it would be something like this:
commands:
check-diff:
parameters:
regex:
type: string
steps:
- run:
command: git diff $BASE_SHA $HEAD_SHA | grep <<parameters.regex>>
- if run above has any result, output true, else output false
jobs:
deploy-service1:
steps:
- check-diff:
regex: '^service1/.*$'
- when:
condition:
equal: [true, <<check-diff.output>>]
steps:
deploy-service-1
deploy-service2:
steps:
- check-diff:
regex: '^service2/.*$'
- when:
condition:
equal: [true, <<check-diff.output>>]
steps:
deploy-service-2
Any help would be much appreciated, thank you!