mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-16 14:12:45 +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:
@@ -87,11 +87,11 @@ type (
|
||||
|
||||
// System defines runtime metadata for a ci/cd system.
|
||||
System struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
Arch string `json:"arch,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
Platform string `json:"arch,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -179,11 +179,13 @@ func (m *Metadata) Environ() map[string]string {
|
||||
"CI_PREV_BUILD_STARTED": strconv.FormatInt(m.Prev.Started, 10),
|
||||
"CI_PREV_BUILD_FINISHED": strconv.FormatInt(m.Prev.Finished, 10),
|
||||
|
||||
"CI_SYSTEM_NAME": m.Sys.Name,
|
||||
"CI_SYSTEM_LINK": m.Sys.Link,
|
||||
"CI_SYSTEM_HOST": m.Sys.Host,
|
||||
"CI_SYSTEM_ARCH": m.Sys.Arch,
|
||||
"CI_SYSTEM_VERSION": version.Version,
|
||||
"CI_SYSTEM_NAME": m.Sys.Name,
|
||||
"CI_SYSTEM_LINK": m.Sys.Link,
|
||||
"CI_SYSTEM_HOST": m.Sys.Host,
|
||||
"CI_SYSTEM_PLATFORM": m.Sys.Platform, // will be set by pipeline platform option or by agent
|
||||
"CI_SYSTEM_VERSION": version.Version,
|
||||
|
||||
"CI_SYSTEM_ARCH": m.Sys.Platform, // TODO: remove after next version
|
||||
}
|
||||
if m.Curr.Event == EventTag {
|
||||
params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/")
|
||||
@@ -198,5 +200,5 @@ func (m *Metadata) Environ() map[string]string {
|
||||
var pullRegexp = regexp.MustCompile(`\d+`)
|
||||
|
||||
func (m *Metadata) SetPlatform(platform string) {
|
||||
m.Sys.Arch = platform
|
||||
m.Sys.Platform = platform
|
||||
}
|
||||
|
@@ -92,7 +92,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||
})
|
||||
|
||||
// create a default network
|
||||
if strings.HasPrefix(c.metadata.Sys.Arch, windowsPrefix) {
|
||||
if strings.HasPrefix(c.metadata.Sys.Platform, windowsPrefix) {
|
||||
config.Networks = append(config.Networks, &backend.Network{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
Driver: networkDriverNAT,
|
||||
|
@@ -78,7 +78,7 @@ func (c *Compiler) createProcess(name string, container *yaml.Container, section
|
||||
}
|
||||
|
||||
if len(container.Commands) != 0 {
|
||||
if c.metadata.Sys.Arch == "windows/amd64" {
|
||||
if c.metadata.Sys.Platform == "windows/amd64" {
|
||||
entrypoint = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
|
||||
command = []string{"[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"}
|
||||
environment["CI_SCRIPT"] = generateScriptWindows(container.Commands)
|
||||
|
@@ -50,7 +50,7 @@ type (
|
||||
// Match returns true if all constraints match the given input. If a single
|
||||
// constraint fails a false value is returned.
|
||||
func (c *Constraints) Match(metadata frontend.Metadata) bool {
|
||||
match := c.Platform.Match(metadata.Sys.Arch) &&
|
||||
match := c.Platform.Match(metadata.Sys.Platform) &&
|
||||
c.Environment.Match(metadata.Curr.Target) &&
|
||||
c.Event.Match(metadata.Curr.Event) &&
|
||||
c.Repo.Match(metadata.Repo.Name) &&
|
||||
|
@@ -440,12 +440,12 @@ func TestConstraints(t *testing.T) {
|
||||
// platform constraint
|
||||
{
|
||||
conf: "{ platform: linux/amd64 }",
|
||||
with: frontend.Metadata{Sys: frontend.System{Arch: "linux/amd64"}},
|
||||
with: frontend.Metadata{Sys: frontend.System{Platform: "linux/amd64"}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
conf: "{ repo: linux/amd64 }",
|
||||
with: frontend.Metadata{Sys: frontend.System{Arch: "windows/amd64"}},
|
||||
with: frontend.Metadata{Sys: frontend.System{Platform: "windows/amd64"}},
|
||||
want: false,
|
||||
},
|
||||
// instance constraint
|
||||
|
Reference in New Issue
Block a user