However when I do that the variable does not get rendered. How can I
achieve this?
You can't pass parameter to template in this way. The variable did not get rendered because we can't use runtime variables in template parameters. It's the direct cause why it didn't get rendered.
This is by design of Azure Devops Service, check Process the pipeline:
To turn a pipeline into a run, Azure Pipelines goes through several steps in this order:
1.First, expand templates and evaluate template expressions.
2.Next, evaluate dependencies at the stage level to pick the first stage(s) to run.
3.For each stage selected to run, two things happen:
All resources used in all jobs are gathered up and validated for authorization to run.
Evaluate dependencies at the job level to pick the first job(s) to run.
4.For each job selected to run, expand multi-configs (strategy: matrix or strategy: parallel in YAML) into multiple runtime jobs.
5.For each runtime job, evaluate conditions to decide whether that job is eligible to run.
6.Request an agent for each eligible runtime job.
So your variable comes after the task is executed(step6) while the parameter is evaluated at the very first of this process(step1 of pipeline run process). See:
This ordering helps answer a common question: why can't I use certain variables in my template parameters? Step 1, template expansion, operates solely on the text of the YAML document. Runtime variables don't exist during that step. After step 1, template parameters have been completely resolved and no longer exist.
In addition: Shayki Abramczyk's comment is right though it's not the main cause of your issue, you should use the Write-Host "##vso[task.setvariable variable=type]$($settings.pipeline.type)"
so that the value of $(type)
would be $settings.pipeline.type
instead of $settings
.
To use variable in next step:
We can check this document:
In order to use a variable as a task input, you must make the variable an output variable, and you must give the producing task a reference name.
More details about how to use that in yaml pipeline please check my another issue.