diff --git a/server/procBuilder.go b/server/procBuilder.go index 5eaadeefa..575c1ca9f 100644 --- a/server/procBuilder.go +++ b/server/procBuilder.go @@ -59,7 +59,9 @@ func (b *procBuilder) Build() ([]*buildItem, error) { sort.Sort(remote.ByName(b.Yamls)) - for j, y := range b.Yamls { + pidSequence := 1 + + for _, y := range b.Yamls { // matrix axes axes, err := matrix.ParseString(string(y.Data)) if err != nil { @@ -69,11 +71,11 @@ func (b *procBuilder) Build() ([]*buildItem, error) { axes = append(axes, matrix.Axis{}) } - for i, axis := range axes { + for _, axis := range axes { proc := &model.Proc{ BuildID: b.Curr.ID, - PID: j + i + 1, - PGID: j + i + 1, + PID: pidSequence, + PGID: pidSequence, State: model.StatusPending, Environ: axis, Name: sanitizePath(y.Name), @@ -123,6 +125,7 @@ func (b *procBuilder) Build() ([]*buildItem, error) { item.Labels = map[string]string{} } items = append(items, item) + pidSequence++ } } diff --git a/server/procBuilder_test.go b/server/procBuilder_test.go index 4452dfaf4..d5f32ae7f 100644 --- a/server/procBuilder_test.go +++ b/server/procBuilder_test.go @@ -201,6 +201,42 @@ pipeline: } } if buildItems[1].Proc.State != model.StatusPending { - t.Fatal("Should not run on dev branch") + t.Fatal("Should run on dev branch") + } +} + +func TestTree(t *testing.T) { + build := &model.Build{} + + b := procBuilder{ + Repo: &model.Repo{}, + Curr: build, + Last: &model.Build{}, + Netrc: &model.Netrc{}, + Secs: []*model.Secret{}, + Regs: []*model.Registry{}, + Link: "", + Yamls: []*remote.FileMeta{ + &remote.FileMeta{Data: []byte(` +pipeline: + build: + image: scratch + yyy: ${DRONE_COMMIT_MESSAGE} +`)}, + }, + } + + _, err := b.Build() + if err != nil { + t.Fatal(err) + } + if len(build.Procs) != 3 { + t.Fatal("Should generate three in total") + } + if build.Procs[1].PPID != 1 { + t.Fatal("Clone step should be a children of the stage") + } + if build.Procs[2].PPID != 1 { + t.Fatal("Build step should be a children of the stage") } }