8000 fix(api): add conditions handling for outgoing hook (#3754) · ovh/cds@feb6221 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit feb6221

Browse files
bnjjjyesnault
authored andcommitted
fix(api): add conditions handling for outgoing hook (#3754)
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
1 parent 8ce1e8b commit feb6221

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

engine/api/workflow/execute_outgoing_hook_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func UpdateOutgoingHookRunStatus(ctx context.Context, db gorp.SqlExecutor, store
5050
mapNodes := wr.Workflow.WorkflowData.Maps()
5151
node := wr.Workflow.WorkflowData.NodeByID(nodeRun.WorkflowNodeID)
5252

53-
report1, err := processNodeOutGoingHook(ctx, db, store, proj, wr, mapNodes, nil, node, int(nodeRun.SubNumber))
53+
report1, _, err := processNodeOutGoingHook(ctx, db, store, proj, wr, mapNodes, nil, node, int(nodeRun.SubNumber))
5454
report.Merge(report1, err) //nolint
5555
if err != nil {
5656
return nil, sdk.WrapError(err, "Unable to processNodeOutGoingHook")

engine/api/workflow/process_node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ func processNodeRun(ctx context.Context, db gorp.SqlExecutor, store cache.Store,
8989
report.Merge(r1, nil) // nolint
9090
return report, conditionOK, nil
9191
case sdk.NodeTypeOutGoingHook:
92-
r1, errO := processNodeOutGoingHook(ctx, db, store, proj, wr, mapNodes, parentNodeRuns, n, subNumber)
92+
r1, conditionOK, errO := processNodeOutGoingHook(ctx, db, store, proj, wr, mapNodes, parentNodeRuns, n, subNumber)
9393
if errO != nil {
9494
return nil, false, sdk.WrapError(errO, "Unable to processNodeOutGoingHook")
9595
}
9696
report.Merge(r1, nil) // nolint
97-
return report, true, nil
97+
return report, conditionOK, nil
9898
}
9999
return nil, false, nil
100100
}

engine/api/workflow/process_outgoinghook.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/ovh/cds/sdk/log"
1616
)
1717

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) {
1919
ctx, end := observability.Span(ctx, "workflow.processNodeOutGoingHook")
2020
defer end()
2121

@@ -34,34 +34,34 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
3434
// If the hookrun is at status terminated, let's trigger outgoing children
3535
if exitingNodeRun != nil && !sdk.StatusIsTerminated(exitingNodeRun.Status) {
3636
log.Debug("hook %d already processed", node.ID)
37-
return nil, nil
37+
return nil, false, nil
3838
} else if exitingNodeRun != nil && exitingNodeRun.Status != sdk.StatusStopped.String() {
3939
log.Debug("hook %d is over, we have to reprocess al the things", node.ID)
4040
for i := range node.Triggers {
4141
t := &node.Triggers[i]
4242
log.Debug("checking trigger %+v", t)
4343
r1, err := processNodeTriggers(ctx, db, store, proj, wr, mapNodes, []*sdk.WorkflowNodeRun{exitingNodeRun}, node, subNumber)
4444
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")
4646
}
4747
report.Merge(r1, nil) // nolint
4848
}
49-
return report, nil
49+
return report, false, nil
5050
} else if exitingNodeRun != nil && exitingNodeRun.Status == sdk.StatusStopped.String() {
51-
return report, nil
51+
return report, false, nil
5252
}
5353
}
5454

5555
//FIX: For the moment, we trigger outgoing hooks on success
5656
for _, p := range parentNodeRun {
5757
if p.Status != sdk.StatusSuccess.String() {
58-
return report, nil
58+
return report, false, nil
5959
}
6060
}
6161

6262
srvs, err := services.FindByType(db, services.TypeHooks)
6363
if err != nil {
64-
return nil, sdk.WrapError(err, "Cannot get hooks service")
64+
return nil, false, sdk.WrapError(err, "Cannot get hooks service")
6565
}
6666

6767
mapParams := map[string]string{}
@@ -101,6 +101,11 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
101101
OutgoingHook: node.OutGoingHookContext,
102102
}
103103

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+
104109
var task sdk.Task
105110
if _, err := services.DoJSONRequest(ctx, srvs, "POST", "/task/execute", hookRun, &task); err != nil {
106111
log.Warning("outgoing hook execution failed: %v", err)
@@ -113,7 +118,7 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
113118
}
114119

115120
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)
117122
}
118123
wr.LastExecution = time.Now()
119124

@@ -125,7 +130,7 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
125130
}
126131

127132
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")
129134
}
130135
}
131136

@@ -147,8 +152,8 @@ func processNodeOutGoingHook(ctx context.Context, db gorp.SqlExecutor, store cac
147152
wr.LastSubNumber = MaxSubNumber(wr.WorkflowNodeRuns)
148153

149154
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")
151156
}
152157

153-
return report, nil
158+
return report, true, nil
154159
}

ui/src/app/shared/workflow/modal/trigger/workflow.trigger.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class WorkflowTriggerComponent {
4141
this.selectedType = t;
4242
this.isParent = isP;
4343
const config = new TemplateModalConfig<boolean, boolean, void>(this.triggerModal);
44+
config.mustScroll = true;
4445
this.modal = this._modalService.open(config);
4546
}
4647

0 commit comments

Comments
 (0)
0