@@ -15,7 +15,7 @@ import (
15
15
"github.com/ovh/cds/sdk/log"
16
16
)
17
17
18
- func processNodeOutGoingHook (ctx context.Context , db gorp.SqlExecutor , store cache.Store , proj * sdk.Project , wr * sdk.WorkflowRun , mapNodes map [int64 ]* sdk.Node , parentNodeRun []* sdk.WorkflowNodeRun , node * sdk.Node , subNumber int ) (* ProcessorReport , error ) {
18
+ func processNodeOutGoingHook (ctx context.Context , db gorp.SqlExecutor , store cache.Store , proj * sdk.Project , wr * sdk.WorkflowRun , mapNodes map [int64 ]* sdk.Node , parentNodeRun []* sdk.WorkflowNodeRun , node * sdk.Node , subNumber int ) (* ProcessorReport , bool , error ) {
19
19
ctx , end := observability .Span (ctx , "workflow.processNodeOutGoingHook" )
20
20
defer end ()
21
21
@@ -34,34 +34,34 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
34
34
// If the hookrun is at status terminated, let's trigger outgoing children
35
35
if exitingNodeRun != nil && ! sdk .StatusIsTerminated (exitingNodeRun .Status ) {
36
36
log .Debug ("hook %d already processed" , node .ID )
37
- return nil , nil
37
+ return nil , false , nil
38
38
} else if exitingNodeRun != nil && exitingNodeRun .Status != sdk .StatusStopped .String () {
39
39
log .Debug ("hook %d is over, we have to reprocess al the things" , node .ID )
40
40
for i := range node .Triggers {
41
41
t := & node .Triggers [i ]
42
42
log .Debug ("checking trigger %+v" , t )
43
43
r1 , err := processNodeTriggers (ctx , db , store , proj , wr , mapNodes , []* sdk.WorkflowNodeRun {exitingNodeRun }, node , subNumber )
44
44
if err != nil {
45
- return nil , sdk .WrapError (err , "Unable to process outgoing hook triggers" )
45
+ return nil , false , sdk .WrapError (err , "Unable to process outgoing hook triggers" )
46
46
}
47
47
report .Merge (r1 , nil ) // nolint
48
48
}
49
- return report , nil
49
+ return report , false , nil
50
50
} else if exitingNodeRun != nil && exitingNodeRun .Status == sdk .StatusStopped .String () {
51
- return report , nil
51
+ return report , false , nil
52
52
}
53
53
}
54
54
55
55
//FIX: For the moment, we trigger outgoing hooks on success
56
56
for _ , p := range parentNodeRun {
57
57
if p .Status != sdk .StatusSuccess .String () {
58
- return report , nil
58
+ return report , false , nil
59
59
}
60
60
}
61
61
62
62
srvs , err := services .FindByType (db , services .TypeHooks )
63
63
if err != nil {
64
- return nil , sdk .WrapError (err , "Cannot get hooks service" )
64
+ return nil , false , sdk .WrapError (err , "Cannot get hooks service" )
65
65
}
66
66
67
67
mapParams := map [string ]string {}
@@ -101,6 +101,11 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
101
101
OutgoingHook : node .OutGoingHookContext ,
102
102
}
103
103
104
+ if ! checkNodeRunCondition (wr , node .Context .Conditions , hookRun .BuildParameters ) {
105
+ log .Debug ("Condition failed %d/%d %+v" , wr .ID , node .ID , hookRun .BuildParameters )
106
+ return report , false , nil
107
+ }
108
+
104
109
var task sdk.Task
105
110
if _ , err := services .DoJSONRequest (ctx , srvs , "POST" , "/task/execute" , hookRun , & task ); err != nil {
106
111
log .Warning ("outgoing hook execution failed: %v" , err )
@@ -113,7 +118,7 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
113
118
}
114
119
115
120
if err := insertWorkflowNodeRun (db , & hookRun ); err != nil {
116
- return nil , sdk .WrapError (err , "unable to insert run (node id : %d, node name : %s, subnumber : %d)" , hookRun .WorkflowNodeID , hookRun .WorkflowNodeName , hookRun .SubNumber )
121
+ return nil , true , sdk .WrapError (err , "unable to insert run (node id : %d, node name : %s, subnumber : %d)" , hookRun .WorkflowNodeID , hookRun .WorkflowNodeName , hookRun .SubNumber )
117
122
}
118
123
wr .LastExecution = time .Now ()
119
124
@@ -125,7 +130,7 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
125
130
}
126
131
127
132
if err := UpdateNodeRunBuildParameters (db , hookRun .ID , hookRun .BuildParameters ); err != nil {
128
- return nil , sdk .WrapError (err , "unable to update workflow node run build parameters" )
133
+ return nil , true , sdk .WrapError (err , "unable to update workflow node run build parameters" )
129
134
}
130
135
}
131
136
@@ -147,8 +152,8 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
147
152
wr .LastSubNumber = MaxSubNumber (wr .WorkflowNodeRuns )
148
153
149
154
if err := UpdateWorkflowRun (ctx , db , wr ); err != nil {
150
- return nil , sdk .WrapError (err , "unable to update workflow run" )
155
+ return nil , true , sdk .WrapError (err , "unable to update workflow run" )
151
156
}
152
157
153
- return report , nil
158
+ return report , true , nil
154
159
}
0 commit comments