Comments (3)
Ok, so I was 'just missing something' then :)
The difference between () and {} is nuanced but it makes sense. I swear I was trying to do the appropriate amount of RTFM before asking. I'd maybe modify the documentation slightly to show both scenarios.
-If
Specifies the optional condition to be evaluated. If the condition
evaluates to false then the task is not invoked. The condition can be
defined in one of two ways depending on your requirements.
Using script block notation (curly braces) the condition will be evaluated
dynamically upon task invocation. This is ideal for tasks that may be
run multiple times and are skipped at first but invoked later when the
script block becomes true.
Example:
task SomeTask -If {$SomeCondition} {...}
Using standard Boolean notation (parenthesis) the condition will only
be evaluated when the task is loaded into the build engine. A use case
for this notation might be evaluating parameters that are passed into
the build.
Example:
task SomeTask -If ($SomeCondition) {...}
On WhatIf a script block is treated as true without invocation using
script block notation but not if the condition is defined in Boolean
notation.
Or something like that?
Regardless, thanks for clarifying for me and thank you for the excellent project!
from invoke-build.
Task parameters If
, Inputs
, and Outputs
can be either script blocks
evaluated on task invocation or other values evaluated on task definition.
In your case the value for If
may change after adding tasks and you want to
use the current changed value on invocation of the task TestConfigure
. So use
the script block:
task TestConfigure -If {$Script:IsConfigured} {
Write-Host 'configured...for certain!'
}
You should use -If $Script:IsConfigured
only if $Script:IsConfigured
does
not change or you specifically want to check for the original value, not
changed during the build.
If values for If
(or Inputs
, Outputs
) do not change during the build then
it does not matter what to use, -If {}
or -If ()
. But if the expression is
complex/expensive you may choose -If {}
in order to avoid evaluation if a
task is not invoked at all in the build. On the other hand, if you want to
catch potential problems earlier, at a task definition, then you still may
want to use -If ()
.
Should we improve help perhaps? Here is the current:
0> . Invoke-Build
0> help task -Parameter If
-If
Specifies the optional condition to be evaluated. If the condition
evaluates to false then the task is not invoked.
The value is a script block evaluated on task invocation or an object
treated as Boolean on definition. On WhatIf a script block is treated
as true without invocation.
If the task is called several times then it is possible that the task
is skipped at first but invoked later when the script block gets true.
from invoke-build.
Thank you for the suggested improved help. I like it and will use it in vNext.
from invoke-build.
Related Issues (20)
- Amend output on task errors.
- Reusing or sharing tasks HOT 5
- ib.cmd ? ignores a specified file
- vscode outline view: no symbols found in document HOT 2
- Different module and package versions HOT 2
- Parallel execution based on dependency tree HOT 2
- invoke-build discovery fails in powershell container HOT 3
- Please consider adding -Computername and -Session parameter to Task HOT 8
- GitHub action output is not colored
- Color and formatting text in Azure DevOps Pipelines HOT 8
- Use-BuildEnv should make parameters mandatory
- Invoke-BuildExec spitting out service principal secret as current directory HOT 6
- Exec doesn't work well with forward slash arguments HOT 7
- Use `[System.Management.Automation.Cmdlet]::CommonParameters` to get the names of all common parameters HOT 3
- Task condition does not work HOT 8
- Build-Parallel writes only to Output stream HOT 7
- property 'File' cannot be found on this object HOT 17
- Do not wrap internal errors in Resolve-MSBuild
- Fix cryptic errors on unknown parameters
- Invoke-BuildExec should pass the original stderr error to the thrown terminating error HOT 38
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invoke-build.