blob: 7324a9ca12f4c0242c8a83494e7e3b7a3bb2b323 [file] [log] [blame]
// Copyright (C) 2017 The Bazel Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import build.bazel.ci.GerritUtils
/**
* Define a step "gerritReview" that wrap a build to be a "Gerrit review": the change
* will be commented according to the result of the build and the verified bit will be
* updated.
* except if that argument is empty (in which case the body is executed directly).
*/
def call(String server, String cookiesFile, String reviewer, changeNum, branch, Closure body) {
GerritUtils gerrit = new GerritUtils(server, cookiesFile, reviewer)
def url = gerrit.url(changeNum)
this.gerritBuild = currentBuild
stage("Start Gerrit review") {
echo "Reviewing change ${url} (${branch})"
gerrit.addReviewer(changeNum)
gerrit.comment(changeNum, branch, "Starting build at ${currentBuild.getAbsoluteUrl()}")
}
def config = [gerritBuild: currentBuild]
try {
body.delegate = config
body()
} finally {
def verified = config.gerritBuild.result == "SUCCESS" ? "+" : "-"
echo "Setting ${verified}Verified to change ${url} after build returned ${config.gerritBuild.result}"
gerrit.review(changeNum, branch, config.gerritBuild.result == "SUCCESS" ? 1 : -1,
"Build ${config.gerritBuild.getAbsoluteUrl()} finished with status ${config.gerritBuild.result}")
}
}