Gitlab-Plugin:Jenkins Pipeline和Gitlab之间的OpenConnection



我想在groovy中开发詹金斯管道,我有一个阶段的角色可以更新gitlab中的提交staus: .updateGitlabCommitStatus(name: 'someName', state: 'someState')。我的代码是在一个时髦的课程中外包的:

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条件或一个bloc troc catch在致电updateGitlabCommitStatus之前检查我的连接是否打开

if (gitLabConnection(" ") {
   steps.properties([connectionObject])
   call updateGitlabCommitStatus
} else {
   do nothin
}

此提交状态很可能是提交构建状态。

这应该通过gitlab api函数完成构建状态。

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键,然后使用它。

最新更新