Closed mathiasi closed 1 year ago
Only workaround I could think of was
DotNet.Test("*Test.csproj") with
{
DisplayName = "Dotnet Test",
TestRunTitle = "Title",
Arguments = "--no-build --configuration Release --collect \"Code coverage\"",
Inputs = new()
{
{ "ContinueOnError", parameters["myBool"] }
}
}
but this looks less ideal.
Hey, Thanks for opening this issue. I agree that this is a very useful feature and should be supported. Unfortunately, I think it will require quite a bit of work as technically a variable can be put in place of basically anything. I think it might have a solution where we create a wrapper type that could be "T or expression" but I will have to do some experiments to verify it can be done.
I will get back to you soon about this.
I was also thinking a wrapper would be needed. Maybe something like Conditioned
- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
command: test
testRunTitle: "Title"
projects: |
*.Test.csproj
${{ if eq(parameters.myBool, true) }}:
arguments: 'some arguments'
${{ if eq(parameters.myBool, false) }}:
arguments: 'some other arguments'
Maybe one solution could cover both scenarios
Once you're in the Dictionary (like in inputs), this is actually possible:
StepTemplate("template1.yaml", new()
{
{ "some", "value" },
{
If.IsPullRequest,
new TemplateParameters()
{
{ "pr", true }
}
},
{ "other", 123 },
}),
Ah okay thanks! Though my key reason for using Sharpliner is to avoid dealing with yaml in the first place :D So I thought it could be cool if it was possible in another manner.
I agree completely.
I think we will end up wrapping all properties in a Conditioned<>
, yeah. For instance, now we have some like that already and some not.
For instance it's possible to do:
{
Pool = If..
}
But it wouldn't be possible for ContinueOnError
. So there is some debt in this where probably everything should be a Conditioned<>
. We could then make variable/parameter references (or expressions) implicitly cast into this as well, producing a string ${{ parameter.foo }}
.
However, there's one more angle to this - https://github.com/sharpliner/sharpliner/issues/122. This issue would mean wrapping all properties again so that we create a dictionary behind that we serialize. This would mean your C# and YAML would be ordered how you want and not how we decide in Sharpliner. So this is another one where we might potentially have to change dozens of properties. I need to consider both and whether it makes sense to do them together. But your issue has preference 100%. The order is not so important.
@mathiasi I was able to make this work using the Conditioned<>
everywhere. However, I still think we have some missing spots, e.g. using generic expressions everywhere. Something like this:
continueOnError: ${{ replace(parameters.someParameter, ' ', '') }}
But I think this should be possible to add with some new Expression()
method...
That was quick! 😄 Unfortunately I won't have the chance to try it out until a in couple of weeks but I definitely will!
I've got this example:
Is there a way to pass the parameter on to the input of the task?