You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-16 08:46:30 +02:00
inject globals
This commit is contained in:
@@ -2,7 +2,6 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -23,24 +22,9 @@ type EnvironStore interface {
|
|||||||
// Environ represents an environment variable.
|
// Environ represents an environment variable.
|
||||||
// swagger:model environ
|
// swagger:model environ
|
||||||
type Environ struct {
|
type Environ struct {
|
||||||
ID int64 `json:"id" meddler:"env_id,pk"`
|
ID int64 `json:"id" meddler:"env_id,pk"`
|
||||||
Name string `json:"name" meddler:"env_name"`
|
Name string `json:"name" meddler:"env_name"`
|
||||||
Value string `json:"value,omitempty" meddler:"env_value"`
|
Value string `json:"value,omitempty" meddler:"env_value"`
|
||||||
Images []string `json:"image" meddler:"env_images,json"`
|
|
||||||
Events []string `json:"event" meddler:"env_events,json"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match returns true if an image and event match the restricted list.
|
|
||||||
func (e *Environ) Match(event string) bool {
|
|
||||||
if len(e.Events) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
for _, pattern := range e.Events {
|
|
||||||
if match, _ := filepath.Match(pattern, event); match {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the required fields and formats.
|
// Validate validates the required fields and formats.
|
||||||
@@ -58,9 +42,7 @@ func (e *Environ) Validate() error {
|
|||||||
// Copy makes a copy of the environment variable without the value.
|
// Copy makes a copy of the environment variable without the value.
|
||||||
func (e *Environ) Copy() *Environ {
|
func (e *Environ) Copy() *Environ {
|
||||||
return &Environ{
|
return &Environ{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
Images: e.Images,
|
|
||||||
Events: e.Events,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -205,6 +205,13 @@ func PostApproval(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
|
envs := map[string]string{}
|
||||||
|
if Config.Services.Environ != nil {
|
||||||
|
globals, _ := Config.Services.Environ.EnvironList(repo)
|
||||||
|
for _, global := range globals {
|
||||||
|
envs[global.Name] = global.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number)
|
uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number)
|
||||||
@@ -223,6 +230,7 @@ func PostApproval(c *gin.Context) {
|
|||||||
Regs: regs,
|
Regs: regs,
|
||||||
Link: httputil.GetURL(c.Request),
|
Link: httputil.GetURL(c.Request),
|
||||||
Yaml: conf.Data,
|
Yaml: conf.Data,
|
||||||
|
Envs: envs,
|
||||||
}
|
}
|
||||||
items, err := b.Build()
|
items, err := b.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -484,6 +492,12 @@ func PostBuild(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
|
if Config.Services.Environ != nil {
|
||||||
|
globals, _ := Config.Services.Environ.EnvironList(repo)
|
||||||
|
for _, global := range globals {
|
||||||
|
buildParams[global.Name] = global.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b := builder{
|
b := builder{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
@@ -201,6 +201,14 @@ func PostHook(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
envs := map[string]string{}
|
||||||
|
if Config.Services.Environ != nil {
|
||||||
|
globals, _ := Config.Services.Environ.EnvironList(repo)
|
||||||
|
for _, global := range globals {
|
||||||
|
envs[global.Name] = global.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
secs, err := Config.Services.Secrets.SecretListBuild(repo, build)
|
secs, err := Config.Services.Secrets.SecretListBuild(repo, build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
@@ -234,6 +242,7 @@ func PostHook(c *gin.Context) {
|
|||||||
Netrc: netrc,
|
Netrc: netrc,
|
||||||
Secs: secs,
|
Secs: secs,
|
||||||
Regs: regs,
|
Regs: regs,
|
||||||
|
Envs: envs,
|
||||||
Link: httputil.GetURL(c.Request),
|
Link: httputil.GetURL(c.Request),
|
||||||
Yaml: conf.Data,
|
Yaml: conf.Data,
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ var Config = struct {
|
|||||||
Senders model.SenderService
|
Senders model.SenderService
|
||||||
Secrets model.SecretService
|
Secrets model.SecretService
|
||||||
Registries model.RegistryService
|
Registries model.RegistryService
|
||||||
|
Environ model.EnvironService
|
||||||
}
|
}
|
||||||
Storage struct {
|
Storage struct {
|
||||||
// Users model.UserStore
|
// Users model.UserStore
|
||||||
|
Reference in New Issue
Block a user