fix: improve environment variable handling in debug mode

- Add a check for non-empty environment variables when debug mode is enabled
- Remove redundant environment variable output in tests

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2024-07-14 15:22:25 +08:00
parent 366c76f84c
commit 36fb3cb455
No known key found for this signature in database
2 changed files with 1 additions and 7 deletions

View File

@ -125,7 +125,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
p.Config.Script = append(env, p.scriptCommands()...)
if p.Config.Debug {
if p.Config.Debug && len(env) > 0 {
p.log(host, "======ENV======")
p.log(host, strings.Join(env, "\n"))
p.log(host, "======END======")

View File

@ -365,9 +365,6 @@ func TestCommandOutput(t *testing.T) {
whoami
uname
localhost: ======END======
localhost: ======ENV======
localhost:
localhost: ======END======
localhost: out: /home/drone-scp
localhost: out: drone-scp
localhost: out: Linux
@ -376,9 +373,6 @@ func TestCommandOutput(t *testing.T) {
whoami
uname
127.0.0.1: ======END======
127.0.0.1: ======ENV======
127.0.0.1:
127.0.0.1: ======END======
127.0.0.1: out: /home/drone-scp
127.0.0.1: out: drone-scp
127.0.0.1: out: Linux