git - 正确配置下游的 Jenkins GitHub Pull Request Builder

标签 git github jenkins ghprb

我正在尝试创建两个都利用 GitHub Pull Request Builder plugin 的 Jenkins 作业为了运行多个状态检查,但我无法从我的下游作业中获取状态检查以显示在我的 GitHub 项目中。

这是我想要设置的总结 CI 流程:

  1. 针对我的 git 存储库打开 pull 请求,触发 Upstream 作业在 Jenkins 中运行
  2. Upstream 根据构建报告其状态,如果SUCCESS,应通过构建后操作调用Downstream 作业
  3. 下游 运行并报告自己的状态检查

第 3 步是我遇到问题的地方。 Downstream 正常运行,但不发布状态。在我的 GitHub 项目设置的 Branches 部分下,状态甚至不可用。我不确定如何 GHPRB执行状态检查的初始创建,但在控制台输出中有对上下文消息的引用:

14:58:23 Started by upstream project "upstream" build number 209
14:58:23 originally caused by:
14:58:23  GitHub pull request #114 of commit f1ff2819a5308f7819275e732cf44a2cc2ec31dc, no merge conflicts.
14:58:23 [EnvInject] - Loading node environment variables.
14:58:23 Building on master in workspace /store/jenkins/jobs/downstream/workspace
14:58:23  > git rev-parse --is-inside-work-tree # timeout=10
14:58:23 Fetching changes from the remote Git repository
14:58:23  > git config remote.origin.url <removed for privacy> # timeout=10
14:58:23 Fetching upstream changes from <removed for privacy>
14:58:23  > git --version # timeout=10
14:58:23  > git -c core.askpass=true fetch --tags --progress <removed for privacy> +refs/pull/*:refs/remotes/origin/pr/*
14:58:24  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
14:58:24  > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
14:58:24 Checking out Revision eac390c51a1b8b591bfe879421bd5fad0421a1ec (refs/remotes/origin/master)
14:58:24  > git config core.sparsecheckout # timeout=10
14:58:24  > git checkout -f eac390c51a1b8b591bfe879421bd5fad0421a1ec
14:58:24 First time build. Skipping changelog.
14:58:24 [build] $ /store/jenkins/tools/hudson.tasks.Ant_AntInstallation/ant_1.8.2/bin/ant -DghprbStatusUrl= "-DghprbSUCCESSMessage=Packaging organization successfully cleaned" -DghprbStartedStatus=Undeploying -DghprbAddTestResults=false "-DghprbCommitStatusContext=Cleaning Packaging" "-DghprbERRORMessage=An error occurred during undeployment" -DghprbUpstreamStatus=true "-DghprbTriggeredStatus=Preparing destructive changes" "-DghprbFAILUREMessage=Packaging organization failed to clean properly" -DghprbShowMatrixStatus=false

以下是两个 Jenkins 作业的相关配置部分:


上游作业

源代码管理:Git

  • 姓名:产地
  • 引用规范:+refs/pull/*:refs/remotes/origin/pr/*
  • 分支说明符:${sha1}

构建触发器

  • GitHub pull 请求生成器
    • 使用 github hooks 触发构建 ✔︎
    • 在下游构建中显示构建错误? ✔︎
    • 触发器设置填充有自定义上下文消息传递

构建后操作

  • 构建其他项目:下游

下游作业

源代码管理:Git

  • 姓名:产地
  • 引用规范:+refs/pull/*:refs/remotes/origin/pr/*
  • 分支说明符:*/master

构建触发器

  • GitHub pull 请求生成器
    • 触发器设置填充有自定义上下文消息传递

构建环境

  • 使用自定义上下文和消息设置 GitHub 提交状态(必须使用 GHPRB 触发器配置上游作业)✔︎
    • 自定义上下文消息传递字段反射(reflect)了触发器设置部分下列出的那些(我怀疑这两个都是必需的,但目前似乎都不起作用)

我错过了什么? 请注意,我没有安装 Jobs DSL 插件,所以我无法利用 the extension that GHPRB provides .

最佳答案

经过反复试验,this comment阐明我的问题。

我的问题的症结在于下游 没有收到所需的环境变量 GHPRB提供。即ghprbGhRepositoryghprbPullIdghprbActualCommitsha1

两个作业的正确配置如下:


上游作业

源代码管理:Git

  • 姓名:产地
  • 引用规范:+refs/pull/*:refs/remotes/origin/pr/*
  • 分支说明符:${sha1}

构建触发器

  • GitHub pull 请求生成器
    • 使用 github hooks 触发构建 ✔︎
    • 在下游构建中显示构建错误? ✔︎
    • 触发器设置填充有自定义上下文消息传递

构建

  • Trigger/call builds on other projects
    • 要构建的项目:下游
    • 预定义参数:
      • ghprbGhRepository=${ghprbGhRepository}
      • ghprbPullId=${ghprbPullId}
      • ghprbActualCommit=${ghprbActualCommit}
      • sha1=${sha1}

下游作业

源代码管理:Git

  • 姓名:产地
  • 引用规范:+refs/pull/*:refs/remotes/origin/pr/*
  • 分支说明符:${sha1}

构建环境

  • 使用自定义上下文和消息设置 GitHub 提交状态(必须使用 GHPRB 触发器配置上游作业)✔︎

关于git - 正确配置下游的 Jenkins GitHub Pull Request Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38746336/

相关文章:

visual-studio - Visual Studio 与 GitHub : Invalid URI: The URI scheme is not valid

c++ - 我应该如何在 github 上设置一个 C++ 项目以便它是可移植的?

ios - Pod 更新后 Github 丢失文件 (Xcode)

Jenkins SSH 管道步骤 -- com.jcraft.jsch.JSchException : invalid privatekey: [B@84d6b5c

Git 报告 fatal error : write error: invalid argument with git clone on git: protocol

javascript - yarn : Procedure for redeploying JavaScript dependencies to Production Server (usage of `yarn.lock` file)

Git 子模块或 fork

git - 通过 git send-email 在同一主题下发送多个补丁

Docker Jenkins - 自动安装的 Maven + Open Java 无法协同工作

authentication - Jenkins : 'Trigger Builds Remotely' 带有 ? token 在使用矩阵授权策略时不起作用