woodpecker/yaml/transform/plugin.go

48 lines
1.1 KiB
Go
Raw Normal View History

2016-05-09 18:28:49 +00:00
package transform
2016-05-10 05:57:57 +00:00
import (
"path/filepath"
2016-05-09 18:28:49 +00:00
2016-05-10 05:57:57 +00:00
"github.com/drone/drone/yaml"
)
// PluginDisable is a transform function that alters the Yaml configuration to
// disables plugins. This is intended for use when executing the pipeline
// locally on your own computer.
func PluginDisable(conf *yaml.Config, patterns []string) error {
2016-05-09 18:28:49 +00:00
for _, container := range conf.Pipeline {
2016-05-10 05:57:57 +00:00
if len(container.Commands) != 0 { // skip build steps
continue
}
var match bool
for _, pattern := range patterns {
if ok, _ := filepath.Match(pattern, container.Name); ok {
match = true
break
}
}
if !match {
container.Disabled = true
2016-05-09 18:28:49 +00:00
}
}
2016-05-10 05:57:57 +00:00
return nil
2016-05-09 18:28:49 +00:00
}
2016-05-10 05:57:57 +00:00
// PluginParams is a transform function that alters the Yaml configuration to
// include plugin vargs parameters as environment variables.
2016-05-10 05:57:57 +00:00
func PluginParams(conf *yaml.Config) error {
for _, container := range conf.Pipeline {
if len(container.Vargs) == 0 {
continue
}
if container.Environment == nil {
container.Environment = map[string]string{}
}
err := argsToEnv(container.Vargs, container.Environment)
if err != nil {
return err
}
}
return nil
}