forked from vmware-archive/atc
/
create_build.go
48 lines (38 loc) · 1.12 KB
/
create_build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package jobserver
import (
"encoding/json"
"fmt"
"net/http"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) CreateJobBuild(pipelineDB db.PipelineDB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger := s.logger.Session("create-job-build")
jobName := r.FormValue(":job_name")
config, _, found, err := pipelineDB.GetConfig()
if err != nil {
logger.Error("could-not-get-pipeline-config", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
job, found := config.Jobs.Lookup(jobName)
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
scheduler := s.schedulerFactory.BuildScheduler(pipelineDB, s.externalURL)
build, _, err := scheduler.TriggerImmediately(logger, job, config.Resources, config.ResourceTypes)
if err != nil {
logger.Error("failed-to-trigger", err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "failed to trigger: %s", err)
return
}
json.NewEncoder(w).Encode(present.Build(build))
})
}