mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 21:03:22 +00:00
Add agent tagging / filtering for pipelines (#902)
Officially support labels for pipelines and agents to improve pipeline picking. * add pipeline labels * update, improve docs and add migration * update proto file --- closes #304 & #860
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
@@ -39,18 +40,26 @@ import (
|
||||
)
|
||||
|
||||
func loop(c *cli.Context) error {
|
||||
filter := rpc.Filter{
|
||||
Labels: map[string]string{
|
||||
"platform": runtime.GOOS + "/" + runtime.GOARCH,
|
||||
},
|
||||
Expr: c.String("filter"),
|
||||
}
|
||||
|
||||
hostname := c.String("hostname")
|
||||
if len(hostname) == 0 {
|
||||
hostname, _ = os.Hostname()
|
||||
}
|
||||
|
||||
labels := map[string]string{
|
||||
"hostname": hostname,
|
||||
"platform": runtime.GOOS + "/" + runtime.GOARCH,
|
||||
"repo": "*", // allow all repos by default
|
||||
}
|
||||
|
||||
for _, v := range c.StringSlice("filter-labels") {
|
||||
parts := strings.SplitN(v, "=", 2)
|
||||
labels[parts[0]] = parts[1]
|
||||
}
|
||||
|
||||
filter := rpc.Filter{
|
||||
Labels: labels,
|
||||
}
|
||||
|
||||
if c.Bool("pretty") {
|
||||
log.Logger = log.Output(
|
||||
zerolog.ConsoleWriter{
|
||||
|
@@ -72,10 +72,10 @@ var flags = []cli.Flag{
|
||||
Name: "hostname",
|
||||
Usage: "agent hostname",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
EnvVars: []string{"WOODPECKER_FILTER"},
|
||||
&cli.StringSliceFlag{
|
||||
EnvVars: []string{"WOODPECKER_FILTER_LABELS"},
|
||||
Name: "filter",
|
||||
Usage: "filter expression to restrict builds by label",
|
||||
Usage: "List of labels to filter tasks on. An agent must be assigned every tag listed in a task to be selected.",
|
||||
},
|
||||
&cli.IntFlag{
|
||||
EnvVars: []string{"WOODPECKER_MAX_PROCS"},
|
||||
|
Reference in New Issue
Block a user