jenkins - gitlab-plugin : Jenkins Pipeline 和 Gitlab 之间的 openConnection
问题描述
我想在 groovy 中开发一个 Jenkins 流水线,我有一个 Stage 有角色来更新 Gitlab 中的提交状态:.updateGitlabCommitStatus(name: 'someName', state: 'someState')
。我的代码在 Groovy 类中外包:
package ...
import com.dabsquared.gitlabjenkins.*
class GitlabSender {
def steps
openConnection() {
steps.properties([steps.gitLabConnection("application_name"])
}
updateGitlabCommitStatus(String name, String state) {
steps.updateGitlabCommitStatus(name: name, state: state)
}
}
我想通过在调用之前添加 if-else 条件或 aa bloc try catch 来检查我的连接是否updateGitlabCommitStatus
打开
if (gitLabConnection(" ") {
steps.properties([connectionObject])
call updateGitlabCommitStatus
} else {
do nothin
}
解决方案
此提交状态很可能是提交构建状态。
这应该通过 Gitlab API 函数Post the build status to a commit 来完成。
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"
示例响应:
{
"author" : {
"web_url" : "https://gitlab.example.com/thedude",
"name" : "Jeff Lebowski",
"avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png",
"username" : "thedude",
"state" : "active",
"id" : 28
},
"name" : "default",
"sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8",
"status" : "success",
"coverage": 100.0,
"description" : null,
"id" : 93,
"target_url" : null,
"ref" : null,
"started_at" : null,
"created_at" : "2016-01-19T09:05:50.355Z",
"allow_failure" : false,
"finished_at" : "2016-01-19T09:05:50.365Z"
}
这个解决方案需要你获取 gitlab api 密钥然后使用它。
推荐阅读
- android - Install new version of Android app programmatically
- java - Java JGit API:如何更新 git 子模块?
- calculated-columns - 我要对发生事件进行分类
- spring-boot - 在 Spring Boot Docker App 的 java.library.path 警告中找不到基于 APR 的 Apache Tomcat Native 库
- python - 抓取多个 URL 的问题 - NFL 投注数据
- node.js - TypeError:无法读取未定义的属性“crud_name”
- javascript - 添加新列后如何使用 JQuery DataTable 进行列搜索
- javascript - JavaScript 中更多参数的扩展函数
- android - 更新 dexguard 版本时抛出错误 - 在 DexGuard 插件之前应用 Crashlytics 插件
- google-sheets - 根据同一行中的值在每一行上创建一个依赖下拉列表