Support secrets in cli exec (#5374)

This commit is contained in:
qwerty287 2025-07-31 07:13:07 +03:00 committed by GitHub
parent eced1ee886
commit 12cd608150
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 8 deletions

View file

@ -18,6 +18,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"maps"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -146,9 +147,9 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax
} }
environ := metadata.Environ() environ := metadata.Environ()
maps.Copy(environ, metadata.Workflow.Matrix)
var secrets []compiler.Secret var secrets []compiler.Secret
for key, val := range metadata.Workflow.Matrix { for key, val := range c.StringMap("secrets") {
environ[key] = val
secrets = append(secrets, compiler.Secret{ secrets = append(secrets, compiler.Secret{
Name: key, Name: key,
Value: val, Value: val,

View file

@ -64,6 +64,11 @@ var flags = []cli.Flag{
Usage: "backend engine to run pipelines on", Usage: "backend engine to run pipelines on",
Value: "auto-detect", Value: "auto-detect",
}, },
&cli.StringMapFlag{
Sources: cli.EnvVars("WOODPECKER_SECRETS"),
Name: "secrets",
Usage: "map of secrets, ex. 'secret=\"val\",secret2=\"value2\"'",
},
// //
// backend options for pipeline compiler // backend options for pipeline compiler

View file

@ -15,6 +15,7 @@
package compiler package compiler
import ( import (
"maps"
"net/url" "net/url"
"path" "path"
"strings" "strings"
@ -74,9 +75,7 @@ func WithMetadata(metadata metadata.Metadata) Option {
return func(compiler *Compiler) { return func(compiler *Compiler) {
compiler.metadata = metadata compiler.metadata = metadata
for k, v := range metadata.Environ() { maps.Copy(compiler.env, metadata.Environ())
compiler.env[k] = v
}
} }
} }
@ -143,9 +142,7 @@ func WithLocal(local bool) Option {
// added by default to every container in the pipeline. // added by default to every container in the pipeline.
func WithEnviron(env map[string]string) Option { func WithEnviron(env map[string]string) Option {
return func(compiler *Compiler) { return func(compiler *Compiler) {
for k, v := range env { maps.Copy(compiler.env, env)
compiler.env[k] = v
}
} }
} }