diff --git a/server/datastore/database/commit_test.go b/server/datastore/database/commit_test.go index d629ee25..8591e18e 100644 --- a/server/datastore/database/commit_test.go +++ b/server/datastore/database/commit_test.go @@ -69,6 +69,21 @@ func TestCommitstore(t *testing.T) { g.Assert(commit.Updated).Equal(getcommit.Updated) }) + g.It("Should Get the build number", func() { + commit := model.Commit{ + RepoID: 1, + Branch: "foo", + Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac", + Status: model.StatusSuccess, + Created: 1398065343, + Updated: 1398065344, + } + cs.PostCommit(&commit) + bn, err := cs.GetBuildNumber(&commit) + g.Assert(err == nil).IsTrue() + g.Assert(bn).Equal(int64(1)) + }) + g.It("Should Delete a Commit", func() { commit := model.Commit{ RepoID: 1, diff --git a/server/worker/docker/docker.go b/server/worker/docker/docker.go index c777d03c..4f497fce 100644 --- a/server/worker/docker/docker.go +++ b/server/worker/docker/docker.go @@ -1,6 +1,7 @@ package docker import ( + "fmt" "log" "path/filepath" "runtime/debug" @@ -115,17 +116,18 @@ func (d *Docker) Do(c context.Context, r *worker.Work) { if err != nil { log.Printf("Unable to fetch build number, Err: %s", err.Error()) } + script.Env = append(script.Env, fmt.Sprintf("DRONE_BUILD_NUMBER=%d", buildNumber)) + script.Env = append(script.Env, fmt.Sprintf("CI_BUILD_NUMBER=%d", buildNumber)) path := r.Repo.Host + "/" + r.Repo.Owner + "/" + r.Repo.Name repo := &repo.Repo{ - Name: path, - Path: r.Repo.CloneURL, - Branch: r.Commit.Branch, - Commit: r.Commit.Sha, - PR: r.Commit.PullRequest, - Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)), - Depth: git.GitDepth(script.Git), - BuildNumber: buildNumber, + Name: path, + Path: r.Repo.CloneURL, + Branch: r.Commit.Branch, + Commit: r.Commit.Sha, + PR: r.Commit.PullRequest, + Dir: filepath.Join("/var/cache/drone/src", git.GitPath(script.Git, path)), + Depth: git.GitDepth(script.Git), } priorCommit, _ := datastore.GetCommitPrior(c, r.Commit) diff --git a/shared/build/build.go b/shared/build/build.go index 6dfac69e..e77776e8 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -488,12 +488,10 @@ func (b *Builder) writeBuildScript(dir string) error { f.WriteEnv("DRONE_COMMIT", b.Repo.Commit) f.WriteEnv("DRONE_PR", b.Repo.PR) f.WriteEnv("DRONE_BUILD_DIR", b.Repo.Dir) - f.WriteEnv("DRONE_BUILD_NUMBER", fmt.Sprintf("%d", b.Repo.BuildNumber)) // add environment variables for code coverage // systems, like coveralls. f.WriteEnv("CI_NAME", "DRONE") - f.WriteEnv("CI_BUILD_NUMBER", fmt.Sprintf("%d", b.Repo.BuildNumber)) f.WriteEnv("CI_BUILD_URL", "") f.WriteEnv("CI_REMOTE", b.Repo.Path) f.WriteEnv("CI_BRANCH", b.Repo.Branch) diff --git a/shared/build/build_test.go b/shared/build/build_test.go index d01dfb79..0efa68fd 100644 --- a/shared/build/build_test.go +++ b/shared/build/build_test.go @@ -522,12 +522,11 @@ func TestWriteBuildScript(t *testing.T) { Hosts: []string{"127.0.0.1"}} b.Key = []byte("ssh-rsa AAA...") b.Repo = &repo.Repo{ - Path: "git://github.com/drone/drone.git", - Branch: "master", - Commit: "e7e046b35", - BuildNumber: 0, - PR: "123", - Dir: "/var/cache/drone/github.com/drone/drone"} + Path: "git://github.com/drone/drone.git", + Branch: "master", + Commit: "e7e046b35", + PR: "123", + Dir: "/var/cache/drone/github.com/drone/drone"} b.writeBuildScript(dir) // persist a dummy build script to disk @@ -549,9 +548,7 @@ func TestWriteBuildScript(t *testing.T) { f.WriteEnv("DRONE_COMMIT", "e7e046b35") f.WriteEnv("DRONE_PR", "123") f.WriteEnv("DRONE_BUILD_DIR", "/var/cache/drone/github.com/drone/drone") - f.WriteEnv("DRONE_BUILD_NUMBER", "0") f.WriteEnv("CI_NAME", "DRONE") - f.WriteEnv("CI_BUILD_NUMBER", "0") f.WriteEnv("CI_BUILD_URL", "") f.WriteEnv("CI_REMOTE", "git://github.com/drone/drone.git") f.WriteEnv("CI_BRANCH", "master") diff --git a/shared/build/repo/repo.go b/shared/build/repo/repo.go index 8f701110..82973efa 100644 --- a/shared/build/repo/repo.go +++ b/shared/build/repo/repo.go @@ -40,9 +40,6 @@ type Repo struct { // (optional) The depth of the `git clone` command. Depth int - - // The monotonically increasing build number for this repo - BuildNumber int64 } // IsRemote returns true if the Repository is located