diff --git a/cmd/server/openapi/docs.go b/cmd/server/openapi/docs.go index 4d45d973d..b86e7cd2b 100644 --- a/cmd/server/openapi/docs.go +++ b/cmd/server/openapi/docs.go @@ -4725,6 +4725,12 @@ const docTemplate = `{ "schedule": { "description": "@weekly,\t3min, ...", "type": "string" + }, + "variables": { + "type": "object", + "additionalProperties": { + "type": "string" + } } } }, @@ -4742,6 +4748,12 @@ const docTemplate = `{ }, "schedule": { "type": "string" + }, + "variables": { + "type": "object", + "additionalProperties": { + "type": "string" + } } } }, diff --git a/server/api/cron.go b/server/api/cron.go index b8d9ecfa5..119b22d36 100644 --- a/server/api/cron.go +++ b/server/api/cron.go @@ -128,6 +128,7 @@ func PostCron(c *gin.Context) { CreatorID: user.ID, Schedule: in.Schedule, Branch: in.Branch, + Variables: in.Variables, Enabled: in.Enabled, } if err := cron.Validate(); err != nil { @@ -231,6 +232,9 @@ func PatchCron(c *gin.Context) { cron.NextExec = nextExec.Unix() } } + if in.Variables != nil { + cron.Variables = in.Variables + } cron.CreatorID = user.ID if err := cron.Validate(); err != nil { diff --git a/server/cron/cron.go b/server/cron/cron.go index 3460fbaa4..5fc86f7f3 100644 --- a/server/cron/cron.go +++ b/server/cron/cron.go @@ -137,13 +137,14 @@ func CreatePipeline(ctx context.Context, store store.Store, cron *model.Cron) (* } return repo, &model.Pipeline{ - Event: model.EventCron, - Commit: commit.SHA, - Ref: "refs/heads/" + cron.Branch, - Branch: cron.Branch, - Message: cron.Name, - Timestamp: cron.NextExec, - Sender: cron.Name, - ForgeURL: commit.ForgeURL, + Event: model.EventCron, + Commit: commit.SHA, + Ref: "refs/heads/" + cron.Branch, + Branch: cron.Branch, + Message: cron.Name, + Timestamp: cron.NextExec, + Sender: cron.Name, + ForgeURL: commit.ForgeURL, + AdditionalVariables: cron.Variables, }, nil } diff --git a/server/model/cron.go b/server/model/cron.go index f865adf06..31086eab5 100644 --- a/server/model/cron.go +++ b/server/model/cron.go @@ -21,15 +21,16 @@ import ( ) type Cron struct { - ID int64 `json:"id" xorm:"pk autoincr 'id'"` - Name string `json:"name" xorm:"name UNIQUE(s) INDEX"` - RepoID int64 `json:"repo_id" xorm:"repo_id UNIQUE(s) INDEX"` - CreatorID int64 `json:"creator_id" xorm:"creator_id INDEX"` - NextExec int64 `json:"next_exec" xorm:"next_exec"` - Schedule string `json:"schedule" xorm:"schedule NOT NULL"` // @weekly, 3min, ... - Created int64 `json:"created" xorm:"created NOT NULL DEFAULT 0"` - Branch string `json:"branch" xorm:"branch"` - Enabled bool `json:"enabled" xorm:"enabled NOT NULL DEFAULT TRUE"` + ID int64 `json:"id" xorm:"pk autoincr 'id'"` + Name string `json:"name" xorm:"name UNIQUE(s) INDEX"` + RepoID int64 `json:"repo_id" xorm:"repo_id UNIQUE(s) INDEX"` + CreatorID int64 `json:"creator_id" xorm:"creator_id INDEX"` + NextExec int64 `json:"next_exec" xorm:"next_exec"` + Schedule string `json:"schedule" xorm:"schedule NOT NULL"` // @weekly, 3min, ... + Created int64 `json:"created" xorm:"created NOT NULL DEFAULT 0"` + Branch string `json:"branch" xorm:"branch"` + Enabled bool `json:"enabled" xorm:"enabled NOT NULL DEFAULT TRUE"` + Variables map[string]string `json:"variables" xorm:"json 'variables'"` } // @name Cron // TableName returns the database table name for xorm. @@ -56,8 +57,9 @@ func (c *Cron) Validate() error { } type CronPatch struct { - Name *string `json:"name"` - Schedule *string `json:"schedule"` - Branch *string `json:"branch"` - Enabled *bool `json:"enabled"` + Name *string `json:"name"` + Schedule *string `json:"schedule"` + Branch *string `json:"branch"` + Enabled *bool `json:"enabled"` + Variables map[string]string `json:"variables"` } // @name CronPatch diff --git a/web/src/lib/api/types/cron.ts b/web/src/lib/api/types/cron.ts index d58698563..1d5c13ced 100644 --- a/web/src/lib/api/types/cron.ts +++ b/web/src/lib/api/types/cron.ts @@ -5,4 +5,5 @@ export interface Cron { schedule: string; enabled: boolean; next_exec: number; + variables: Record; } diff --git a/web/src/views/repo/settings/Crons.vue b/web/src/views/repo/settings/Crons.vue index f5b9a8578..92c55dcbf 100644 --- a/web/src/views/repo/settings/Crons.vue +++ b/web/src/views/repo/settings/Crons.vue @@ -102,6 +102,18 @@ {{ $t('repo.settings.crons.not_executed_yet') }} + + {{ $t('repo.manual_pipeline.variables.desc') }} + + +
@@ -126,6 +139,7 @@ import IconButton from '~/components/atomic/IconButton.vue'; import ListItem from '~/components/atomic/ListItem.vue'; import Checkbox from '~/components/form/Checkbox.vue'; import InputField from '~/components/form/InputField.vue'; +import KeyValueEditor from '~/components/form/KeyValueEditor.vue'; import TextField from '~/components/form/TextField.vue'; import Settings from '~/components/layout/Settings.vue'; import useApiClient from '~/compositions/useApiClient'; @@ -147,6 +161,15 @@ const selectedCron = ref>(); const isEditingCron = computed(() => !!selectedCron.value?.id); const date = useDate(); +const selectedCronVariables = computed>({ + async set(_vars) { + selectedCron.value!.variables = _vars; + }, + get() { + return selectedCron.value!.variables !== undefined ? selectedCron.value!.variables : {}; + }, +}); + const selectedCronEnabled = computed({ async set(_enabled) { selectedCron.value!.enabled = _enabled; @@ -160,6 +183,12 @@ async function loadCrons(page: number): Promise { return apiClient.getCronList(repo.value.id, { page }); } +const isVariablesValid = ref(true); + +const isFormValid = computed(() => { + return isVariablesValid.value; +}); + const { resetPage, data: crons, loading } = usePagination(loadCrons, () => !selectedCron.value); const { doSubmit: createCron, isLoading: isSaving } = useAsyncAction(async () => {