Skip to content

Commit e67c3b7

Browse files
Merge pull request #6407 from devtron-labs/webhook-manual-cd-fix
fix: auto pre-cd not getting triggered (if cd is manual) after webhook ci event is captured
2 parents efb8fe6 + 60e6fc9 commit e67c3b7

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

internal/sql/repository/pipelineConfig/PipelineRepository.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func (t TriggerType) ToString() string {
4444
return string(t)
4545
}
4646

47+
func (t TriggerType) IsManual() bool {
48+
return t == TRIGGER_TYPE_MANUAL
49+
}
50+
51+
func (t TriggerType) IsAuto() bool {
52+
return t == TRIGGER_TYPE_AUTOMATIC
53+
}
54+
4755
const TRIGGER_TYPE_AUTOMATIC TriggerType = "AUTOMATIC"
4856
const TRIGGER_TYPE_MANUAL TriggerType = "MANUAL"
4957

@@ -59,8 +67,8 @@ type Pipeline struct {
5967
Deleted bool `sql:"deleted,notnull"`
6068
PreStageConfig string `sql:"pre_stage_config_yaml"`
6169
PostStageConfig string `sql:"post_stage_config_yaml"`
62-
PreTriggerType TriggerType `sql:"pre_trigger_type"` // automatic, manual
63-
PostTriggerType TriggerType `sql:"post_trigger_type"` // automatic, manual
70+
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
71+
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
6472
PreStageConfigMapSecretNames string `sql:"pre_stage_config_map_secret_names"` // configmap names
6573
PostStageConfigMapSecretNames string `sql:"post_stage_config_map_secret_names"` // secret names
6674
RunPreStageInEnv bool `sql:"run_pre_stage_in_env"` // secret names

pkg/workflow/dag/WorkflowDagExecutor.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ func (impl *WorkflowDagExecutorImpl) handleWebhookExternalCiEvent(artifact *repo
472472
err = &util.ApiError{Code: "401", HttpStatusCode: 401, UserMessage: "Unauthorized"}
473473
return hasAnyTriggered, err
474474
}
475-
if pipeline.TriggerType == pipelineConfig.TRIGGER_TYPE_MANUAL {
475+
isQualifiedForCdAutoTrigger := helper.IsCdQualifiedForAutoTriggerForWebhookCiEvent(pipeline)
476+
if !isQualifiedForCdAutoTrigger {
476477
impl.logger.Warnw("skipping deployment for manual trigger for webhook", "pipeline", pipeline)
477478
continue
478479
}

pkg/workflow/dag/helper/helper.go

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"github.com/devtron-labs/devtron/internal/sql/repository"
7+
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
78
)
89

910
func GetMaterialInfoJson(materialInfo json.RawMessage) ([]byte, error) {
@@ -29,3 +30,18 @@ func UpdateScanStatusInCiArtifact(ciArtifact *repository.CiArtifact, isScanPlugi
2930
ciArtifact.Scanned = true
3031
}
3132
}
33+
34+
// IsCdQualifiedForAutoTriggerForWebhookCiEvent returns bool, if a cd/pre-cd is qualified for auto trigger for a webhook ci event
35+
func IsCdQualifiedForAutoTriggerForWebhookCiEvent(pipeline *pipelineConfig.Pipeline) bool {
36+
/*
37+
A cd is qualified for auto trigger for webhookCiEvent if it satisfies below two conditions:-
38+
1. If pre-cd exists and is set on auto.
39+
2. If only cd exists and is set on auto.
40+
*/
41+
if len(pipeline.PreTriggerType) > 0 && pipeline.PreTriggerType.IsAuto() {
42+
return true
43+
} else if len(pipeline.PreTriggerType) == 0 && pipeline.TriggerType.IsAuto() {
44+
return true
45+
}
46+
return false
47+
}

0 commit comments

Comments
 (0)