Commit 3275c783dcc9af3f8431186ab6feb58a150597bc
1 parent
e1f5af1a
Exists in
staging
and in
4 other branches
add hook for gitlab projects
Showing
3 changed files
with
11 additions
and
6 deletions
Show diff stats
plugins/serpro_integration/lib/ext/community.rb
@@ -24,8 +24,9 @@ class Community | @@ -24,8 +24,9 @@ class Community | ||
24 | 24 | ||
25 | if allow_jenkins_integration | 25 | if allow_jenkins_integration |
26 | jenkins_integration = SerproIntegrationPlugin::JenkinsIntegration.new(jenkins_host, jenkins_private_token, jenkins_user) | 26 | jenkins_integration = SerproIntegrationPlugin::JenkinsIntegration.new(jenkins_host, jenkins_private_token, jenkins_user) |
27 | + | ||
27 | jenkins_integration.create_jenkis_project(self, gitlab_project.path_with_namespace, gitlab_project.web_url, gitlab_project.http_url_to_repo) | 28 | jenkins_integration.create_jenkis_project(self, gitlab_project.path_with_namespace, gitlab_project.web_url, gitlab_project.http_url_to_repo) |
28 | - gitlab_integration.create_jenkins_hook(jenkins_integration.project_url) | 29 | + gitlab_integration.create_jenkins_hook(jenkins_integration.host) |
29 | end | 30 | end |
30 | 31 | ||
31 | end | 32 | end |
plugins/serpro_integration/lib/serpro_integration_plugin/gitlab_integration.rb
@@ -63,8 +63,8 @@ class SerproIntegrationPlugin::GitlabIntegration | @@ -63,8 +63,8 @@ class SerproIntegrationPlugin::GitlabIntegration | ||
63 | end | 63 | end |
64 | 64 | ||
65 | 65 | ||
66 | - def create_jenkins_hook(jenkins_project_url) | ||
67 | - @client.add_project_hook(@project.id, "#{jenkins_project_url}/gitlab/build_now") | 66 | + def create_jenkins_hook(jenkins_host) |
67 | + @client.add_project_hook(@project.id, "#{jenkins_host}/gitlab/build_now") | ||
68 | end | 68 | end |
69 | 69 | ||
70 | end | 70 | end |
plugins/serpro_integration/lib/serpro_integration_plugin/jenkins_integration.rb
@@ -3,21 +3,25 @@ require 'jenkins_api_client' | @@ -3,21 +3,25 @@ require 'jenkins_api_client' | ||
3 | 3 | ||
4 | class SerproIntegrationPlugin::JenkinsIntegration | 4 | class SerproIntegrationPlugin::JenkinsIntegration |
5 | 5 | ||
6 | + attr_accessor :host, :project_name, :user, :private_token, :profile | ||
7 | + | ||
6 | def initialize(host, private_token, user) | 8 | def initialize(host, private_token, user) |
7 | @client = JenkinsApi::Client.new(:server_url => host, :password => private_token, :username => user) | 9 | @client = JenkinsApi::Client.new(:server_url => host, :password => private_token, :username => user) |
8 | @profile = nil | 10 | @profile = nil |
9 | - | 11 | + @host = host |
12 | + @user = user | ||
13 | + @private_token = private_token | ||
10 | end | 14 | end |
11 | 15 | ||
12 | def project_url | 16 | def project_url |
13 | - "#{jenkins_host}/#{jenkins_project_name}" | 17 | + "#{host}/#{project_name}" |
14 | end | 18 | end |
15 | 19 | ||
16 | #FIXME make jenkins integration works | 20 | #FIXME make jenkins integration works |
17 | def create_jenkis_project(profile, repository_path, web_url, git_url) | 21 | def create_jenkis_project(profile, repository_path, web_url, git_url) |
18 | @profile = profile | 22 | @profile = profile |
19 | #begin | 23 | #begin |
20 | - project_name = repository_path.split('/').last | 24 | + @project_name = repository_path.split('/').last |
21 | if @client.job.list(project_name).blank? | 25 | if @client.job.list(project_name).blank? |
22 | @client.job.create(profile.jenkins_project_name, xml_jenkins(repository_path, web_url, git_url)) | 26 | @client.job.create(profile.jenkins_project_name, xml_jenkins(repository_path, web_url, git_url)) |
23 | end | 27 | end |