mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 11:51:02 +00:00
enable globals (#2091)
* fixes #1523 to ensure json-file driver * added environment * inject globals
This commit is contained in:
parent
daa23ce673
commit
dab3f0a9f9
4 changed files with 72 additions and 0 deletions
48
model/environ.go
Normal file
48
model/environ.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
errEnvironNameInvalid = errors.New("Invalid Environment Variable Name")
|
||||
errEnvironValueInvalid = errors.New("Invalid Environment Variable Value")
|
||||
)
|
||||
|
||||
// EnvironService defines a service for managing environment variables.
|
||||
type EnvironService interface {
|
||||
EnvironList(*Repo) ([]*Environ, error)
|
||||
}
|
||||
|
||||
// EnvironStore persists environment information to storage.
|
||||
type EnvironStore interface {
|
||||
EnvironList(*Repo) ([]*Environ, error)
|
||||
}
|
||||
|
||||
// Environ represents an environment variable.
|
||||
// swagger:model environ
|
||||
type Environ struct {
|
||||
ID int64 `json:"id" meddler:"env_id,pk"`
|
||||
Name string `json:"name" meddler:"env_name"`
|
||||
Value string `json:"value,omitempty" meddler:"env_value"`
|
||||
}
|
||||
|
||||
// Validate validates the required fields and formats.
|
||||
func (e *Environ) Validate() error {
|
||||
switch {
|
||||
case len(e.Name) == 0:
|
||||
return errEnvironNameInvalid
|
||||
case len(e.Value) == 0:
|
||||
return errEnvironValueInvalid
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Copy makes a copy of the environment variable without the value.
|
||||
func (e *Environ) Copy() *Environ {
|
||||
return &Environ{
|
||||
ID: e.ID,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
|
@ -205,6 +205,13 @@ func PostApproval(c *gin.Context) {
|
|||
if err != nil {
|
||||
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() {
|
||||
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,
|
||||
Link: httputil.GetURL(c.Request),
|
||||
Yaml: conf.Data,
|
||||
Envs: envs,
|
||||
}
|
||||
items, err := b.Build()
|
||||
if err != nil {
|
||||
|
@ -484,6 +492,12 @@ func PostBuild(c *gin.Context) {
|
|||
if err != nil {
|
||||
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{
|
||||
Repo: repo,
|
||||
|
|
|
@ -201,6 +201,14 @@ func PostHook(c *gin.Context) {
|
|||
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)
|
||||
if err != nil {
|
||||
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,
|
||||
Secs: secs,
|
||||
Regs: regs,
|
||||
Envs: envs,
|
||||
Link: httputil.GetURL(c.Request),
|
||||
Yaml: conf.Data,
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ var Config = struct {
|
|||
Senders model.SenderService
|
||||
Secrets model.SecretService
|
||||
Registries model.RegistryService
|
||||
Environ model.EnvironService
|
||||
}
|
||||
Storage struct {
|
||||
// Users model.UserStore
|
||||
|
|
Loading…
Reference in a new issue