@@ -104,7 +104,7 @@ type TriggerService interface {
104104	TriggerPostStage (request  bean.TriggerRequest ) (* bean4.ManifestPushTemplate , error )
105105	TriggerPreStage (request  bean.TriggerRequest ) (* bean4.ManifestPushTemplate , error )
106106
107- 	TriggerAutoCDOnPreStageSuccess (triggerContext  bean.TriggerContext , cdPipelineId , ciArtifactId , workflowId  int ,  triggerdBy   int32 ) error 
107+ 	TriggerAutoCDOnPreStageSuccess (triggerContext  bean.TriggerContext , cdPipelineId , ciArtifactId , workflowId  int ) error 
108108
109109	TriggerStageForBulk (triggerRequest  bean.TriggerRequest ) error 
110110
@@ -646,7 +646,7 @@ func (impl *TriggerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerR
646646		WorkflowType : bean3 .CD_WORKFLOW_TYPE_DEPLOY ,
647647		ExecutorType : cdWorkflow .WORKFLOW_EXECUTOR_TYPE_SYSTEM ,
648648		Status :       cdWorkflow .WorkflowInitiated , // deployment Initiated for auto trigger 
649- 		TriggeredBy :  1 ,
649+ 		TriggeredBy :  triggeredBy ,
650650		StartedOn :    triggeredAt ,
651651		Namespace :    impl .config .GetDefaultNamespace (),
652652		CdWorkflowId : cdWf .Id ,
@@ -677,13 +677,12 @@ func (impl *TriggerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerR
677677		impl .logger .Errorw ("error in fetching environment deployment config by appId and envId" , "appId" , pipeline .AppId , "envId" , pipeline .EnvironmentId , "err" , err )
678678		return  err 
679679	}
680- 	// setting triggeredBy as 1(system user) since case of auto trigger 
681- 	validationErr  :=  impl .validateDeploymentTriggerRequest (ctx , adapter .NewValidateDeploymentTriggerObj (runner , pipeline , artifact .ImageDigest , envDeploymentConfig , 1 , false ))
680+ 	validationErr  :=  impl .validateDeploymentTriggerRequest (ctx , adapter .NewValidateDeploymentTriggerObj (runner , pipeline , artifact .ImageDigest , envDeploymentConfig , triggeredBy , false ))
682681	if  validationErr  !=  nil  {
683682		impl .logger .Errorw ("validation error deployment request" , "cdWfr" , runner .Id , "err" , validationErr )
684683		return  validationErr 
685684	}
686- 	releaseErr  :=  impl .TriggerCD (ctx , artifact , cdWf .Id , savedWfr .Id , pipeline , envDeploymentConfig , triggeredAt )
685+ 	releaseErr  :=  impl .TriggerCD (ctx , artifact , cdWf .Id , savedWfr .Id , pipeline , envDeploymentConfig , triggeredAt ,  triggeredBy )
687686	// if releaseErr found, then the mark current deployment Failed and return 
688687	if  releaseErr  !=  nil  {
689688		err  :=  impl .cdWorkflowCommonService .MarkCurrentDeploymentFailed (runner , releaseErr , triggeredBy )
@@ -695,38 +694,38 @@ func (impl *TriggerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerR
695694	return  nil 
696695}
697696
698- func  (impl  * TriggerServiceImpl ) TriggerCD (ctx  context.Context , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , pipeline  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , triggeredAt  time.Time ) error  {
697+ func  (impl  * TriggerServiceImpl ) TriggerCD (ctx  context.Context , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , pipeline  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , triggeredAt  time.Time ,  triggeredBy   int32 ) error  {
699698	impl .logger .Debugw ("automatic pipeline trigger attempt async" , "artifactId" , artifact .Id )
700- 	err  :=  impl .triggerReleaseAsync (ctx , artifact , cdWorkflowId , wfrId , pipeline , envDeploymentConfig , triggeredAt )
699+ 	err  :=  impl .triggerReleaseAsync (ctx , artifact , cdWorkflowId , wfrId , pipeline , envDeploymentConfig , triggeredAt ,  triggeredBy )
701700	if  err  !=  nil  {
702701		impl .logger .Errorw ("error in cd trigger" , "err" , err )
703702		return  err 
704703	}
705704	return  err 
706705}
707706
708- func  (impl  * TriggerServiceImpl ) triggerReleaseAsync (ctx  context.Context , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , pipeline  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , triggeredAt  time.Time ) error  {
709- 	err  :=  impl .validateAndTrigger (ctx , pipeline , envDeploymentConfig , artifact , cdWorkflowId , wfrId , triggeredAt )
707+ func  (impl  * TriggerServiceImpl ) triggerReleaseAsync (ctx  context.Context , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , pipeline  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , triggeredAt  time.Time ,  triggeredBy   int32 ) error  {
708+ 	err  :=  impl .validateAndTrigger (ctx , pipeline , envDeploymentConfig , artifact , cdWorkflowId , wfrId , triggeredAt ,  triggeredBy )
710709	if  err  !=  nil  {
711710		impl .logger .Errorw ("error in trigger for pipeline" , "pipelineId" , strconv .Itoa (pipeline .Id ))
712711	}
713712	impl .logger .Debugw ("trigger attempted for all pipeline " , "artifactId" , artifact .Id )
714713	return  err 
715714}
716715
717- func  (impl  * TriggerServiceImpl ) validateAndTrigger (ctx  context.Context , p  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , triggeredAt  time.Time ) error  {
716+ func  (impl  * TriggerServiceImpl ) validateAndTrigger (ctx  context.Context , p  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , triggeredAt  time.Time ,  triggeredBy   int32 ) error  {
718717	//TODO: verify this logic 
719718	object  :=  impl .enforcerUtil .GetAppRBACNameByAppId (p .AppId )
720719	envApp  :=  strings .Split (object , "/" )
721720	if  len (envApp ) !=  2  {
722721		impl .logger .Error ("invalid req, app and env not found from rbac" )
723722		return  errors .New ("invalid req, app and env not found from rbac" )
724723	}
725- 	err  :=  impl .releasePipeline (ctx , p , envDeploymentConfig , artifact , cdWorkflowId , wfrId , triggeredAt )
724+ 	err  :=  impl .releasePipeline (ctx , p , envDeploymentConfig , artifact , cdWorkflowId , wfrId , triggeredAt ,  triggeredBy )
726725	return  err 
727726}
728727
729- func  (impl  * TriggerServiceImpl ) releasePipeline (ctx  context.Context , pipeline  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , triggeredAt  time.Time ) error  {
728+ func  (impl  * TriggerServiceImpl ) releasePipeline (ctx  context.Context , pipeline  * pipelineConfig.Pipeline , envDeploymentConfig  * bean9.DeploymentConfig , artifact  * repository3.CiArtifact , cdWorkflowId , wfrId  int , triggeredAt  time.Time ,  triggeredBy   int32 ) error  {
730729	startTime  :=  time .Now ()
731730	defer  func () {
732731		impl .logger .Debugw ("auto trigger release process completed" , "timeTaken" , time .Since (startTime ), "cdPipelineId" , pipeline .Id , "artifactId" , artifact .Id , "wfrId" , wfrId )
@@ -751,8 +750,7 @@ func (impl *TriggerServiceImpl) releasePipeline(ctx context.Context, pipeline *p
751750
752751	adapter .SetPipelineFieldsInOverrideRequest (request , pipeline , envDeploymentConfig )
753752
754- 	// setting deployedBy as 1(system user) since case of auto trigger 
755- 	id , _ , err  :=  impl .handleCDTriggerRelease (ctx , request , envDeploymentConfig , triggeredAt , 1 )
753+ 	id , _ , err  :=  impl .handleCDTriggerRelease (ctx , request , envDeploymentConfig , triggeredAt , triggeredBy )
756754	if  err  !=  nil  {
757755		impl .logger .Errorw ("error in auto  cd pipeline trigger" , "pipelineId" , pipeline .Id , "artifactId" , artifact .Id , "err" , err )
758756	} else  {
0 commit comments