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

View file

@ -64,6 +64,11 @@ var flags = []cli.Flag{
Usage: "backend engine to run pipelines on",
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

View file

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