Skip to content

Commit

Permalink
(#2484) Documentation on multiple actions per task (#2487)
Browse files Browse the repository at this point in the history
in Cake scripting. Also added an example for the Run() override in Frosting.
  • Loading branch information
nils-a committed Aug 15, 2022
1 parent 6580a46 commit a15762d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions input/docs/writing-builds/tasks/defining-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ Task("A")
});
```

In script for [Cake .NET Tool], each task can have one or more actions to be executed when the task is executed.
Those actions are defined using the `Does` (see above) and `DoesForEach` (see [tasks for collections](./running-task-for-collections)) methods.
Both methods can be chained to define more than one action per task. As an example:

```csharp
Task("A")
.Does(() =>
{
Information("This action runs first.");
}).DoesForEach(GetFiles("./**/*"), f =>
{
Information("Found file: "+f);
}).Does(() => {
Information("This action runs last.");
});
```

# Defining tasks in Cake Frosting

To define a task in [Cake Frosting] create a class inheriting from [FrostingTask]:
Expand All @@ -24,6 +41,19 @@ public class TaskA : FrostingTask
}
```

To define the action of a task in [Cake Frosting], override the `Run` method:

```csharp
[TaskName("A")]
public class TaskA : FrostingTask<Context>
{
public override void Run(Context context)
{
context.Information("This task runs...");
}
}
```

[Cake .NET Tool]: /docs/running-builds/runners/dotnet-tool
[Cake Frosting]: /docs/running-builds/runners/cake-frosting
[FrostingTask]: /api/Cake.Frosting/FrostingTask/

0 comments on commit a15762d

Please sign in to comment.