forked from appleboy/drone-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
57 lines (44 loc) · 861 Bytes
/
plugin.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
package main
import (
"errors"
"strings"
)
type (
// Plugin values.
Plugin struct {
BaseURL string
Username string
Token string
Job []string
}
)
func trimElement(keys []string) []string {
var newKeys []string
for _, value := range keys {
value = strings.Trim(value, " ")
if len(value) == 0 {
continue
}
newKeys = append(newKeys, value)
}
return newKeys
}
// Exec executes the plugin.
func (p Plugin) Exec() error {
if len(p.BaseURL) == 0 || len(p.Username) == 0 || len(p.Token) == 0 {
return errors.New("missing jenkins config")
}
jobs := trimElement(p.Job)
if len(jobs) == 0 {
return errors.New("missing jenkins job")
}
auth := &Auth{
Username: p.Username,
Token: p.Token,
}
jenkins := NewJenkins(auth, p.BaseURL)
for _, value := range jobs {
jenkins.trigger(value, nil)
}
return nil
}