Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix variable templates using expressions #329

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Sdk/AzurePipelines/AzureDevops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ static async IAsyncEnumerable<TemplateToken> ProcessVariableSequence(Context con
}
else if (template != null)
{
var file = await ReadTemplate(context, template, parameters != null ? parameters.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "variable-template-root");
var evalp = parameters != null ? TemplateEvaluator.Evaluate(staticVarCtx, "workflow-value", parameters, 0, parameters.FileId) : null;
var file = await ReadTemplate(context, template, evalp != null ? evalp.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "variable-template-root");
var res = await ParseVariables(context.ChildContext(file, template), vars, (from e in file where e.Key.AssertString("").Value == "variables" select e.Value).First(), staticVarCtx);
if (res is SequenceToken sq) {
await foreach(var x in ProcessVariableSequence(context, vars, staticVarCtx, staticVars, sq)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
- name: templateParameters
default: Release
variables:
- template: vars.yml
parameters:
prefix: ${{ parameters.templateParameters }}
- name: ncfg
value: TEST-${{ variables.buildConfig }}
steps:
- bash: ${{ variables.ncfg }}
- ${{ if ne(variables.ncfg, 'TEST-Release') }}:
- assert: this won't work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
- name: prefix
default: Debug
variables:
- name: buildConfig
value: ${{ parameters.prefix }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
- name: templateName
default: ./vars.yml
variables:
- template: ${{ parameters.templateName }}
- name: ncfg
value: TEST-${{ variables.buildConfig }}
steps:
- bash: ${{ variables.ncfg }}
- ${{ if ne(variables.ncfg, 'TEST-Release') }}:
- assert: this won't work
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variables:
- name: buildConfig
value: Release
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
- name: template
type: object
default:
template: vars.yml
parameters:
prefix: Release
variables:
- ${{ parameters.template }}
- name: ncfg
value: TEST-${{ variables.buildConfig }}
steps:
- bash: ${{ variables.ncfg }}
- ${{ if ne(variables.ncfg, 'TEST-Release') }}:
- assert: this won't work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
- name: prefix
default: Debug
variables:
- name: buildConfig
value: ${{ parameters.prefix }}
Loading