Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/sql/repository/pipelineConfig/PipelineRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func (t TriggerType) ToString() string {
return string(t)
}

func (t TriggerType) IsManual() bool {
return t == TRIGGER_TYPE_MANUAL
}

func (t TriggerType) IsAuto() bool {
return t == TRIGGER_TYPE_AUTOMATIC
}

const TRIGGER_TYPE_AUTOMATIC TriggerType = "AUTOMATIC"
const TRIGGER_TYPE_MANUAL TriggerType = "MANUAL"

Expand All @@ -59,8 +67,8 @@ type Pipeline struct {
Deleted bool `sql:"deleted,notnull"`
PreStageConfig string `sql:"pre_stage_config_yaml"`
PostStageConfig string `sql:"post_stage_config_yaml"`
PreTriggerType TriggerType `sql:"pre_trigger_type"` // automatic, manual
PostTriggerType TriggerType `sql:"post_trigger_type"` // automatic, manual
PreTriggerType TriggerType `sql:"pre_trigger_type"` // automatic, manual; when a pre-cd task doesn't exist/removed in a cd then this field is updated as null
PostTriggerType TriggerType `sql:"post_trigger_type"` // automatic, manual; when a post-cd task doesn't exist/removed in a cd then this field is updated as null
PreStageConfigMapSecretNames string `sql:"pre_stage_config_map_secret_names"` // configmap names
PostStageConfigMapSecretNames string `sql:"post_stage_config_map_secret_names"` // secret names
RunPreStageInEnv bool `sql:"run_pre_stage_in_env"` // secret names
Expand Down
3 changes: 2 additions & 1 deletion pkg/workflow/dag/WorkflowDagExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ func (impl *WorkflowDagExecutorImpl) handleWebhookExternalCiEvent(artifact *repo
err = &util.ApiError{Code: "401", HttpStatusCode: 401, UserMessage: "Unauthorized"}
return hasAnyTriggered, err
}
if pipeline.TriggerType == pipelineConfig.TRIGGER_TYPE_MANUAL {
isQualifiedForCdAutoTrigger := helper.IsCdQualifiedForAutoTriggerForWebhookCiEvent(pipeline)
if !isQualifiedForCdAutoTrigger {
impl.logger.Warnw("skipping deployment for manual trigger for webhook", "pipeline", pipeline)
continue
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/workflow/dag/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"github.com/devtron-labs/devtron/internal/sql/repository"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
)

func GetMaterialInfoJson(materialInfo json.RawMessage) ([]byte, error) {
Expand All @@ -29,3 +30,18 @@ func UpdateScanStatusInCiArtifact(ciArtifact *repository.CiArtifact, isScanPlugi
ciArtifact.Scanned = true
}
}

// IsCdQualifiedForAutoTriggerForWebhookCiEvent returns bool, if a cd/pre-cd is qualified for auto trigger for a webhook ci event
func IsCdQualifiedForAutoTriggerForWebhookCiEvent(pipeline *pipelineConfig.Pipeline) bool {
/*
A cd is qualified for auto trigger for webhookCiEvent if it satisfies below two conditions:-
1. If pre-cd exists and is set on auto.
2. If only cd exists and is set on auto.
*/
if len(pipeline.PreTriggerType) > 0 && pipeline.PreTriggerType.IsAuto() {
return true
} else if len(pipeline.PreTriggerType) == 0 && pipeline.TriggerType.IsAuto() {
return true
}
return false
}
Loading