-
Notifications
You must be signed in to change notification settings - Fork 55
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
Evaluate undefined service connection variables to empty strings at pipeline queue time #1319
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
I think this should work - I'll test it now and let you know. |
It works for excluding the steps, but doesn't seem to work when the variables are set to I'll check out the generated yaml to see if I can tell what's going on. |
I see now that Inside a job, pipeline variables don't show up (this seems to me to be the purpose of the |
Yeah, that's my guess. In my experience the variables only show up after a couple of layers of pass-through as parameters.. it's not great. I'll try some experiments with it. First I'm just logging the value of the kusto variable before that step: https://dev.azure.com/dnceng/internal/_build/results?buildId=2463501&view=logs&s=380ab8c6-4139-55ff-15c4-fb48260f4dca |
Yep, as expected they resolve to empty strings |
An alternative to just get this unblocked could be to go with "force this feature off" parameters that are passed all the way from the yml we control down into the common publish yml. 😄 Some background: for the (non-Docker) Go pipelines, I was fed up with matrices and variables and went essentially parameter and template-only, because they're more predictable and faster to iterate. (Errors tend to show up at eval time rather than only at runtime, and inspecting evaluated yml is more useful.) That might leave me with a blind spot on how to debug odd variable behavior like this or some other alternatives that might exist. |
I'm thinking that maybe the syntax |
@dagood I found a solution that works. I tested it by setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a solution that works. I tested it by setting ingestKustoImageInfo and waitForIngestionEnabled to false, and then replacing the service connection variable names with variables that don't exist (so that they'd fail if we tried to use the service connections).
Just want to confirm that the positive case still works where this is enabled for our .NET builds?
Assuming it works for the positive case: I suppose this would have to be because Not to say that everything in Azure Pipelines needs to be reasoned out (or can be), but thought it might be worth hypothesizing. 😄 |
Shoot, yeah, this doesn't actually work. My intention was to get the service connections to resolve as empty strings, so that the It doesn't work because I've been trying a few other things with no success:
^ This example never resolves the correct value for
However I think that solution doesn't work because these variables themselves are not populated until after templates are generated, since they depend on the conditions inside the templates... yeah. If we remove the I'm open to other suggestions too. |
What about changing the implementation of |
@mthalman it already does that, is this what you mean?
The issue is getting the service connection string to...
I think the next thing to try is passing in the service connection variables as parameters to the publish stage. Elevating variables like that, in my experience, has allowed them to be accessible at pipeline queue time. That's how the internal/public project names are made available in the template expression on that same line (even though they're also variables). |
That's the part I was missing. This should be able to be defaulted in a variables template to an empty string. Then it can be overridden via a variable group. |
a6b0286
to
ff9e95d
Compare
OK, I just pushed some changes that should get this working. Here's some test runs for our different scenarios:
|
internalProjectName: ${{ parameters.internalProjectName }} | ||
condition: and(succeeded(), eq(variables['ingestKustoImageInfo'], 'true')) | ||
condition: and(succeeded(), eq('${{ parameters.ingestKustoImageInfo }}', 'true')) | ||
${{ if eq(parameters.ingestKustoImageInfo, 'true') }}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this check was moved to conditionalize the entire call to run-imagebuilder.yml, that would simplify things. Same for the other two implementations in wait-for-mcr-*.yml
templates.
I tried to update to the latest eng/common today and hit similar issues with 36550ca introducing more variables that are expected to be set at template-eval-time. But that made me realize something about this PR and this problem in general: if it works to add a variable with value '' to our config, we can simply do that in our repo/group to avoid maintenance pain here. I tried putting these in |
@dagood did this also work for any issues you had with |
Yep, setting No worries, Go builds are happy to chug along with a manual change for a bit as long as we don't urgently/frequently need to update. I wish I'd realized sooner that we could simply define the variables on the Go side and skip the scoping mess. 😄 |
So: I'm happy to close this PR. For other potential users of .NET Docker tools in the future there could be value in adding empty string defaults here, but I'm not sure that's worth the maintenance effort at the moment. Up to you. 🙂 |
Great. Thanks for the update! |
A task condition doesn't work to avoid
serviceConnection: $(kusto.serviceConnectionName)
because the validity of that type of auth is checked before the build starts (something like template-eval-time) rather than just before the task starts.Note: I'm not actually sure if this works. It might just always disable the step. I only learned recently that variables work at all in template conditions, and I didn't find documentation that describes it very well so I don't know the edge cases. But I do expect that e.g. if a log command is used to change
ingestKustoImageInfo
from false to true, it wouldn't be able to react to that.Example failed run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2462622&view=results