@@ -2,7 +2,6 @@ package jenkins
2
2
3
3
import (
4
4
"github.com/devstream-io/devstream/internal/pkg/plugininstaller"
5
- "github.com/devstream-io/devstream/pkg/util/jenkins"
6
5
"github.com/devstream-io/devstream/pkg/util/log"
7
6
"github.com/devstream-io/devstream/pkg/util/scm"
8
7
)
@@ -19,12 +18,14 @@ func CreateOrUpdateJob(options plugininstaller.RawOptions) error {
19
18
return err
20
19
}
21
20
// 2. create or update jenkins job
22
- err = opts .createOrUpdateJob (jenkinsClient )
21
+ return opts .createOrUpdateJob (jenkinsClient )
22
+ }
23
+
24
+ func ConfigRepo (options plugininstaller.RawOptions ) error {
25
+ opts , err := newJobOptions (options )
23
26
if err != nil {
24
- log .Debugf ("jenkins execute script failed: %s" , err )
25
27
return err
26
28
}
27
- // 3. create repo webhook
28
29
scmClient , err := scm .NewClient (opts .ProjectRepo .BuildRepoInfo ())
29
30
if err != nil {
30
31
return err
@@ -37,6 +38,7 @@ func DeleteJob(options plugininstaller.RawOptions) error {
37
38
if err != nil {
38
39
return err
39
40
}
41
+ // 1. delete jenkins job
40
42
client , err := opts .newJenkinsClient ()
41
43
if err != nil {
42
44
log .Debugf ("jenkins init client failed: %s" , err )
@@ -46,44 +48,36 @@ func DeleteJob(options plugininstaller.RawOptions) error {
46
48
if err != nil {
47
49
return err
48
50
}
49
- // delete repo webhook
51
+ // 2. delete repo webhook
50
52
scmClient , err := scm .NewClient (opts .ProjectRepo .BuildRepoInfo ())
51
53
if err != nil {
52
54
return err
53
55
}
54
56
return scmClient .DeleteWebhook (opts .buildWebhookInfo ())
55
57
}
56
58
57
- func PreInstall (plugins []* jenkins.JenkinsPlugin , cascTemplate string ) plugininstaller.BaseOperation {
58
- return func (options plugininstaller.RawOptions ) error {
59
- opts , err := newJobOptions (options )
60
- if err != nil {
61
- return err
62
- }
63
- // 1. init jenkins client
64
- jenkinsClient , err := opts .newJenkinsClient ()
65
- if err != nil {
66
- log .Debugf ("jenkins init client failed: %s" , err )
67
- return err
68
- }
69
- // 2. install plugins
70
- err = opts .installPlugins (jenkinsClient , plugins )
71
- if err != nil {
72
- log .Debugf ("jenkins preinstall plugins failed: %s" , err )
73
- return err
74
- }
59
+ func PreInstall (options plugininstaller.RawOptions ) error {
60
+ opts , err := newJobOptions (options )
61
+ if err != nil {
62
+ return err
63
+ }
64
+ // 1. init jenkins client
65
+ jenkinsClient , err := opts .newJenkinsClient ()
66
+ if err != nil {
67
+ log .Debugf ("jenkins init client failed: %s" , err )
68
+ return err
69
+ }
70
+
71
+ // 2. get all plugins need to preConfig
72
+ pluginsConfigs := opts .extractJenkinsPlugins ()
75
73
76
- switch opts .ProjectRepo .RepoType {
77
- case "gitlab" :
78
- // 3. create gitlab connection for gitlab
79
- err := opts .createGitlabSSHPrivateKey (jenkinsClient )
80
- if err != nil {
81
- return err
82
- }
83
- return opts .createGitlabConnection (jenkinsClient , cascTemplate )
84
- default :
85
- log .Debugf ("jenkins preinstall only support gitlab for now" )
86
- return nil
87
- }
74
+ // 3. install all plugins
75
+ err = installPlugins (jenkinsClient , pluginsConfigs , opts .Jenkins .EnableRestart )
76
+ if err != nil {
77
+ log .Debugf ("jenkins preinstall plugins failed: %s" , err )
78
+ return err
88
79
}
80
+
81
+ // 4. config repo related config in jenkins
82
+ return preConfigPlugins (jenkinsClient , pluginsConfigs )
89
83
}
0 commit comments