This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
forked from swipely/jenkins-git-notes-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
git_notes_publisher.rb
49 lines (44 loc) · 1.63 KB
/
git_notes_publisher.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
require File.expand_path('../../lib/constants', __FILE__)
require File.expand_path('../../lib/build_context', __FILE__)
require File.expand_path('../../lib/build_participant', __FILE__)
require File.expand_path('../../lib/build_notes', __FILE__)
require File.expand_path('../../lib/git_updater', __FILE__)
class GitNotesPublisher < Jenkins::Tasks::Publisher
include BuildParticipant
display_name "Publish build result as git-notes"
def initialize(attrs = {})
end
##
# Runs before the build begins
#
# @param [Jenkins::Model::Build] build the build which will begin
# @param [Jenkins::Model::Listener] listener the listener for this build.
def prebuild(build, listener)
end
##
# Runs the step over the given build and reports the progress to the listener.
#
# @param [Jenkins::Model::Build] build on which to run this step
# @param [Jenkins::Launcher] launcher the launcher that can run code on the node running this build
# @param [Jenkins::Model::Listener] listener the listener for this build.
def perform(build, launcher, listener)
BuildContext.instance.set(build, launcher, listener) do
git_updater = GitUpdater.new
retries = Constants::CONCURRENT_UPDATE_RETRIES
notes = BuildNotes.new.notes
begin
info "updating git notes"
git_updater.update!(notes)
rescue GitUpdater::ConcurrentUpdateError => e
if retries > 0
warn "caught ConcurrentUpdateError while updating git notes, retrying (#{retries}x left)"
retries -= 1
retry
else
raise e
end
end
info "updated git notes: #{notes}"
end
end
end