Gitlab挂钩不会在合并请求对象上触发Jenkins Build

时间:2014-10-22 22:31:31

标签: git jenkins gitlab

当我在GitLab中提交合并请求时,我遇到了问题。当我提交合并请求时,我没有建立一个工作,虽然我有一个webhook来监听合并请求或推送。每当我推动它,它确实构建。

以下是我从webhook获得的推送请求示例:

{"before":"bf12dc027feacfb99cd8e24b1be0993d29652e3d","after":"3ec0e32587f999f4edcb7085859a1af94f62c7ad","ref":"refs/heads/DUMMY_foo_bar_test","user_id":14,"user_name":"adam","project_id":9,"repository":{"name":"exchange-api","url":"git@gitlab01.localhost.com:exchange/exchange-api.git","description":"","homepage":"http://gitlab01.localhost.com/exchange/exchange-api"},"commits":[{"id":"3ec0e32587f999f4edcb7085859a1af94f62c7ad","message":"Fooo bar","timestamp":"2014-10-22T16:14:50-06:00","url":"http://gitlab01.localhost.com/exchange/exchange-api/commit/3ec0e32587f999f4edcb7085859a1af94f62c7ad","author":{"name":"Adam","email":"Adam@localhost.com"}}],"total_commits_count":1}

以下是Gitlab为merge_request发送的内容:

{"object_kind":"merge_request","object_attributes":{"id":117,"target_branch":"US4395_safenet","source_branch":"DUMMY_foo_bar_test","source_project_id":9,"author_id":14,"assignee_id":null,"title":"Dummy foo bar test","created_at":"2014-10-22 21:52:35 UTC","updated_at":"2014-10-22 21:52:35 UTC","milestone_id":null,"state":"opened","merge_status":"unchecked","target_project_id":9,"iid":9,"description":"","position":0}}

当您为合并请求按“Test Hook”时,作业会成功构建并且没有问题,这里是发送的数据:

{"before":"2ba2af40719a0b14661b5078d2c709fb7814f16f","after":"d27f6559cc4c4a0b4e76a00c21f6848169e1d5ab","ref":"refs/heads/dev_cloud","user_id":14,"user_name":"adam bourg","project_id":9,"repository":{"name":"exchange-api","url":"git@gitlab01.localhost.com:exchange/exchange-api.git","description":"","homepage":"http://gitlab01.localhost.com/exchange/exchange-api"},"commits":[{"id":"d27f6559cc4c4a0b4e76a00c21f6848169e1d5ab","message":"Merge branch 'dev_cloud' of localhost.com:exchange-api into dev_cloud","timestamp":"2014-10-14T15:53:34-06:00","url":"http://gitlab01.localhost.com/exchange/exchange-api/commit/d27f6559cc4c4a0b4e76a00c21f6848169e1d5ab","author":{"name":"Adam","email":"Adam@localhost.com"}},{"id":"ef9eba1cc80b1ca7c9178ee2e6c35908a459b5ea","message":"Merge branch 'qa' into dev_cloud","timestamp":"2014-10-14T15:53:26-06:00","url":"http://gitlab01.localhost.com/exchange/exchange-api/commit/ef9eba1cc80b1ca7c9178ee2e6c35908a459b5ea","author":{"name":"Adam","email":"Adam@localhost.com"}},{"id":"2ba2af40719a0b14661b5078d2c709fb7814f16f","message":"US3425: recommender_drug needs plan_id in calculate_listed_pharmacy_cost","timestamp":"2014-10-14T15:53:12-06:00","url":"http://gitlab01.localhost.com/exchange/exchange-api/commit/2ba2af40719a0b14661b5078d2c709fb7814f16f","author":{"name":"Adam","email":"Adam@localhost.com"}}],"total_commits_count":3}

为什么真正的合并请求会触发发送如此少的数据?我怎样才能解决这个问题并让Jenkins正确地为这份工作建立?

詹金斯版本:1.584

Gitlab Hook插件版本:1.1.0

链接:https://wiki.jenkins-ci.org/display/JENKINS/Gitlab+Hook+Plugin

1 个答案:

答案 0 :(得分:0)

另外,我只是对这个想法玩了一下。

我使用的场景:

  • 分支大师
  • 分支功能,由主人
  • 创建
  • 在功能分支上添加了一些提交/更改
  • 推送功能分支提交
  • 主人没有变化
  • 在gitlab中创建的合并请求
  • 合并请求已接受

