Skip to content

Commit c09463a

Browse files
committed
[CI] Adds script to create new Jenkins Jobs
1 parent 1f11498 commit c09463a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.github/create_jenkins_job.rb

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
source_branch = ARGV[0]
18+
target_branch = ARGV[1]
19+
20+
def usage
21+
<<~USAGE
22+
23+
This script creates a new Jenkins Job in .ci/jobs. It takes two parameters:
24+
- source branch: branch name for the job to use as a source
25+
- target branch: branch name for the new job
26+
In the new file, it is going to replace the source branch value with the target branch value and
27+
create a new yml file based on that.
28+
29+
E.g.:
30+
$ #{__FILE__} 7.x 7.99
31+
This is going to use .ci/jobs/elastic+elasticsearch-ruby+7.x.yml as a source and create
32+
.ci/jobs/elastic+elasticsearch-ruby+7.99.yml and replace all the ocurrences of '7.x' with '7.99'
33+
in the new file.
34+
USAGE
35+
end
36+
37+
unless source_branch && target_branch
38+
puts usage
39+
exit
40+
end
41+
42+
job_file = File.expand_path("../.ci/jobs/elastic+elasticsearch-ruby+#{source_branch}.yml", __dir__)
43+
raise ArgumentError, "cannot find file #{job_file}" unless File.exist? job_file
44+
45+
target_branch_file = File.expand_path("../.ci/jobs/elastic+elasticsearch-ruby+#{target_branch}.yml", __dir__)
46+
target_branch_content = File.read(job_file).gsub(source_branch, target_branch)
47+
48+
begin
49+
File.open(target_branch_file, 'w') { |file| file.puts target_branch_content }
50+
rescue StandardError => e
51+
raise e
52+
end

0 commit comments

Comments
 (0)