Skip to content

Tasks Preconditions

guryanovev edited this page Dec 27, 2016 · 5 revisions

Preconditions allow to skip task execution at a certain case. Use WithPrecondition helper to configure a predicate to check the condition:

var predicate = true;

var fooTask = Task(
    "foo",
    new MyTask().WithPrecondition(predicate));

The task will be executed only if predicate is true. Optionally you can pass the second parameter that will be used as a task result value (when the task is skipped):

var predicate = true;

var fooTask = Task(
    "foo",
    new MyTask().WithPrecondition(predicate, defaultValue));

Preconditions are often used with properties passed to the workflow. For example, extracting version number from source control is not necessary if the Version is already provided from the outside:

public string Version { get; set; } // passed from Rosalia CLI

protected override void RegisterTasks()
{
    ITaskFuture<string> getVersionTask = Task(
        "svnVersion",
        new SvnVersionTask
        {
            /* ... */
        }
        .TransformWith(svnVersion => 
            string.Format("1.0.{0}.0", svnVersion.Max.Number))
        .WithPrecondition(
            string.IsNullOrEmpty(Version),  
            Version));
}