@@ -15,6 +15,7 @@ import (
1515 "github.com/bmatcuk/doublestar"
1616 "github.com/SAP/jenkins-library/pkg/gcs"
1717 "github.com/SAP/jenkins-library/pkg/piperenv"
18+ "github.com/SAP/jenkins-library/pkg/events"
1819 "github.com/SAP/jenkins-library/pkg/gcp"
1920 "github.com/SAP/jenkins-library/pkg/telemetry"
2021 "github.com/SAP/jenkins-library/pkg/splunk"
@@ -249,14 +250,31 @@ func TestStepCommand() *cobra.Command {
249250 splunkClient.Send(telemetryClient.GetData(), logCollector)
250251 }
251252 if GeneralConfig.HookConfig.GCPPubSubConfig.Enabled {
252- err := gcp.NewGcpPubsubClient(
253+ log.Entry().Debug("publishing event to GCP Pub/Sub...")
254+ // prepare event payload
255+ payload := events.NewPayloadTaskRunFinished(
256+ telemetryClient.GetData().StageName,
257+ STEP_NAME,
258+ stepTelemetryData.ErrorCode,
259+ )
260+ // create event
261+ eventData, err := events.NewEventTaskRunFinished(
262+ piperOsCmd.GeneralConfig.HookConfig.GCPPubSubConfig.TypePrefix,
263+ piperOsCmd.GeneralConfig.HookConfig.GCPPubSubConfig.Source,
264+ payload,
265+ )
266+ // publish cloud event via GCP Pub/Sub
267+ err = gcp.NewGcpPubsubClient(
253268 vaultClient,
254- GeneralConfig.HookConfig.GCPPubSubConfig.ProjectNumber,
255- GeneralConfig.HookConfig.GCPPubSubConfig.IdentityPool,
256- GeneralConfig.HookConfig.GCPPubSubConfig.IdentityProvider,
257- GeneralConfig.CorrelationID,
258- GeneralConfig.HookConfig.OIDCConfig.RoleID,
259- ).Publish(GeneralConfig.HookConfig.GCPPubSubConfig.Topic, telemetryClient.GetDataBytes())
269+ piperOsCmd.GeneralConfig.HookConfig.GCPPubSubConfig.ProjectNumber,
270+ piperOsCmd.GeneralConfig.HookConfig.GCPPubSubConfig.IdentityPool,
271+ piperOsCmd.GeneralConfig.HookConfig.GCPPubSubConfig.IdentityProvider,
272+ piperOsCmd.GeneralConfig.CorrelationID,
273+ piperOsCmd.GeneralConfig.HookConfig.OIDCConfig.RoleID,
274+ ).Publish(
275+ fmt.Sprintf("%spipelinetaskrun-finished", piperOsCmd.GeneralConfig.HookConfig.GCPPubSubConfig.TopicPrefix),
276+ eventData,
277+ )
260278 if err != nil {
261279 log.Entry().WithError(err).Warn("event publish failed")
262280 }
0 commit comments