Add server configuration option to add default set of labels for workflows that has no labels specified (#4326)

This commit is contained in:
Lauris BH
2024-11-14 23:23:42 +02:00
committed by GitHub
parent 1c7728fae3
commit 5699d22a55
6 changed files with 53 additions and 23 deletions

View File

@@ -173,6 +173,11 @@ var flags = append([]cli.Flag{
Usage: "The maximum time in minutes you can set in the repo settings before a pipeline gets killed",
Value: 120,
},
&cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_DEFAULT_WORKFLOW_LABELS"),
Name: "default-workflow-labels",
Usage: "The default label filter to set for workflows that has no label filter set. By default workflows will be allowed to run on any agent, if not specified in the workflow.",
},
&cli.DurationFlag{
Sources: cli.EnvVars("WOODPECKER_SESSION_EXPIRES"),
Name: "session-expires",

View File

@@ -188,6 +188,17 @@ func setupEvilGlobals(ctx context.Context, c *cli.Command, s store.Store) (err e
server.Config.Pipeline.DefaultTimeout = c.Int("default-pipeline-timeout")
server.Config.Pipeline.MaxTimeout = c.Int("max-pipeline-timeout")
_labels := c.StringSlice("default-workflow-labels")
labels := make(map[string]string, len(_labels))
for _, v := range _labels {
name, value, ok := strings.Cut(v, "=")
if !ok {
return fmt.Errorf("invalid label filter: %s", v)
}
labels[name] = value
}
server.Config.Pipeline.DefaultWorkflowLabels = labels
// backend options for pipeline compiler
server.Config.Pipeline.Proxy.No = c.String("backend-no-proxy")
server.Config.Pipeline.Proxy.HTTP = c.String("backend-http-proxy")