forked from forj-oss/forjj-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.go
79 lines (65 loc) · 2.55 KB
/
create.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This file has been created by "go generate" as initial code. go generate will never update it, EXCEPT if you remove it.
// So, update it for your need.
package main
import (
"github.com/forj-oss/goforjj"
"log"
"os"
"path"
)
// return true if instance doesn't exist.
func (r *CreateReq) check_source_existence(ret *goforjj.PluginData) (p *JenkinsPlugin, httpCode int) {
log.Printf("Checking Jenkins source code existence.")
src := path.Join(r.Forj.ForjjSourceMount, r.Forj.ForjjInstanceName)
if _, err := os.Stat(path.Join(src, jenkins_file)); err == nil {
log.Printf(ret.Errorf("Unable to create the jenkins source code for instance name '%s' which already exist.\nUse 'update' to update it (or update %s), and 'maintain' to update jenkins according to his configuration.", r.Forj.ForjjInstanceName, src))
return nil, 419 // Abort message returned to forjj.
}
p = newPlugin(src, r.Forj.ForjjDeployMount)
p.setEnv(r.Forj.ForjjDeploymentEnv, r.Forj.ForjjInstanceName)
log.Printf(ret.StatusAdd("environment checked."))
return
}
// We assume template source file is loaded.
func (r *JenkinsPlugin) create_jenkins_sources(ret *goforjj.PluginData) (err error) {
if err = r.DefineSources(); err != nil {
log.Printf(ret.Errorf("%s", err))
return err
}
log.Print("Start copying source files...")
if err = r.copy_source_files(ret, nil); err != nil {
return
}
log.Print("Start Generating source files...")
if err = r.generate_source_files(ret, nil); err != nil {
return
}
if err = r.generate_jobsdsl(ret, nil); err != nil {
return
}
return
}
// add_projects add project data in the jenkins.yaml file
func (jp *JenkinsPlugin) add_projects(req *CreateReq, ret *goforjj.PluginData) error {
projects := ProjectInfo{}
projects.set_project_info(req.Forj.ForjCommonStruct)
instanceData := req.Objects.App[req.Forj.ForjjInstanceName]
projects.setDslInfo(instanceData.SeedJobStruct)
return projects.set_projects_to(req.Objects.Projects, jp, ret, nil, req.Forj.ForjjInfra, instanceData.JenkinsfilePath)
}
// generate_jobsdsl generate any missing job-dsl source file.
// TODO: Support for different Repository path that Forjj have to checkout appropriately.
func (p *JenkinsPlugin) generate_jobsdsl(ret *goforjj.PluginData, status *bool) (err error) {
if p.yaml.Projects == nil {
return
}
if err = p.yaml.Projects.Generates(p, p.InstanceName, ret, status); err != nil {
log.Print(ret.Errorf("%s", err))
}
return
}
func (r *CreateArgReq) SaveMaintainOptions(ret *goforjj.PluginData) {
if ret.Options == nil {
ret.Options = make(map[string]goforjj.PluginOption)
}
}