elvanja / jenkins-gitlab-hook-plugin

Enables Gitlab web hooks to be used to trigger SMC polling on Gitlab projects
142 stars 81 forks source link

Do not find project for composite branch names #2

Closed Isammoc closed 11 years ago

Isammoc commented 11 years ago

Hi,

First, thanks for this usefull plugin. But I have a small issue.

I configured Jenkins with git plugin to build several branches pattern :

When I trigger build with a remote trigger (or manually), all run fine . But when I use gitlab hook, only fully specified branches are built like gitlab/dev

In log :

Dec 5, 2012 2:27:41 PM sun.reflect.GeneratedMethodAccessor549 invoke
INFO: gitlab web hook triggered for repo url http://gitlab.example.com/myproject
Dec 5, 2012 2:27:41 PM sun.reflect.GeneratedMethodAccessor579 invoke
WARNING: no project references the given repo url and commit branch

(url is manually changed)

elvanja commented 11 years ago

Hi, glad you use it :-)

Funny thing, I did test multilevel / composite branch names, especially since I use gitflow. But, I did notice you are probably using version 0.1.1. And this is entirely my fault. I committed the code to mine and Jenkins fork, but didn't release the plugin.

So, just did that. You should be seeing version 0.2.0 in your Jenkins plugin update center, and if not (it takes time to propagate), you can find it @ jenkins repo.

Before we go on, please use that updated version. In log, there should be some more info, e.g.

INFO: gitlab web hook triggered for repo url http://gitlab.example.com/myproject
INFO: with payload: ... here comes the payload from gitlab, you can delete sensitive data

Please send me this info. It should be enough for me to be able to figure out the cause.

Isammoc commented 11 years ago

Thanks for replying,

You're right, I'm using version 0.1.1. No update is available for now, I'm waiting for propagation and will come back then.

Isammoc commented 11 years ago

Ok, I'm on version 0.2.0 now.

I created a new branch story/test and push it to gitlab

Here the jenkins log :

INFO: gitlab web hook triggered for repo url http://gitlab.example.com/myproject and test branch
INFO: with payload: {"before"=>"0000000000000000000000000000000000000000", "after"=>"3e213054239ede90231239a41a4308bbf51df0a4", "ref"=>"refs/heads/story/test", "user_id"=>14, "user_name"=>"Me ****", "repository"=>{"name"=>"myproject", "url"=>"http://gitlab.example.com/myproject", "description"=>nil, "homepage"=>"http://gitlab.example.com/myproject"}, "commits"=>[{"id"=>"3e213054239ede90231239a41a4308bbf51df0a4", "message"=>"Dummy test 1", "timestamp"=>"2012-12-06T11:25:31+01:00", "url"=>"http://gitlab.dev.example.com/myproject/commits/3e213054239ede90231239a41a4308bbf51df0a4", "author"=>{"name"=>"Me ****", "email"=>"me@example.com"}}], "total_commits_count"=>1}
INFO: project build-webapp doesn't match the test branch
WARNING: no project references the given repo url and commit branch

(urls, names and mails manually changed)

I expected to see story/test instead of test in the first line. Maube this is the issue ?

elvanja commented 11 years ago

Yes, you are right, I've been using only the last in payload["ref"].split("/"). Wait for a fix...

Isammoc commented 11 years ago

I can't test my fix (and I am not used to code in ruby), but I think something like this could be fix the issue :

  def get_commit_branch(payload)
    payload["ref"].split("/")[2..-1].join("/") if payload && payload["ref"]
  end

in models/gitlab_web_hook_api.rb (lines 115-117)

elvanja commented 11 years ago

Excellent, I wrote it a bit different, to ensure the intent is clear (removing head and ref from the entire path). I can't release from here but the update will be available later today. Let me know how it goes after you try it.

Isammoc commented 11 years ago

Thanks, I cannot wait to see this working ^^

elvanja commented 11 years ago

OK, so the new version 0.2.3 is up with another fix. It should now accept branches like refactoring-what-not. If you're impatient, you can find it here. Fingers crossed :-)

Isammoc commented 11 years ago
INFO: gitlab web hook triggered for repo url http://gitlab.example.com/myproject and story/test branch
INFO: with payload: {"before"=>"3e213054239ede90231239a41a4308bbf51df0a4", "after"=>"04a609729d97f803f084695909a2751ec2172b9e", "ref"=>"refs/heads/story/test", "user_id"=>14, "user_name"=>"Me **********", "repository"=>{"name"=>"myproject", "url"=>"http://gitlab.example.com/myproject", "description"=>nil, "homepage"=>"http://gitlab.example.com/myproject"}, "commits"=>[{"id"=>"04a609729d97f803f084695909a2751ec2172b9e", "message"=>"Dummy test 5", "timestamp"=>"2012-12-07T15:59:28+01:00", "url"=>"http://gitlab.example.com/myproject/commits/04a609729d97f803f084695909a2751ec2172b9e", "author"=>{"name"=>"Me ********", "email"=>"me@example.com"}}], "total_commits_count"=>1}
INFO: project build-webapp matches the story/test branch
INFO: project build-webapp doesn't match the master branch
INFO: project build-webapp doesn't match the ** branch
WARNING: could not determine master project, please create a project for the repo (usually for the master branch)

My job is not triggered :'(

elvanja commented 11 years ago

Yep, residue from another feature I am building (automatic Jenkins project creating per Gitlab branch). Switched it off, should work now. New version @ jenkins repo, and please test as usual :-)

Isammoc commented 11 years ago

Tried this morning. Job is well triggered ^^

Thanks a lot.

elvanja commented 11 years ago

Great :-)