在创建的合并请求中,gitlab在"未选中"中发送了merge_request JSON。状态以及有关特征分支上的源(功能分支),目标(主)和最新提交的详细信息:

{
    "object_kind": "merge_request",
    "object_attributes":
    {
        "id": 1,
        "target_branch": "master",
        "source_branch": "develop",
        "source_project_id": 1,
        "author_id": 1,
        "assignee_id": 1,
        "title": "Merge test",
        "created_at": "2014-10-26 19:27:54 UTC",
        "updated_at": "2014-10-26 19:27:54 UTC",
        "milestone_id": null,
        "state": "opened",
        "merge_status": "unchecked",
        "target_project_id": 1,
        "iid": 1,
        "description": "",
        "position": 0,
        "source": {
            "name": "jenkins-hooks-test",
            "ssh_url": "git@gitlab.local:root/jenkins-hooks-test.git",
            "http_url": "http://gitlab.local/root/jenkins-hooks-test.git",
            "namespace": "root",
            "visibility_level": 10
        },
        "target": {
            "name": "jenkins-hooks-test",
            "ssh_url": "git@gitlab.local:root/jenkins-hooks-test.git",
            "http_url": "http://gitlab.local/root/jenkins-hooks-test.git",
            "namespace": "root",
            "visibility_level": 10
        },
        "last_commit": {
            "id": "8e71eab5362ef1165b6e233c97f7e9afcdba6485",
            "message": "change\n",
            "timestamp": "2014-10-26T12:11:21-07:00",
            "url": "http://gitlab.local/root/jenkins-hooks-test/commit/8e71eab5362ef1165b6e233c97f7e9afcdba6485",
            "author": {
                "name": "Vanja Radovanovic",
                "email": "some@email.com"
            }
        }
    }
}

没有触发任何工作,但在这种情况下似乎没问题。 原因是在合并请求之前,我推动了功能分支的更改以及那些已经构建在Jenkins上的更改。 发出合并请求时,无需构建该情况。

然后,在接受请求后,它被合并到gitlab中。 结果,发生了一次新的提交(在master分支上进行合并提交),并且触发了Jenkins的构建:

{
    "before": "62823aa9df67e76c97a22a7229495db51abd6c7f",
    "after": "2edb684defde57dce8344ed5800b5e90e4e18a5d",
    "ref": "refs/heads/master",
    "user_id": 1,
    "user_name": "Administrator",
    "project_id": 1,
    "repository": {
        "name": "jenkins-hooks-test",
        "url": "git@gitlab.local:root/jenkins-hooks-test.git",
        "description": "",
        "homepage": "http://gitlab.local/root/jenkins-hooks-test"
    },
    "commits": [
        {
            "id": "23cb86268570fcf53b59870fb7f4bc2fc5bf1f16",
            "message": "change\n",
            "timestamp": "2014-10-26T01:34:57+02:00",
            "url": "http://gitlab.local/root/jenkins-hooks-test/commit/23cb86268570fcf53b59870fb7f4bc2fc5bf1f16",
            "author": {
                "name": "Vanja Radovanović",
                "email": "some@email.com"
            }
        },
        {
            "id": "8e71eab5362ef1165b6e233c97f7e9afcdba6485",
            "message": "change\n",
            "timestamp": "2014-10-26T20:11:21+01:00",
            "url": "http://gitlab.local/root/jenkins-hooks-test/commit/8e71eab5362ef1165b6e233c97f7e9afcdba6485",
            "author": {
                "name": "Vanja Radovanović",
                "email": "some@email.com"
            }
        },
        {
            "id": "2edb684defde57dce8344ed5800b5e90e4e18a5d",
            "message": "Merge branch 'develop' into 'master'\nMerge test\nSee merge request !1\n",
            "timestamp": "2014-10-26T12:32:00-07:00",
            "url": "http://gitlab.local/root/jenkins-hooks-test/commit/2edb684defde57dce8344ed5800b5e90e4e18a5d",
            "author": {
                "name": "Administrator",
                "email": "some@email.com"
            }
        }
    ],
    "total_commits_count": 3
}

我看到它的方式,一切都已正常完成。 我知道Gitlab提供了在合并请求即将到来时在钩子URL上推送数据的能力,但是我没有看到你需要它的原因。

也许你可以提供一些关于你的流程的更多细节吗?