forked from gocd/build_utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-docs-pipelines.rb
52 lines (46 loc) · 1.38 KB
/
create-docs-pipelines.rb
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
#!/usr/bin/env ruby
if File.basename($PROGRAM_NAME) != 'rake'
require 'shellwords'
puts "bundle exec rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
exec "bundle exec rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
end
require 'net/http'
require 'uri'
require 'base64'
require 'json'
require 'tempfile'
def validate(key)
value = ENV[key].to_s.strip
raise "Please specify #{key}" if value == ''
value
end
version_to_release = validate('VERSION_TO_RELEASE')
template = validate('TEMPLATE')
gocd_group = validate('GROUP')
repo = validate('REPO')
username = validate('USERNAME')
password = validate('PASSWORD')
task :default do
repo_url = "https://mirrors.gocd.org/git/gocd/#{repo}"
pipeline_name = "#{repo}-release-#{version_to_release}"
payload = {
group: gocd_group,
pipeline: {
label_template: '${COUNT}',
name: pipeline_name,
template: template,
enable_pipeline_locking: false,
materials: [
{
type: 'git',
attributes: {
url: repo_url,
branch: "release-#{version_to_release}",
shallow_clone: true
}
}
]
}
}
sh("curl -u'#{username}:#{password}' -H 'Content-Type: application/json' -H 'Accept: application/vnd.go.cd.v4+json' 'https://build.gocd.org/go/api/admin/pipelines' -d '#{payload.to_json}'")
end