Skip to content

Commit

Permalink
not set --env if thvariable is not present
Browse files Browse the repository at this point in the history
close containers#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 <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Jul 29, 2019
1 parent c3c45f3 commit 6e5a833
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmd/podman/shared/parse/parse.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/podman-create.1.md
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/podman-run.1.md
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/run_test.go
Expand Up @@ -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))
Expand Down

0 comments on commit 6e5a833

Please sign in to comment.