Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add os.Environ() for git commands environments #67

Merged
merged 1 commit into from
Apr 6, 2023
Merged

Add os.Environ() for git commands environments #67

merged 1 commit into from
Apr 6, 2023

Conversation

ambroisie
Copy link
Contributor

I run the local agent on NixOS, and without this fix the commands lose their PATH which means they can't execute any external tool (e.g: uname which is needed by some git commands, git-lfs)

@lafriks lafriks added the enhancement New feature or request label Apr 3, 2023
@6543 6543 added this to the v2.1.0 milestone Apr 4, 2023
@6543
Copy link
Member

6543 commented Apr 4, 2023

diff --git a/plugin.go b/plugin.go
index 0764543..101abc5 100644
--- a/plugin.go
+++ b/plugin.go
@@ -41,6 +41,9 @@ func (p Plugin) Exec() error {
                return err
        }
 
+       // set vars from exec environment
+       defaultEnvVars = append(os.Environ(), defaultEnvVars...)
+
        // alter home var for all commands exec afterwards
        if err := setHome(p.Config.Home); err != nil {
                return err
@@ -190,7 +193,7 @@ func retryExec(cmd *exec.Cmd, backoff time.Duration, retries int) (err error) {
 }
 
 func appendEnv(cmd *exec.Cmd, env ...string) *exec.Cmd {
-       cmd.Env = append(cmd.Environ(), env...)
+       cmd.Env = append(cmd.Env, env...)
        return cmd
 }

@6543
Copy link
Member

6543 commented Apr 4, 2023

strange it does build ... with my patch does that work too?

@ambroisie
Copy link
Contributor Author

That also works @6543.

@6543
Copy link
Member

6543 commented Apr 5, 2023

@ambroisie would you apply to make the linter happy?

@ambroisie
Copy link
Contributor Author

@6543 done.

@6543 6543 changed the title Do not overwrite command environment Add os.Environ() for git commands environments Apr 6, 2023
@6543 6543 merged commit 388c4cd into woodpecker-ci:master Apr 6, 2023
@woodpecker-bot woodpecker-bot mentioned this pull request Jul 12, 2023
@woodpecker-bot
Copy link
Contributor

🎉 This PR is included in version 2.1.0 🎉

The release is now available [here]([object Object])

Thank you for your contribution. ❤️📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants