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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/jenkins-rails/ext.rb', line 31
def xml_config(params)
supported_scm_providers = ['git', 'subversion']
raise 'Job name must be specified' unless params[:name]
params[:keep_dependencies] = false if params[:keep_dependencies].nil?
params[:block_build_when_downstream_building] = false if params[:block_build_when_downstream_building].nil?
params[:block_build_when_upstream_building] = false if params[:block_build_when_upstream_building].nil?
params[:concurrent_build] = false if params[:concurrent_build].nil?
unless supported_scm_providers.include?(params[:scm_provider]) || params[:scm_provider].nil?
raise "SCM #{params[:scm_provider]} is currently not supported"
end
raise 'SCM URL must be specified' if params[:scm_url].nil? && !params[:scm_provider].nil?
params[:scm_branch] = "master" if params[:scm_branch].nil? && !params[:scm_provider].nil?
params[:child_threshold] = 'failure' if params[:child_threshold].nil? && !params[:child_projects].nil?
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml|
xml.project {
xml.actions
xml.description
xml.keepDependencies "#{params[:keep_dependencies]}"
xml.properties {
xml.send("hudson.security.AuthorizationMatrixProperty") {
xml.permission "hudson.model.Item.Configure:#{params[:username]}"
xml.permission "hudson.model.Item.Read:#{params[:username]}"
xml.permission "hudson.model.Item.Discover:#{params[:username]}"
xml.permission "hudson.model.Item.Build:#{params[:username]}"
xml.permission "hudson.model.Item.Workspace:#{params[:username]}"
xml.permission "hudson.model.Item.Cancel:#{params[:username]}"
xml.permission "hudson.model.Run.Delete:#{params[:username]}"
xml.permission "hudson.model.Run.Update:#{params[:username]}"
xml.permission "hudson.scm.SCM.Tag:#{params[:username]}"
}
}
if params[:scm_provider] == 'subversion'
xml.scm(:class => "hudson.scm.SubversionSCM", :plugin => "[email protected]") {
xml.locations {
xml.send("hudson.scm.SubversionSCM_-ModuleLocation") {
xml.remote "#{params[:scm_url]}"
xml.local "."
}
}
xml.excludedRegions
xml.includedRegions
xml.excludedUsers
xml.excludedRevprop
xml.excludedCommitMessages
xml.workspaceUpdater(:class => "hudson.scm.subversion.UpdateUpdater")
}
elsif params[:scm_provider] == 'git'
xml.scm(:class => "hudson.plugins.git.GitSCM") {
xml.configVersion "2"
xml.userRemoteConfigs {
xml.send("hudson.plugins.git.UserRemoteConfig") {
xml.name
xml.refspec
xml.url "#{params[:scm_url]}"
}
}
xml.branches {
xml.send("hudson.plugins.git.BranchSpec") {
xml.name "#{params[:scm_branch]}"
}
}
xml.disableSubmodules "false"
xml.recursiveSubmodules "false"
xml.doGenerateSubmoduleConfigurations "false"
xml.authorOrCommitter "false"
xml.clean "false"
xml.wipeOutWorkspace "false"
xml.pruneBranches "false"
xml.remotePoll "false"
xml.ignoreNotifyCommit "false"
xml.useShallowClone "false"
xml.buildChooser(:class => "hudson.plugins.git.util.DefaultBuildChooser")
xml.gitTool "Default"
xml.submoduleCfg(:class => "list")
xml.relativeTargetDir
xml.reference
xml.excludedRegions
xml.excludedUsers
xml.gitConfigName
xml.gitConfigEmail
xml.skipTag "false"
xml.includedRegions
xml.scmName
}
else
xml.scm(:class => "hudson.scm.NullSCM")
end
xml.canRoam "true"
xml.disabled "false"
xml.blockBuildWhenDownstreamBuilding "#{params[:block_build_when_downstream_building]}"
xml.blockBuildWhenUpstreamBuilding "#{params[:block_build_when_upstream_building]}"
xml.triggers.vector {
xml.send('com.cloudbees.jenkins.GitHubPushTrigger', :plugin => "[email protected]"){
xml.spec
}
xml.send('hudson.triggers.SCMTrigger'){
xml.spec "* * * * *"
xml.ignorePostCommitHooks 'false'
}
}
xml.concurrentBuild "#{params[:concurrent_build]}"
xml.builders {
if params[:shell_command]
xml.send("hudson.tasks.Shell") {
xml.command "#{params[:shell_command]}"
}
end
}
xml.publishers {
if params[:child_projects]
xml.send("hudson.tasks.BuildTrigger") {
xml.childProjects"#{params[:child_projects]}"
name, ordinal, color = get_threshold_params(params[:child_threshold])
xml.threshold {
xml.name "#{name}"
xml.ordinal "#{ordinal}"
xml.color "#{color}"
}
}
end
}
xml.buildWrappers
}
}
builder.to_xml
end
|