-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
144 lines (139 loc) · 4.87 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"github.com/jenkins-api/api"
"github.com/jenkins-api/g"
"flag"
"net/url"
"fmt"
)
func main() {
cfg := flag.String("c", "cfg.json", "configuration file")
g.ParseConfig(*cfg)
jenkins := NewJenkinsWithData()
jobs, err := jenkins.GetJobs(true)
if err != nil {
}
if len(jobs) == 0 {
}
// job, _ := jenkins.GetJob("abcd", true)
// jenkins.Build(job, nil, true)
// mavenJobItem := MavenJobItem()
// jenkins.CreateJob(mavenJobItem, "ab", true)
// jenkins.CreateJobByCfgXml("" +
// `<?xml version='1.0' encoding='UTF-8'?>
//<project>
// <actions/>
// <description>测试jenkins git</description>
// <keepDependencies>false</keepDependencies>
// <properties>
// <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="[email protected]">
// <gitLabConnection></gitLabConnection>
// </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
// <hudson.model.ParametersDefinitionProperty>
// <parameterDefinitions>
// <hudson.model.ChoiceParameterDefinition>
// <name>branch</name>
// <description></description>
// <choices class="java.util.Arrays$ArrayList">
// <a class="string-array">
// <string>dev </string>
// <string>master</string>
// </a>
// </choices>
// </hudson.model.ChoiceParameterDefinition>
// <hudson.model.ChoiceParameterDefinition>
// <name>env</name>
// <description></description>
// <choices class="java.util.Arrays$ArrayList">
// <a class="string-array">
// <string>300</string>
// <string>500</string>
// <string>800</string>
// </a>
// </choices>
// </hudson.model.ChoiceParameterDefinition>
// <hudson.model.StringParameterDefinition>
// <name>parameter</name>
// <description></description>
// <defaultValue>{"default":0}</defaultValue>
// </hudson.model.StringParameterDefinition>
// </parameterDefinitions>
// </hudson.model.ParametersDefinitionProperty>
// </properties>
// <scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
// <configVersion>2</configVersion>
// <userRemoteConfigs>
// <hudson.plugins.git.UserRemoteConfig>
// <url>https://git.oschina.net/zedhs/sso-java.git</url>
// <credentialsId>43ea5e08-a999-4b8b-ac6a-17445f1d3b76</credentialsId>
// </hudson.plugins.git.UserRemoteConfig>
// </userRemoteConfigs>
// <branches>
// <hudson.plugins.git.BranchSpec>
// <name>*/master</name>
// </hudson.plugins.git.BranchSpec>
// </branches>
// <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
// <submoduleCfg class="list"/>
// <extensions/>
// </scm>
// <canRoam>true</canRoam>
// <disabled>false</disabled>
// <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
// <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
// <triggers/>
// <concurrentBuild>false</concurrentBuild>
// <builders/>
// <publishers/>
// <buildWrappers/>
//</project>`, "abcd", true)
//var build api.Build
//build.Url = "http://10.128.31.109:8800/job/auto/10"
//log, _ := jenkins.GetBuildConsoleOutput(build, true);
//fmt.Println(string(log))
job, _ := jenkins.GetJob("TestGit", true);
//param := map[string][]string{
// "branch": []string{"dev"},
//}
//fmt.Println(param.en)
a:=url.Values{}
a.Set("branch","master")
fmt.Println(a.Encode())
jenkins.Build(job, a, true)
}
func NewJenkinsWithData() *api.Jenkins {
var auth api.Auth
auth.Username = "admin"
auth.ApiToken = "admin"
return api.NewJenkins(&auth, "http://10.128.31.109:8800")
}
func MavenJobItem() api.MavenJobItem {
scm := api.Scm{
ScmContent: api.ScmSvn{
Locations: api.Locations{
[]api.ScmSvnLocation{
api.ScmSvnLocation{IgnoreExternalsOption: "false", DepthOption: "infinity", Local: ".", Remote: "http://some-svn-url"},
},
},
IgnoreDirPropChanges: "false",
FilterChangelog: "false",
WorkspaceUpdater: api.WorkspaceUpdater{Class: "hudson.scm.subversion.UpdateUpdater"},
},
Class: "hudson.scm.SubversionSCM",
Plugin: "[email protected]",
}
triggers := api.Triggers{[]api.Trigger{api.ScmTrigger{}}}
postStep := api.RunPostStepsIfResult{Name: "FAILURE", Ordinal: "2", Color: "RED", CompleteBuild: "true"}
settings := api.JobSettings{Class: "jenkins.mvn.DefaultSettingsProvider"}
globalSettings := api.JobSettings{Class: "jenkins.mvn.DefaultSettingsProvider"}
jobItem := api.MavenJobItem{
Plugin: "[email protected]",
Description: "test description",
Scm: scm,
Triggers: triggers,
RunPostStepsIfResult: postStep,
Settings: settings,
GlobalSettings: globalSettings,
}
return jobItem
}