Question: Properties and parameters validation #379
Unanswered
GreatTeacherBasshead
asked this question in
Q&A
Replies: 1 comment
|
Since this is a how-to question (and tagged as one), I'm moving it to Discussions where Q&A lives now. Short version: a Properties block is evaluated before any task runs, so the Join-Path against $baseDir in there happens before your Validate task ever gets a chance to assert on it. If you want validation to gate the property setup, either do the assert inside the Properties block itself, or compute the derived properties inside a task that depends on Validate rather than in the global Properties block. Happy to go deeper in the discussion thread. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Context
I want to use a parameter passed via command line to initialize some properties which are used in multiple tasks, instead of initializing them in each task.
Invoke-psake script.ps1 -parameters @{"baseDir" = "...some_path_here..."}And I want to validate that parameter first.
Example
Problem
Properties are initialized before any task. So my validation task doesn't do any work at all. For instance, if I don't pass $baseDir as a parameter or leave it empty, I will not reach Validate task. It will fail on a step of Properties initialization (
$reusedPath = Join-Path $baseDir "smth") with really not informative error:~~~~~~~~~~~ [<<==>>] Exception: Cannot bind argument to parameter 'Path' because it is null.Question
Is there way to validate parameters before Properties initialization? Or is there other way how to achieve the same goal?
Environment
All reactions