Class: Lhj::Command::JenkinsBuild
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_device(udid, name) ⇒ Object
-
#add_property(client, job_name, param_key, param_value, param_desc) ⇒ Object
-
#all_group ⇒ Object
-
#create_tester(email, id) ⇒ Object
-
#handle ⇒ Object
-
#initialize(argv) ⇒ JenkinsBuild
constructor
A new instance of JenkinsBuild.
-
#update_job(client, job_name, param_key, param_value, param_desc) ⇒ Object
-
#validate! ⇒ Object
#auto_spin, #begin_title, #run, #stop
Constructor Details
Returns a new instance of JenkinsBuild.
27
28
29
30
31
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 27
def initialize(argv)
@server_url = argv.option('server_url')
@job = argv.option('job')
super
end
|
Class Method Details
.options ⇒ Object
14
15
16
17
18
19
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 14
def self.options
[
%w[--server_url jenkins的地址],
%w[--job 运行的任务名]
]
end
|
Instance Method Details
#add_device(udid, name) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 33
def add_device(udid, name)
post_data = {
'data' => {
'attributes' => {
'name' => name,
'platform' => 'IOS',
'udid' => udid
},
'type' => 'devices'
}
}
res = Lhj::ConnectAPI.post('https://api.appstoreconnect.apple.com/v1/devices', post_data)
puts res.body
end
|
#add_property(client, job_name, param_key, param_value, param_desc) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 126
def add_property(client, job_name, param_key, param_value, param_desc)
xml = client.job.get_config(job_name)
n_xml = Nokogiri::XML(xml)
params = n_xml.xpath('//parameterDefinitions').first
return if params
pro = n_xml.xpath('//properties').first
c_xml = <<~DESC
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>WEBHOOK</name>
<description>webhook url</description>
<defaultValue>https://oapi.dingtalk.com/robot/sendBySession?session=cd8539f8472e2f5d39a6beef94ffc569</defaultValue>
<trim>true</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
DESC
pro.add_child(c_xml)
xml_modified = n_xml.to_xml
client.job.post_config(job_name, xml_modified)
end
|
#all_group ⇒ Object
181
182
183
184
185
186
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 181
def all_group
res = Lhj::ConnectAPI.get('https://api.appstoreconnect.apple.com/v1/betaGroups')
res_body = JSON.parse(res.body)
names = res_body['data'].map { |item| { id: item['id'], name: item['attributes']['name'] } }
names.each { |a| puts a[:name] + '---' + a[:id] }
end
|
#create_tester(email, id) ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 150
def create_tester(email, id)
names = email.split('@') if email =~ /@/
first_name = names[1] if names && names.length > 1
last_name = names[0] if names&.length&.positive?
first_name ||= 'first'
last_name ||= 'last'
post_data = {
'data' => {
'attributes' => {
'email' => email,
'firstName' => first_name,
'lastName' => last_name
},
'relationships' => {
'betaGroups' => {
'data' => [
{
'id' => id,
'type' => 'betaGroups'
}
]
}
},
'type' => 'betaTesters'
}
}
res = Lhj::ConnectAPI.post('https://api.appstoreconnect.apple.com/v1/betaTesters', post_data)
res_body = JSON.parse(res.body)
puts 'success' if res_body['data']
end
|
#handle ⇒ Object
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
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 48
def handle
api = Lhj::YapiHelper.new(project_id: 449, interface_id: 103638, model_name: 'OrderDetail', model_pre: 'PT')
api.process
job_name = 'aom_uat_haijian'
end
|
#update_job(client, job_name, param_key, param_value, param_desc) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 108
def update_job(client, job_name, param_key, param_value, param_desc)
xml = client.job.get_config(job_name)
n_xml = Nokogiri::XML(xml)
params = n_xml.xpath('//parameterDefinitions').first
string_params = params.children.select { |p| p.name.eql?('hudson.model.StringParameterDefinition') }
param = string_params.find { |p| p.children.find { |c| c.name.eql?('name') && c.content.eql?(param_key) } }
has_desc = false
param.children.each do |p|
has_desc = true if p.name.eql?('description')
p.content = param_value if p.name.eql?('defaultValue')
p.content = param_desc if p.name.eql?('description')
p.content = 'true' if p.name.eql?('trim')
end
param.add_child("<description>#{param_desc}</description>") unless has_desc
xml_modified = n_xml.to_xml
client.job.post_config(job_name, xml_modified)
end
|
#validate! ⇒ Object
21
22
23
24
25
|
# File 'lib/lhj/command/jenkins/jenkins_build.rb', line 21
def validate!
super
help! '输入jenkins的地址' unless @server_url
help! '输入任务名' unless @job
end
|