jenkinsci / gitlab-hook-plugin

Deprecated, see https://www.jenkins.io/jep/7
133 stars 42 forks source link

undefined method `getQuietPeriod' for nil:NilClass when testing the /build_now/project-name webhook #32

Open gtheraud opened 8 years ago

gtheraud commented 8 years ago

I added following webhooks for Push and Tag Push Events in gitlab :

http://jenkins.local/gitlab/build_now/my-project

my-project is a Jenkins Pipeline project. When i test the webhooks, i get the following HTTP Response :

NoMethodError at /build_now/my-project
undefined method `getQuietPeriod' for nil:NilClass
file: api.rb location: POST /build_now/:project_name line: 43

with the following stack-trace :

/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/models/api.rb in POST /build_now/:project_name
 project.scheduleBuild2(project.getQuietPeriod(), cause_builder.with(details), actions_builder.with(project, details))
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb in call
 status, headers, body = @app.call(env)
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb in call
 app.call env
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb in call
 status, headers, body = app.call(env)
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-protection-1.2.0/lib/rack/protection/base.rb in call
 result or app.call(env)
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb in call
 status, headers, body = @app.call(env)
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-1.4.1/lib/rack/nulllogger.rb in call
 @app.call(env)
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/vendor/gems/gems/rack-1.4.1/lib/rack/head.rb in call
 status, headers, body = @app.call(env)
/var/lib/jenkins/plugins/gitlab-hook/WEB-INF/classes/models/root_action.rb in call
 GitlabWebHook::Api.new.call(env)
file:/var/lib/jenkins/plugins/ruby-runtime/WEB-INF/lib/jruby-rack-1.1.13.1.jar!/rack/handler/servlet.rb in call
 self.class.response.new(@app.call(create_env(servlet_env)))
gtheraud commented 8 years ago

This issue might be linked to #31 since my build is a Pipeline build. I found out that there might be a bug in models/services/get_jenkins_projects.rb :

projects = Java.jenkins.model.Jenkins.instance.getAllItems(AbstractProject.java_class).map do |jenkins_project|

This won't return the pipeline jobs. When I removed AbstractProject.java_class to include pipeline jobs, i get :

undefined method 'scm' for OrgJenkinsciPluginsWorkflowJob::WorkflowJob

Unfortunately, that is how much I can do so far.

wuzhaozhongguo commented 8 years ago

I also had the same problem,my gitlab web hooks is http://site/gitlab/build_now/projectName jenkins 2.20

danielmbarlow commented 8 years ago

I had the same problem, but found a workaround. I use the same web hook as @wuzhaozhongguo, but I opened the project configuration screen in Jenkins and copied the 'Project name' field from there. After that it worked.

Before: http://<site>/gitlab/build_now/BO_Merge_Request_Build After: http://<site>/gitlab/build_now/bo_merge_request_build

Looks like it might be a case issue.

I'm on gitlab-hook-plugin v1.4.2, Jenkins 2.7.3.

Hope that helps.

chanxiaohui commented 7 years ago

Is this problem solved?

llorllale commented 7 years ago

Having this issue on Jenkins 2.73.2., gilab-hook version 1.4.2.

@danielmbarlow 's suggestion did not work