forked from actions/runner
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azp: check undefined parameters and report error (#260)
- Loading branch information
1 parent
4195f5c
commit 4deb0bf
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using GitHub.DistributedTask.Expressions2.Sdk; | ||
using GitHub.DistributedTask.ObjectTemplating; | ||
|
||
namespace Runner.Server.Azure.Devops | ||
{ | ||
class ParametersContextData : IReadOnlyObject | ||
{ | ||
private Dictionary<string, object> data; | ||
private TemplateValidationErrors errors; | ||
public ParametersContextData(Dictionary<string, object> data, TemplateValidationErrors errors) | ||
{ | ||
this.data = data; | ||
this.errors = errors; | ||
} | ||
|
||
public object this[string key] => data[key]; | ||
|
||
public int Count => data.Count; | ||
|
||
public IEnumerable<string> Keys => data.Keys; | ||
|
||
public IEnumerable<object> Values => data.Values; | ||
|
||
public bool ContainsKey(string key) | ||
{ | ||
return data.ContainsKey(key); | ||
} | ||
|
||
public IEnumerator GetEnumerator() | ||
{ | ||
return data.GetEnumerator(); | ||
} | ||
|
||
public bool TryGetValue(string key, out object value) | ||
{ | ||
if(!data.TryGetValue(key, out value)) { | ||
errors.Add($"Unexpected parameter reference 'parameters.{key}'"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
testworkflows/azpipelines/referenced-missing-parameter-error/pipeline.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ExpectedException: TemplateValidationException | ||
# ExpectedErrorMessage: test6 | ||
|
||
parameters: | ||
- name: no | ||
type: number | ||
default: 0 | ||
steps: | ||
- script: echo ${{ parameters[format('{0}', 'test6')] }} |
6 changes: 6 additions & 0 deletions
6
testworkflows/azpipelines/referenced-missing-parameter-ok/pipeline.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
parameters: | ||
- name: no | ||
type: number | ||
default: 2 | ||
steps: | ||
- script: echo ${{ coalesce('test', parameters.y) }} |