1

我在 Jenkins 设立了一份工作,负责对 GerritHub.io 的评论做出裁决。当推送代码更改以供审查时,该作业会正确触发,并且 Jenkins 在构建开始和构建结果时会在 GerritHub 中给出评论。我在 jenkins 中的 Gerrit 服务器定义被配置为对构建失败、构建不稳定和构建成功给出判断。

但是:没有给出判决投票。

更新:在 GUI 中以 Jenkins 用户身份登录显示 Jenkins 用户只有执行代码审查的权限:-1..1。所以我在 Jenkins 中更改了我的 Gerrit 服务器设置,只提供代码审查。现在它有效,但仅适用于“代码审查”,不适用于“验证”。它表明限制在 GerritHub.io 中,并且应该可以在那里进行配置。

4

1 回答 1

1

按照Jenkins 插件页面上有关访问权限的文档进行操作,但不要添加非交互式用户,而是添加您的 Jenkins 正在使用的用户。(我更喜欢在我的审查裁决中有一个名为“Jenkins”的单独用户)

[access "refs/heads/*"]
label-Code-Review = -1..+1 group user/<Jenkins User Id>
label-Verified = -1..+1 group user/<Jenkins User Id>

默认情况下,代码审查的访问权限似乎已经到位,但无论如何都添加并添加读取权限。访问权限在“访问”选项卡中正常可用。

我为自己制作了一个脚本来简化编辑访问权限。我创建了一次访问权限,并将文件“groups”和“project.config”签入到 github repo。这是脚本:

#!/bin/bash
usage(){
  echo "Parameter 1: userid (GitHub & GerritHub)"
  echo "Parameter 2: repository name"
  exit 1
}

printline(){
  echo -e "${GRAY}====================${BLACK}"
}

check(){
  if [[ $? -ne 0 ]]; then
    echo -e "${RED}Failed: ${1}${BLACK}"
    echo $2
    rm -rf $tmp
    exit 1
  else
    echo -e "$1 - ${GREEN}DONE${BLACK}"
    printline
  fi
}

if [[ $# -ne 2 ]]; then
  usage
fi

RED='\033[0;31m'  
GREEN='\033[0;32m'  
GRAY='\033[1;30m'  
BLACK='\033[0m'   # No Color
userid=$1
repo=$2
organization="FILL IN HERE"
template="FILL IN HERE"

if [[ -z "$userid" ]]; then
  usage
fi

if [[ -z "$repo" ]]; then
  usage
fi

tmp=$(mktemp -d)

[[ -f ~/.ssh/id_rsa ]] && [[ -f ~/.ssh/id_rsa.pub ]] 
check "Check key pair in ~/.ssh/" ""

cd $tmp

git clone git@github.com:${organization}/${repo}.git
check "Clone $repo to $tmp " "(project created in GitHub? https://github.com/organizations/${organization}/repositories/new)"

cd $repo

git remote add GerritHub ssh://${userid}@review.gerrithub.io:29418/${organization}/${repo}
check "Add GerritHub as remote " "(is the project imported to GerritHub?  https://review.gerrithub.io/plugins/github-plugin/static/repositories.html)"

git fetch GerritHub  refs/meta/config:refs/remotes/GerritHub/meta/config
check "Get current access config" "(is the project imported to GerritHub?  https://review.gerrithub.io/plugins/github-plugin/static/repositories.html)"

git checkout GerritHub/meta/config
check "Check out meta/config from GerritHub"

git fetch ssh://git@github.com/${organization}/${template} master && git cherry-pick FETCH_HEAD --strategy-option theirs
check "Get access template from GitHub" ""

git push -f GerritHub  HEAD:refs/meta/config
check "Push new access rights to GerritHub" ""

rm -rf $tmp
于 2017-07-31T10:00:09.117 回答