I'm trying to make use of Container Job template in a pipeline which runs on both Microsoft Hosted and Self-Hosted (Containerized) build agents.
ContainerJob template works well when run in Microsoft Hosted
but fails in Self-Hosted agent saying cannot run container inside a containerized build agent
. Error makes sense though.
I figured that if below section can be added/removed conditionally then same Container Job template works in both agents.
${{ if not(parameters.isSelfHosted) }}:
container:
image: ${{ parameters.generalImage}}
endpoint: ${{ parameters.endpoint}}
environment: ${{ parameters.environment }}
But the condition is always true and container
section is added always and failed in self-hosted agent always. I think expressions are not allowed randomly inside a template.
I can separate out this template into 2 templates and load them in respective build agent but that's the last resort. Any help in dynamically creating/altering a template is highly appreciated.