Merge branch 'origin/main' into 'next-release/main'

This commit is contained in:
oauth 2024-11-14 22:58:45 +00:00
commit fec418ba95
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", Usage: "The maximum time in minutes you can set in the repo settings before a pipeline gets killed",
Value: 120, 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{ &cli.DurationFlag{
Sources: cli.EnvVars("WOODPECKER_SESSION_EXPIRES"), Sources: cli.EnvVars("WOODPECKER_SESSION_EXPIRES"),
Name: "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.DefaultTimeout = c.Int("default-pipeline-timeout")
server.Config.Pipeline.MaxTimeout = c.Int("max-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 // backend options for pipeline compiler
server.Config.Pipeline.Proxy.No = c.String("backend-no-proxy") server.Config.Pipeline.Proxy.No = c.String("backend-no-proxy")
server.Config.Pipeline.Proxy.HTTP = c.String("backend-http-proxy") server.Config.Pipeline.Proxy.HTTP = c.String("backend-http-proxy")

View file

@ -357,6 +357,14 @@ The default docker image to be used when cloning the repo.
It is also added to the trusted clone plugin list. It is also added to the trusted clone plugin list.
### `WOODPECKER_DEFAULT_WORKFLOW_LABELS`
> By default run workflows on any agent if no label conditions are set in workflow definition.
You can specify default label/platform conditions that will be used for agent selection for workflows that does not have labels conditions set.
Example: `platform=linux/amd64,backend=docker`
### `WOODPECKER_DEFAULT_PIPELINE_TIMEOUT` ### `WOODPECKER_DEFAULT_PIPELINE_TIMEOUT`
> 60 (minutes) > 60 (minutes)

View file

@ -67,6 +67,7 @@ var Config = struct {
Pipeline struct { Pipeline struct {
AuthenticatePublicRepos bool AuthenticatePublicRepos bool
DefaultCancelPreviousPipelineEvents []model.WebhookEvent DefaultCancelPreviousPipelineEvents []model.WebhookEvent
DefaultWorkflowLabels map[string]string
DefaultClonePlugin string DefaultClonePlugin string
TrustedClonePlugins []string TrustedClonePlugins []string
Volumes []string Volumes []string

View file

@ -72,16 +72,17 @@ func parsePipeline(forge forge.Forge, store store.Store, currentPipeline *model.
} }
b := stepbuilder.StepBuilder{ b := stepbuilder.StepBuilder{
Repo: repo, Repo: repo,
Curr: currentPipeline, Curr: currentPipeline,
Prev: prev, Prev: prev,
Netrc: netrc, Netrc: netrc,
Secs: secs, Secs: secs,
Regs: regs, Regs: regs,
Envs: envs, Envs: envs,
Host: server.Config.Server.Host, Host: server.Config.Server.Host,
Yamls: yamls, Yamls: yamls,
Forge: forge, Forge: forge,
DefaultLabels: server.Config.Pipeline.DefaultWorkflowLabels,
ProxyOpts: compiler.ProxyOptions{ ProxyOpts: compiler.ProxyOptions{
NoProxy: server.Config.Pipeline.Proxy.No, NoProxy: server.Config.Pipeline.Proxy.No,
HTTPProxy: server.Config.Pipeline.Proxy.HTTP, HTTPProxy: server.Config.Pipeline.Proxy.HTTP,

View file

@ -17,6 +17,7 @@ package stepbuilder
import ( import (
"fmt" "fmt"
"maps"
"path/filepath" "path/filepath"
"strings" "strings"
@ -40,17 +41,18 @@ import (
// StepBuilder Takes the hook data and the yaml and returns in internal data model. // StepBuilder Takes the hook data and the yaml and returns in internal data model.
type StepBuilder struct { type StepBuilder struct {
Repo *model.Repo Repo *model.Repo
Curr *model.Pipeline Curr *model.Pipeline
Prev *model.Pipeline Prev *model.Pipeline
Netrc *model.Netrc Netrc *model.Netrc
Secs []*model.Secret Secs []*model.Secret
Regs []*model.Registry Regs []*model.Registry
Host string Host string
Yamls []*forge_types.FileMeta Yamls []*forge_types.FileMeta
Envs map[string]string Envs map[string]string
Forge metadata.ServerForge Forge metadata.ServerForge
ProxyOpts compiler.ProxyOptions DefaultLabels map[string]string
ProxyOpts compiler.ProxyOptions
} }
type Item struct { type Item struct {
@ -186,8 +188,10 @@ func (b *StepBuilder) genItemForWorkflow(workflow *model.Workflow, axis matrix.A
DependsOn: parsed.DependsOn, DependsOn: parsed.DependsOn,
RunsOn: parsed.RunsOn, RunsOn: parsed.RunsOn,
} }
if item.Labels == nil { if len(item.Labels) == 0 {
item.Labels = map[string]string{} item.Labels = make(map[string]string, len(b.DefaultLabels))
// Set default labels if no labels are defined in the pipeline
maps.Copy(item.Labels, b.DefaultLabels)
} }
return item, errorsAndWarnings return item, errorsAndWarnings