Skip to content

Commit

Permalink
chore: load env from /run/drone/env path
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy committed Jul 18, 2020
1 parent 685cc31 commit daf0401
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import (
"os"

"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
)

// Version set at compile-time
var Version string

func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
godotenv.Load(filename)
}

if _, err := os.Stat("/run/drone/env"); err == nil {
godotenv.Overload("/run/drone/env")
}

app := cli.NewApp()
app.Name = "jenkins plugin"
app.Usage = "trigger jenkins jobs"
Expand Down Expand Up @@ -46,12 +54,6 @@ func main() {
Usage: "jenkins job",
EnvVar: "PLUGIN_JOB,JENKINS_JOB,INPUT_JOB",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
EnvVar: "ENV_FILE",
Value: ".env",
},
}

// Override a template
Expand Down Expand Up @@ -93,10 +95,6 @@ REPOSITORY:
}

func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}

plugin := Plugin{
BaseURL: c.String("host"),
Username: c.String("user"),
Expand Down

0 comments on commit daf0401

Please sign in to comment.