mirror of
https://github.com/drone/drone-cli.git
synced 2024-11-23 01:11:57 +01:00
added default env variables
This commit is contained in:
parent
5c0bfedd01
commit
43c0d6cf63
@ -60,11 +60,15 @@ func (n *batchNode) Run(b *B) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// runs the container
|
||||
// creates the container conf
|
||||
conf := toContainerConfig(n.step)
|
||||
if n.step.Config != nil {
|
||||
conf.Cmd = toCommand(b, n.step)
|
||||
}
|
||||
|
||||
// inject environment vars
|
||||
injectEnv(b, conf)
|
||||
|
||||
name, err := b.Run(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -2,6 +2,7 @@ package builder
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/drone/drone-cli/common"
|
||||
"github.com/samalba/dockerclient"
|
||||
@ -41,6 +42,26 @@ func toContainerConfig(step *common.Step) *dockerclient.ContainerConfig {
|
||||
return config
|
||||
}
|
||||
|
||||
// helper function to inject drone-specific environment
|
||||
// variables into the container.
|
||||
func injectEnv(b *B, conf *dockerclient.ContainerConfig) {
|
||||
conf.Env = append(conf.Env, "DRONE=true")
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("DRONE_BRANCH=%s", b.Commit.Branch))
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("DRONE_COMMIT=%s", b.Commit.Sha))
|
||||
|
||||
// for jenkins campatibility
|
||||
conf.Env = append(conf.Env, "CI=true")
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("WORKSPACE=%s", b.Clone.Dir))
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("GIT_BRANCH=%s", b.Commit.Branch))
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("GIT_COMMIT=%s", b.Commit.Sha))
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("JOB_NAME=%s/%s/%s", b.Repo.Host, b.Repo.Owner, b.Repo.Name))
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("BUILD_DIR=%s", b.Clone.Dir))
|
||||
|
||||
// for internal use only
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("_drone_repo_id=%d", b.Repo.ID))
|
||||
conf.Env = append(conf.Env, fmt.Sprintf("_drone_commit_id=%d", b.Commit.ID))
|
||||
}
|
||||
|
||||
// helper function to encode the build step to
|
||||
// a json string. Primarily used for plugins, which
|
||||
// expect a json encoded string in stdin or arg[1].
|
||||
|
@ -2,6 +2,7 @@ package common
|
||||
|
||||
// Build represents a build
|
||||
type Build struct {
|
||||
ID int64 `json:"id"`
|
||||
Status string `json:"status"`
|
||||
ExitCode int `json:"exit_code"`
|
||||
Started int64 `json:"started_at"`
|
||||
|
@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
type Commit struct {
|
||||
ID int64 `json:"id"`
|
||||
Status string `json:"status"`
|
||||
Started int64 `json:"started_at"`
|
||||
Finished int64 `json:"finished_at"`
|
||||
|
@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
type Repo struct {
|
||||
ID int64 `json:"id"`
|
||||
Remote string `json:"remote"`
|
||||
Host string `json:"host"`
|
||||
Owner string `json:"owner"`
|
||||
|
@ -90,6 +90,7 @@ func transformDockerPlugin(c *common.Config) {
|
||||
step.Privileged = true
|
||||
step.Volumes = nil
|
||||
step.NetworkMode = ""
|
||||
step.Entrypoint = []string{}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user