From 6e5a833c1bf0f467b1c547aed1dd5673123ad2fe Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Mon, 29 Jul 2019 16:44:09 -0400 Subject: [PATCH] not set --env if thvariable is not present close #3648 podman create and podman run do not set --env value if the environment is not present with a value Signed-off-by: Qi Wang --- cmd/podman/shared/parse/parse.go | 5 +++-- docs/podman-create.1.md | 2 +- docs/podman-run.1.md | 2 +- test/e2e/run_test.go | 6 ++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/podman/shared/parse/parse.go b/cmd/podman/shared/parse/parse.go index 9fbc92fc3cae..3a75ff7a884d 100644 --- a/cmd/podman/shared/parse/parse.go +++ b/cmd/podman/shared/parse/parse.go @@ -126,8 +126,9 @@ func parseEnv(env map[string]string, line string) error { } } else { // if only a pass-through variable is given, clean it up. - val, _ := os.LookupEnv(name) - env[name] = val + if val, ok := os.LookupEnv(name); ok { + env[name] = val + } } } return nil diff --git a/docs/podman-create.1.md b/docs/podman-create.1.md index d796c2586164..e944c1086bad 100644 --- a/docs/podman-create.1.md +++ b/docs/podman-create.1.md @@ -253,7 +253,7 @@ You need to specify multi option commands in the form of a json string. Set environment variables -This option allows you to specify arbitrary environment variables that are available for the process that will be launched inside of the container. If you specify a environment variable without a value, podman will check the host environment for a value or set the environment to "". If you specify a environment variable ending in --*--, podman will search the host environment for variables starting with the prefix and add them to the container. If you want to add an environment variable with a ***** following it, then you need to set a value. +This option allows you to specify arbitrary environment variables that are available for the process that will be launched inside of the container. If you specify a environment variable without a value, podman will check the host environment for a value or not set the environment. If you specify a environment variable ending in --*--, podman will search the host environment for variables starting with the prefix and add them to the container. If you want to add an environment variable with a ***** following it, then you need to set a value. See **Environment** note below for precedence. diff --git a/docs/podman-run.1.md b/docs/podman-run.1.md index f5f44fad4782..f46a2a4d4f7e 100644 --- a/docs/podman-run.1.md +++ b/docs/podman-run.1.md @@ -260,7 +260,7 @@ You need to specify multi option commands in the form of a json string. Set environment variables -This option allows you to specify arbitrary environment variables that are available for the process that will be launched inside of the container. If you specify a environment variable without a value, podman will check the host environment for a value or set the environment to "". If you specify a environment variable ending in --*--, podman will search the host environment for variables starting with the prefix and add them to the container. If you want to add an environment variable with a ***** following it, then you need to set a value. +This option allows you to specify arbitrary environment variables that are available for the process that will be launched inside of the container. If you specify a environment variable without a value, podman will check the host environment for a value or not set the environment. If you specify a environment variable ending in --*--, podman will search the host environment for variables starting with the prefix and add them to the container. If you want to add an environment variable with a ***** following it, then you need to set a value. See **Environment** note below for precedence. diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index e35c84f5bbca..d7b7cd2e5b9a 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -213,6 +213,12 @@ var _ = Describe("Podman run", func() { Expect(match).Should(BeTrue()) os.Unsetenv("FOO") + session = podmanTest.Podman([]string{"run", "--rm", "--env", "FOO", ALPINE, "printenv", "FOO+test"}) + session.WaitWithDefaultTimeout() + fmt.Println(session.OutputToString()) + Expect(len(session.OutputToString())).To(Equal(0)) + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0))