diff --git a/engine/api/notification/user.go b/engine/api/notification/user.go index d035578404..326dbd9074 100644 --- a/engine/api/notification/user.go +++ b/engine/api/notification/user.go @@ -3,6 +3,7 @@ package notification import ( "context" "fmt" + "strings" "github.com/go-gorp/gorp" "github.com/rockbears/log" @@ -217,7 +218,17 @@ func getWorkflowEvent(notif *sdk.UserNotificationSettings, params map[string]str Subject: subject, Body: body, } - e.Recipients = append(e.Recipients, notif.Recipients...) + + var recipients []string + for i := range notif.Recipients { + r, err := interpolate.Do(notif.Recipients[i], params) + if err != nil { + return sdk.EventNotif{}, err + } + recipients = append(recipients, strings.Split(r, ",")...) + } + + e.Recipients = append(e.Recipients, recipients...) return e, nil } diff --git a/tests/04_sc_workflow_run_notif.yml b/tests/04_sc_workflow_run_notif.yml index c341509040..63f4d4eb5d 100644 --- a/tests/04_sc_workflow_run_notif.yml +++ b/tests/04_sc_workflow_run_notif.yml @@ -21,6 +21,7 @@ testcases: - script: "{{.cdsctl}} -f {{.cdsctl.config}} project remove --force 04SCWORKFLOWRUNNOTIF" - script: "{{.cdsctl}} -f {{.cdsctl.config}} group remove --force 04scworkflowrunnotif" - script: "{{.cdsctl}} -f {{.cdsctl.config}} project add 04SCWORKFLOWRUNNOTIF 04SCWorkflowRunNotif" + - script: "{{.cdsctl}} -f {{.cdsctl.config}} project variable add 04SCWORKFLOWRUNNOTIF email_notif string \"notif1@locahost.local,notif2@locahost.local\"" - name: import pipeline and workflow steps: @@ -69,6 +70,22 @@ testcases: verify: from: result.bodyjson.content-decoded regex: logcontent:foo2 + - type: http + method: GET + url: '{{.smtpmock.url}}/messages/notif1@locahost.local' + assertions: + - result.statuscode ShouldEqual 200 + - result.bodyjson.__len__ ShouldEqual 1 + retry: 10 + delay: 3 + - type: http + method: GET + url: '{{.smtpmock.url}}/messages/notif2@locahost.local' + assertions: + - result.statuscode ShouldEqual 200 + - result.bodyjson.__len__ ShouldEqual 1 + retry: 10 + delay: 3 - name: run workflow 04SCWorkflowRunNotif-WORKFLOW-EMPTY steps: diff --git a/tests/fixtures/04SCWorkflowRunNotif/workflow.yml b/tests/fixtures/04SCWorkflowRunNotif/workflow.yml index 38cf3f5003..1d686be845 100644 --- a/tests/fixtures/04SCWorkflowRunNotif/workflow.yml +++ b/tests/fixtures/04SCWorkflowRunNotif/workflow.yml @@ -13,6 +13,7 @@ notifications: on_success: always recipients: - notif@localhost.local + - "{{.cds.proj.email_notif}}" template: body: | title:{{.cds.project}}/{{.cds.workflow}}#{{.cds.version}} {{.cds.status}}