我的詹金斯和Gerrithub都没有判决

时间:2017-07-27 13:58:58

标签: jenkins configuration gerrit-trigger

我已经在Jenkins找到了一份工作,对GerritHub.io的评论做出判决。 当推送代码更改进行审核时,作业会被正确触发,而Jenkins会在构建开始和构建结果时在GerritHub中发表评论。我在jenkins中的Gerrit Server定义被配置为在构建失败,构建不稳定和构建成功时给予判断。

:未作出判决投票。

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

1 个答案:

答案 0 :(得分:1)

按照the Jenkins plugin page上有关访问权限的文档,但不要使用非交互式用户,请添加Jenkins正在使用的用户。 (我更喜欢在我的评论判断中有一个名为'Jenkins'的单独用户)

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

默认情况下,Code-Review的访问权限似乎已经到位,但在任何情况下都要添加两者并添加读取权限。正常情况下,“访问”选项卡中提供了访问权限。

我为自己编写了一个脚本来简化编辑访问权限。我创建了一次访问权限,并将文件'groups'和'project.config'签入github仓库。这是脚本:

#!/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