diff --git a/pkg/build/build.go b/pkg/build/build.go index b95d75dd6..812844521 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -414,10 +414,18 @@ func (b *Builder) writeDockerfile(dir string) error { dockerfile.WriteEnv("CI", "true") dockerfile.WriteEnv("DRONE", "true") - dockerfile.WriteEnv("DRONE_BRANCH", b.Repo.Branch) - dockerfile.WriteEnv("DRONE_COMMIT", b.Repo.Commit) - dockerfile.WriteEnv("DRONE_PR", b.Repo.PR) - dockerfile.WriteEnv("DRONE_BUILD_DIR", b.Repo.Dir) + if b.Repo.Branch != "" { + dockerfile.WriteEnv("DRONE_BRANCH", b.Repo.Branch) + } + if b.Repo.Commit != "" { + dockerfile.WriteEnv("DRONE_COMMIT", b.Repo.Commit) + } + if b.Repo.PR != "" { + dockerfile.WriteEnv("DRONE_PR", b.Repo.PR) + } + if b.Repo.Dir != "" { + dockerfile.WriteEnv("DRONE_BUILD_DIR", b.Repo.Dir) + } dockerfile.WriteAdd("proxy.sh", "/etc/drone.d/") dockerfile.WriteEntrypoint("/bin/bash -e /usr/local/bin/drone")