Skip to content

Commit 4c4c08d

Browse files
committed
Add try/catch around teardown code
Add try/catch around teardown code to avoid errors like this: An error occurred in a custom teardown action. Teardown error: System.InvalidOperationException: The context data has not been setup. at Cake.Core.CakeDataService.Get[TData]() in C:\projects\cake\src\Cake.Core\CakeDataService.cs:line 32 at Cake.Core.CakeEngineActions.<>c__DisplayClass21_0`1.<RegisterTeardown>b__0(ITeardownContext context) in C:\projects\cake\src\Cake.Core\CakeEngineActions.cs:line 64 at Cake.Core.CakeEngine.PerformTeardown(IExecutionStrategy strategy, ICakeContext context, Stopwatch stopWatch, CakeReport report, Boolean exceptionWasThrown, Exception thrownException) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 493 https://travis-ci.org/GitTools/GitVersion/jobs/495911487#L1914
1 parent 9d00191 commit 4c4c08d

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

build.cake

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,40 +66,47 @@ Setup<BuildParameters>(context =>
6666

6767
Teardown<BuildParameters>((context, parameters) =>
6868
{
69-
Information("Starting Teardown...");
69+
try
70+
{
71+
Information("Starting Teardown...");
7072

71-
Information("Repository info : IsMainRepo {0}, IsMainBranch {1}, IsTagged: {2}, IsPullRequest: {3}",
72-
parameters.IsMainRepo,
73-
parameters.IsMainBranch,
74-
parameters.IsTagged,
75-
parameters.IsPullRequest);
73+
Information("Repository info : IsMainRepo {0}, IsMainBranch {1}, IsTagged: {2}, IsPullRequest: {3}",
74+
parameters.IsMainRepo,
75+
parameters.IsMainBranch,
76+
parameters.IsTagged,
77+
parameters.IsPullRequest);
7678

77-
if(context.Successful)
79+
if(context.Successful)
80+
{
81+
// if(parameters.ShouldPublish)
82+
// {
83+
// if(parameters.CanPostToGitter)
84+
// {
85+
// var message = "@/all Version " + parameters.Version.SemVersion + " of the GitVersion has just been released, https://www.nuget.org/packages/GitVersion.";
86+
87+
// var postMessageResult = Gitter.Chat.PostMessage(
88+
// message: message,
89+
// messageSettings: new GitterChatMessageSettings { Token = parameters.Gitter.Token, RoomId = parameters.Gitter.RoomId}
90+
// );
91+
92+
// if (postMessageResult.Ok)
93+
// {
94+
// Information("Message {0} succcessfully sent", postMessageResult.TimeStamp);
95+
// }
96+
// else
97+
// {
98+
// Error("Failed to send message: {0}", postMessageResult.Error);
99+
// }
100+
// }
101+
// }
102+
}
103+
104+
Information("Finished running tasks.");
105+
}
106+
catch (Exception exception)
78107
{
79-
// if(parameters.ShouldPublish)
80-
// {
81-
// if(parameters.CanPostToGitter)
82-
// {
83-
// var message = "@/all Version " + parameters.Version.SemVersion + " of the GitVersion has just been released, https://www.nuget.org/packages/GitVersion.";
84-
85-
// var postMessageResult = Gitter.Chat.PostMessage(
86-
// message: message,
87-
// messageSettings: new GitterChatMessageSettings { Token = parameters.Gitter.Token, RoomId = parameters.Gitter.RoomId}
88-
// );
89-
90-
// if (postMessageResult.Ok)
91-
// {
92-
// Information("Message {0} succcessfully sent", postMessageResult.TimeStamp);
93-
// }
94-
// else
95-
// {
96-
// Error("Failed to send message: {0}", postMessageResult.Error);
97-
// }
98-
// }
99-
// }
100-
}
101-
102-
Information("Finished running tasks.");
108+
Error(exception.Dump());
109+
}
103110
});
104111

105112
//////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)