foreman_pipeline 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +674 -0
- data/README.md +36 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/foreman_pipeline/foreman_pipeline-bootstrap.js +8 -0
- data/app/assets/javascripts/foreman_pipeline/foreman_pipeline.js +20 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/jenkins-instance-details-info.controller.js +46 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/jenkins-instance-details-users.controller.js +72 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/jenkins-instance-details.controller.js +40 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details-info.html +36 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details-users.html +107 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/details/views/jenkins-instance-details.html +53 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/jenkins-instances.controller.js +34 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/jenkins-instances.factory.js +14 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/jenkins-instances.module.js +93 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/new/new-jenkins-instance.controller.js +40 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/new/views/new-jenkins-instance-form.html +50 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/new/views/new-jenkins-instance.html +16 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/views/jenkins-instances-table-collapsed.html +20 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/views/jenkins-instances-table-full.html +30 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-instances/views/jenkins-instances.html +17 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-project-params/jenkins-project-params.factory.js +11 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-project-params/jenkins-project-params.module.js +6 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-projects/jenkins-projects.factory.js +9 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-projects/jenkins-projects.module.js +10 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-requests/jenkins-requests.factory.js +11 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-requests/jenkins-requests.module.js +10 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-users/details/jenkins-user-info.controller.js +39 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-users/details/views/jenkins-user-info.html +37 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-users/jenkins-users.factory.js +10 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-users/jenkins-users.module.js +6 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-users/new/new-jenkins-user.controller.js +45 -0
- data/app/assets/javascripts/foreman_pipeline/jenkins-users/new/views/new-jenkins-user.html +32 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-add-paths.controller.js +63 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-content-views.controller.js +55 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-environments.controller.js +56 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-hostgroups.controller.js +59 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-info.controller.js +69 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-jenkins-projects.controller.js +49 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-jenkins.controller.js +56 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-resources.controller.js +60 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details-to-environments.controller.js +157 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/job-details.controller.js +34 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/job-projects-discovery.controller.js +96 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/job-projects-parameters.controller.js +54 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/views/job-jenkins-projects.html +1 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/views/job-projects-discovery.html +91 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/project-discovery/views/job-projects-parameters.html +77 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-content-views.html +83 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-environments.html +50 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-hostgroups.html +81 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-info.html +117 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-jenkins-projects.html +75 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-jenkins.html +88 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-paths-list.html +72 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-resources.html +86 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details-to-environments.html +51 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/details/views/job-details.html +80 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/jobs.controller.js +40 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/jobs.factory.js +54 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/jobs.module.js +142 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/new/new-job.controller.js +31 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/new/views/new-job-form.html +47 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/new/views/new-job.html +17 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/views/jobs-table-collapsed.html +20 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/views/jobs-table-full.html +66 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/views/jobs.html +19 -0
- data/app/assets/javascripts/foreman_pipeline/jobs/views/pln-path-selector.html +10 -0
- data/app/assets/stylesheets/foreman_pipeline/foreman_pipeline.css +13 -0
- data/app/controllers/foreman_pipeline/api/jenkins_instances_controller.rb +124 -0
- data/app/controllers/foreman_pipeline/api/jenkins_project_params_controller.rb +34 -0
- data/app/controllers/foreman_pipeline/api/jenkins_projects_controller.rb +29 -0
- data/app/controllers/foreman_pipeline/api/jenkins_requests_controller.rb +28 -0
- data/app/controllers/foreman_pipeline/api/jenkins_users_controller.rb +89 -0
- data/app/controllers/foreman_pipeline/api/jobs_controller.rb +271 -0
- data/app/controllers/foreman_pipeline/application_controller.rb +4 -0
- data/app/helpers/foreman_pipeline/application_helper.rb +4 -0
- data/app/lib/actions/foreman_pipeline/jenkins/abstract_jenkins_action.rb +20 -0
- data/app/lib/actions/foreman_pipeline/jenkins/build.rb +35 -0
- data/app/lib/actions/foreman_pipeline/jenkins/build_project.rb +31 -0
- data/app/lib/actions/foreman_pipeline/jenkins/bulk_build.rb +23 -0
- data/app/lib/actions/foreman_pipeline/jenkins/get_build_details.rb +11 -0
- data/app/lib/actions/foreman_pipeline/jenkins/get_build_params.rb +11 -0
- data/app/lib/actions/foreman_pipeline/jenkins/get_version.rb +17 -0
- data/app/lib/actions/foreman_pipeline/jenkins/list.rb +15 -0
- data/app/lib/actions/foreman_pipeline/jenkins/wait_and_poll.rb +33 -0
- data/app/lib/actions/foreman_pipeline/jenkins/wait_for_build.rb +42 -0
- data/app/lib/actions/foreman_pipeline/jenkins/wait_host_ready.rb +36 -0
- data/app/lib/actions/foreman_pipeline/jenkins_instance/abstract_jenkins_instance_action.rb +17 -0
- data/app/lib/actions/foreman_pipeline/jenkins_instance/create_jenkins_instance_keys.rb +45 -0
- data/app/lib/actions/foreman_pipeline/job/create_activation_key.rb +20 -0
- data/app/lib/actions/foreman_pipeline/job/create_host.rb +88 -0
- data/app/lib/actions/foreman_pipeline/job/cv_promote_job_hook.rb +22 -0
- data/app/lib/actions/foreman_pipeline/job/cv_publish_job_hook.rb +22 -0
- data/app/lib/actions/foreman_pipeline/job/deploy_new_host.rb +25 -0
- data/app/lib/actions/foreman_pipeline/job/find_packages_to_install.rb +16 -0
- data/app/lib/actions/foreman_pipeline/job/job_hook.rb +24 -0
- data/app/lib/actions/foreman_pipeline/job/multiple_promotions.rb +18 -0
- data/app/lib/actions/foreman_pipeline/job/promote.rb +38 -0
- data/app/lib/actions/foreman_pipeline/job/redeploy.rb +45 -0
- data/app/lib/actions/foreman_pipeline/job/repo_sync_job_hook.rb +33 -0
- data/app/lib/actions/foreman_pipeline/job/run_job_manually.rb +25 -0
- data/app/lib/actions/foreman_pipeline/job/suspend_until_provisioned.rb +13 -0
- data/app/lib/actions/foreman_pipeline/mixins/ssh_extension.rb +41 -0
- data/app/lib/actions/foreman_pipeline/mixins/uri_extension.rb +14 -0
- data/app/lib/foreman_pipeline/api/rendering.rb +18 -0
- data/app/models/foreman_pipeline/authorization/base_model.rb +31 -0
- data/app/models/foreman_pipeline/authorization/jenkins_instance.rb +8 -0
- data/app/models/foreman_pipeline/authorization/jenkins_project.rb +8 -0
- data/app/models/foreman_pipeline/authorization/jenkins_project_param.rb +8 -0
- data/app/models/foreman_pipeline/authorization/jenkins_user.rb +7 -0
- data/app/models/foreman_pipeline/authorization/job.rb +7 -0
- data/app/models/foreman_pipeline/concerns/compute_resource_extension.rb +11 -0
- data/app/models/foreman_pipeline/concerns/content_view_extension.rb +12 -0
- data/app/models/foreman_pipeline/concerns/content_view_repository_extension.rb +12 -0
- data/app/models/foreman_pipeline/concerns/hostgroup_extension.rb +12 -0
- data/app/models/foreman_pipeline/concerns/kt_environment_extension.rb +18 -0
- data/app/models/foreman_pipeline/concerns/repository_extension.rb +12 -0
- data/app/models/foreman_pipeline/glue/elastic_search/base_model.rb +21 -0
- data/app/models/foreman_pipeline/glue/elastic_search/jenkins_instance.rb +11 -0
- data/app/models/foreman_pipeline/glue/elastic_search/jenkins_project.rb +11 -0
- data/app/models/foreman_pipeline/glue/elastic_search/jenkins_user.rb +11 -0
- data/app/models/foreman_pipeline/glue/elastic_search/job.rb +11 -0
- data/app/models/foreman_pipeline/jenkins_instance.rb +51 -0
- data/app/models/foreman_pipeline/jenkins_project.rb +18 -0
- data/app/models/foreman_pipeline/jenkins_project_param.rb +21 -0
- data/app/models/foreman_pipeline/jenkins_user.rb +15 -0
- data/app/models/foreman_pipeline/job.rb +72 -0
- data/app/models/foreman_pipeline/job_jenkins_project.rb +25 -0
- data/app/models/foreman_pipeline/job_to_environment.rb +19 -0
- data/app/views/foreman/unattended/snippets/_jenkins_instance_pubkey.erb +10 -0
- data/app/views/foreman_pipeline/api/common/async.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/common/index.json.rabl +7 -0
- data/app/views/foreman_pipeline/api/compute_resources/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/compute_resources/show.json.rabl +5 -0
- data/app/views/foreman_pipeline/api/content_views/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/content_views/show.json.rabl +5 -0
- data/app/views/foreman_pipeline/api/environments/show.json.rabl +11 -0
- data/app/views/foreman_pipeline/api/hostgroups/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/hostgroups/show.json.rabl +5 -0
- data/app/views/foreman_pipeline/api/jenkins_instances/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/jenkins_instances/show.json.rabl +7 -0
- data/app/views/foreman_pipeline/api/jenkins_project_params/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/jenkins_project_params/show.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/jenkins_projects/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/jenkins_projects/show.json.rabl +7 -0
- data/app/views/foreman_pipeline/api/jenkins_users/index.json.rabl +2 -0
- data/app/views/foreman_pipeline/api/jenkins_users/show.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/jobs/available_paths.json.rabl +9 -0
- data/app/views/foreman_pipeline/api/jobs/index.json.rabl +3 -0
- data/app/views/foreman_pipeline/api/jobs/show.json.rabl +32 -0
- data/config/mount_engine.rb +3 -0
- data/config/routes.rb +53 -0
- data/db/migrate/20141003121914_create_job_table.rb +13 -0
- data/db/migrate/20141003145152_add_organization_to_jobs_table.rb +9 -0
- data/db/migrate/20141014125836_make_content_view_and_hostgroup_optional_for_job.rb +11 -0
- data/db/migrate/20141029121444_create_test_table.rb +11 -0
- data/db/migrate/20141029125423_add_organization_to_test_table.rb +9 -0
- data/db/migrate/20141030154210_create_jobs_tests_table.rb +12 -0
- data/db/migrate/20141120130350_add_resource_to_job.rb +9 -0
- data/db/migrate/20150121134503_create_jenkins_instances_table.rb +13 -0
- data/db/migrate/20150121134748_add_jenkins_instances_to_job_table.rb +9 -0
- data/db/migrate/20150122155819_add_kt_environment_to_jobs_table.rb +9 -0
- data/db/migrate/20150127101153_add_trigger_options_to_jobs_table.rb +13 -0
- data/db/migrate/20150202180711_add_content_column_to_tests_table.rb +9 -0
- data/db/migrate/20150209145400_add_pubkey_to_jenkins_instance_table.rb +9 -0
- data/db/migrate/20150209160604_add_jenkins_home_to_jenkins_instance_table.rb +9 -0
- data/db/migrate/20150212115234_add_uniqueness_to_jenkins_instance_url.rb +9 -0
- data/db/migrate/20150212125901_add_uniqueness_to_test_name.rb +9 -0
- data/db/migrate/20150213095447_add_cert_path_to_jenkins_instances.rb +9 -0
- data/db/migrate/20150216170951_add_build_step_to_tests_table.rb +9 -0
- data/db/migrate/20150223142315_change_jenkins_instance_cert_path_column.rb +9 -0
- data/db/migrate/20150224090100_create_jenkins_projects_table.rb +19 -0
- data/db/migrate/20150226182211_add_org_to_jenkins_project.rb +9 -0
- data/db/migrate/20150301134121_create_jenkins_project_params_table.rb +16 -0
- data/db/migrate/20150303134951_change_jenkins_project_param_value_column.rb +9 -0
- data/db/migrate/20150304123529_change_jenkins_project_params_table.rb +9 -0
- data/db/migrate/20150305122212_drop_tests_table.rb +5 -0
- data/db/migrate/20150312153833_create_jenkins_users.rb +15 -0
- data/db/migrate/20150313093244_add_jenkins_user_to_jobs.rb +9 -0
- data/db/migrate/20150313115956_change_jenkins_user_owner.rb +9 -0
- data/db/migrate/20150318141859_rename_tables.rb +19 -0
- data/db/migrate/20150323153355_remove_owner_from_jenkins_user.rb +9 -0
- data/db/migrate/20150323165954_add_jenkins_user_to_instance.rb +9 -0
- data/db/migrate/20150323175436_remove_jenkins_user_from_job.rb +9 -0
- data/db/migrate/20150324082437_remove_jenkins_instance_from_user.rb +9 -0
- data/db/migrate/20150324093416_add_promote_to_jobs.rb +9 -0
- data/db/migrate/20150324124034_create_job_path.rb +13 -0
- data/db/migrate/20150408143011_remove_cv_promote_from_job.rb +9 -0
- data/db/migrate/20150408145022_rename_job_path.rb +11 -0
- data/db/migrate/20150923073033_drop_orphaned_table.rb +8 -0
- data/lib/foreman_pipeline.rb +5 -0
- data/lib/foreman_pipeline/engine.rb +67 -0
- data/lib/foreman_pipeline/permissions.rb +3 -0
- data/lib/foreman_pipeline/permissions/jenkins_instance_permissions.rb +25 -0
- data/lib/foreman_pipeline/permissions/jenkins_project_params_permissions.rb +9 -0
- data/lib/foreman_pipeline/permissions/jenkins_projects_permissions.rb +9 -0
- data/lib/foreman_pipeline/permissions/jenkins_request_permissions.rb +9 -0
- data/lib/foreman_pipeline/permissions/jenkins_user_permissions.rb +24 -0
- data/lib/foreman_pipeline/permissions/job_permissions.rb +27 -0
- data/lib/foreman_pipeline/plugin.rb +17 -0
- data/lib/foreman_pipeline/roles.rb +13 -0
- data/lib/foreman_pipeline/tasks/foreman_pipeline_seed.rake +18 -0
- data/lib/foreman_pipeline/tasks/foreman_pipeline_test.rake +34 -0
- data/lib/foreman_pipeline/version.rb +3 -0
- data/test/factories/hostgroup_factory.rb +6 -0
- data/test/factories/jenkins_instance_related_factory.rb +20 -0
- data/test/foreman_pipeline_plugin_test_helper.rb +28 -0
- data/test/unit/job_test.rb +26 -0
- data/test/unit/sanity_test.rb +12 -0
- metadata +327 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class AbstractJenkinsAction < Actions::EntryAction
|
5
|
+
|
6
|
+
def job
|
7
|
+
j = ::ForemanPipeline::Job.find input.fetch(:job_id)
|
8
|
+
fail "no jenkins instance specified for the job with id #{j.id}" if j.jenkins_instance.nil?
|
9
|
+
j.init_run
|
10
|
+
j
|
11
|
+
end
|
12
|
+
|
13
|
+
def jenkins_project
|
14
|
+
::ForemanPipeline::JenkinsProject.find input[:project_id]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module Actions
|
3
|
+
module ForemanPipeline
|
4
|
+
module Jenkins
|
5
|
+
class Build < AbstractJenkinsAction
|
6
|
+
|
7
|
+
def run
|
8
|
+
#are we willing to wait longer than 5 mins until build starts?
|
9
|
+
output[:build_num] = job.jenkins_instance.client.job.build(jenkins_project.name, params, 'build_start_timeout' => 300)
|
10
|
+
output[:project_name] = jenkins_project.name
|
11
|
+
output[:build_params] = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def params
|
15
|
+
project_params = jenkins_project.jenkins_project_params
|
16
|
+
return {} if project_params.empty?
|
17
|
+
template_binding project_params
|
18
|
+
end
|
19
|
+
|
20
|
+
def template_binding(project_params)
|
21
|
+
host = input[:data][:host]
|
22
|
+
activation_key = input[:data][:activation_key]
|
23
|
+
packages = input[:data][:packages]
|
24
|
+
|
25
|
+
project_params.each do |param|
|
26
|
+
param.value = ERB.new(param.value).result(binding)
|
27
|
+
param.format_bool
|
28
|
+
end.map do |param|
|
29
|
+
{param.name => param.value}
|
30
|
+
end.reduce(:merge)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class BuildProject < AbstractJenkinsAction
|
5
|
+
|
6
|
+
def plan(options)
|
7
|
+
sequence do
|
8
|
+
build_task = plan_action(Build, options)
|
9
|
+
wait_task = plan_action(WaitForBuild, :job_id => options[:job_id],
|
10
|
+
:name => options[:project_name],
|
11
|
+
:build_num => build_task.output[:build_num])
|
12
|
+
|
13
|
+
plan_self(:build_status => wait_task.output[:details][:result], :name => options[:project_name])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
output[:status] = input[:build_status]
|
19
|
+
end
|
20
|
+
|
21
|
+
def rescue_strategy_for_self
|
22
|
+
Dynflow::Action::Rescue::Skip
|
23
|
+
end
|
24
|
+
|
25
|
+
def humanized_name
|
26
|
+
"Build Jenkins Project: %s" % input[:name]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class BulkBuild < Actions::ActionWithSubPlans
|
5
|
+
|
6
|
+
def plan(projects, opts)
|
7
|
+
plan_self(:project_ids => projects.map(&:id), :opts => opts)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_sub_plans
|
11
|
+
projects = ::ForemanPipeline::JenkinsProject.where(:id => input[:project_ids])
|
12
|
+
|
13
|
+
packs = input[:opts].delete(:packages)
|
14
|
+
input[:opts][:data].merge!({:packages => packs})
|
15
|
+
|
16
|
+
projects.map do |project|
|
17
|
+
trigger(BuildProject, input[:opts].merge({:project_id => project.id, :project_name => project.name}))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class GetVersion < Actions::EntryAction
|
5
|
+
|
6
|
+
def run
|
7
|
+
instance = ::ForemanPipeline::JenkinsInstance.find input[:id]
|
8
|
+
output[:version] = instance.create_client.get_jenkins_version
|
9
|
+
end
|
10
|
+
|
11
|
+
def humanized_name
|
12
|
+
"Get Jenkins CI version: %s" % input[:name]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class List < AbstractJenkinsAction
|
5
|
+
def run
|
6
|
+
output[:projects] = job.jenkins_instance.client.job.list input[:filter]
|
7
|
+
end
|
8
|
+
|
9
|
+
def humanized_name
|
10
|
+
"List projects in Jenkins Instance: %s" % job.jenkins_instance.name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class WaitAndPoll < AbstractJenkinsAction
|
5
|
+
include Dynflow::Action::Polling
|
6
|
+
include Dynflow::Action::Cancellable
|
7
|
+
|
8
|
+
def external_task
|
9
|
+
output[:result]
|
10
|
+
end
|
11
|
+
|
12
|
+
def done?
|
13
|
+
external_task
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def invoke_external_task
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def external_task=(external_task_data)
|
23
|
+
output[:result] = external_task_data
|
24
|
+
end
|
25
|
+
|
26
|
+
def poll_interval
|
27
|
+
5
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class WaitForBuild < WaitAndPoll
|
5
|
+
|
6
|
+
def poll_interval
|
7
|
+
10
|
8
|
+
end
|
9
|
+
|
10
|
+
def rescue_strategy_for_self
|
11
|
+
Dynflow::Action::Rescue::Skip
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(event = nil)
|
15
|
+
unless event == Dynflow::Action::Skip
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def external_task=(external_task_data)
|
21
|
+
if external_task_data.is_a?(Hash)
|
22
|
+
output[:result] = !external_task_data[:result].nil?
|
23
|
+
if external_task_data[:result] == "FAILURE"
|
24
|
+
fail "Jenkins build failed"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def poll_external_task
|
32
|
+
details = job.jenkins_instance.client.job
|
33
|
+
.get_build_details(input.fetch(:name), input.fetch(:build_num))
|
34
|
+
.with_indifferent_access
|
35
|
+
output[:details] = details
|
36
|
+
details
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Jenkins
|
4
|
+
class WaitHostReady < WaitAndPoll
|
5
|
+
include Mixins::SshExtension
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def poll_external_task
|
10
|
+
status = nil
|
11
|
+
ip = Socket::getaddrinfo(input[:jenkins_instance_hostname], 'www', nil, Socket::SOCK_STREAM)[0][3]
|
12
|
+
Net::SSH.start(ip, 'root', :keys => [input.fetch(:cert_path)]) do |ssh|
|
13
|
+
status = ssh_exec!(ssh, command)
|
14
|
+
end
|
15
|
+
output[:jenkins_ip] = ip
|
16
|
+
output[:status] = status
|
17
|
+
status[2].to_i == 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def command
|
21
|
+
c = []
|
22
|
+
c << "sudo -u jenkins ssh -i #{input[:jenkins_home]}/.ssh/#{input[:jenkins_instance_hostname]} -o StrictHostKeyChecking=no root@#{input[:host_ip]}"
|
23
|
+
c << "'echo"
|
24
|
+
c << echo
|
25
|
+
c << "'"
|
26
|
+
c.join(" ")
|
27
|
+
end
|
28
|
+
|
29
|
+
def echo
|
30
|
+
'"host ready yet?"'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Actions
|
5
|
+
module ForemanPipeline
|
6
|
+
module JenkinsInstance
|
7
|
+
class AbstractJenkinsInstanceAction < Actions::EntryAction
|
8
|
+
include Mixins::SshExtension
|
9
|
+
|
10
|
+
def parse_jenkins_hostname
|
11
|
+
URI(input.fetch(:jenkins_url)).host
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'net/scp'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Actions
|
6
|
+
module ForemanPipeline
|
7
|
+
module JenkinsInstance
|
8
|
+
class CreateJenkinsInstanceKeys < AbstractJenkinsInstanceAction
|
9
|
+
|
10
|
+
def run
|
11
|
+
output[:pubkey] = fetch_pubkey(parse_jenkins_hostname)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch_pubkey(host)
|
15
|
+
buffer = StringIO.new
|
16
|
+
ip = Socket::getaddrinfo(host, 'www', nil, Socket::SOCK_STREAM)[0][3]
|
17
|
+
|
18
|
+
Net::SSH.start(ip, 'root', :keys => [input.fetch(:cert_path)]) do |ssh|
|
19
|
+
status = ssh_exec!(ssh, "ls #{key_location}")[2]
|
20
|
+
ssh.exec!("mkdir #{key_location}") if status > 0
|
21
|
+
ssh.exec! "sed -i s:Defaults\\.*requiretty:#Defaults\\ requiretty:g /etc/sudoers"
|
22
|
+
ssh.exec! "rm -f #{key_location}/#{parse_jenkins_hostname}.pub #{key_location}/#{parse_jenkins_hostname}"
|
23
|
+
ssh.exec! "sudo -u jenkins ssh-keygen -f #{key_location}/#{parse_jenkins_hostname} -t rsa -N '' -q"
|
24
|
+
ssh.scp.download! "#{key_location}/#{parse_jenkins_hostname}.pub", buffer
|
25
|
+
end
|
26
|
+
|
27
|
+
buffer.string
|
28
|
+
end
|
29
|
+
|
30
|
+
def key_location
|
31
|
+
"#{input.fetch(:jenkins_home)}/.ssh"
|
32
|
+
end
|
33
|
+
|
34
|
+
def finalize
|
35
|
+
if output[:pubkey].match(/^ssh-rsa/)
|
36
|
+
output[:status] = 0
|
37
|
+
else
|
38
|
+
output[:status] = 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Job
|
4
|
+
class CreateActivationKey < Actions::EntryAction
|
5
|
+
middleware.use ::Actions::Middleware::KeepCurrentUser
|
6
|
+
|
7
|
+
def run
|
8
|
+
output[:new_key] = ::Katello::ActivationKey.create(
|
9
|
+
name: "key-for-#{input[:name]}",
|
10
|
+
organization_id: input[:organization_id],
|
11
|
+
environment_id: input[:environment_id],
|
12
|
+
content_view_id: input[:content_view_id],
|
13
|
+
user_id: ::User.current.id,
|
14
|
+
cp_id: input[:cp_id]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Actions
|
2
|
+
module ForemanPipeline
|
3
|
+
module Job
|
4
|
+
class CreateHost < Actions::EntryAction
|
5
|
+
middleware.use ::Actions::Middleware::KeepCurrentUser
|
6
|
+
|
7
|
+
def plan(name, hostgroup, compute_resource, options = {})
|
8
|
+
compute_attributes = hostgroup.compute_profile.compute_attributes
|
9
|
+
.where(compute_resource_id: compute_resource.id)
|
10
|
+
.first.vm_attrs
|
11
|
+
|
12
|
+
plan_self name: name,
|
13
|
+
hostgroup_id: hostgroup.id,
|
14
|
+
compute_attributes: compute_attributes,
|
15
|
+
options: options
|
16
|
+
input.update compute_resource_id: compute_resource.id if compute_resource
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
hostgroup = Hostgroup.find(input[:hostgroup_id])
|
21
|
+
location = Location.where(:name => "foreman_pipeline").first_or_create
|
22
|
+
location.subnet_ids = (location.subnet_ids + [hostgroup.subnet_id]).uniq
|
23
|
+
location.save!
|
24
|
+
host = ::Host::Managed.new(
|
25
|
+
name: input[:name],
|
26
|
+
hostgroup: hostgroup,
|
27
|
+
build: true,
|
28
|
+
managed: true,
|
29
|
+
enabled: true,
|
30
|
+
environment: hostgroup.environment,
|
31
|
+
compute_resource_id: input.fetch(:compute_resource_id),
|
32
|
+
compute_attributes: input[:compute_attributes],
|
33
|
+
puppet_proxy: hostgroup.puppet_proxy,
|
34
|
+
puppet_ca_proxy: hostgroup.puppet_ca_proxy,
|
35
|
+
organization_id: input[:options][:org_id],
|
36
|
+
location: location
|
37
|
+
)
|
38
|
+
|
39
|
+
organization_param
|
40
|
+
keys_param
|
41
|
+
|
42
|
+
host.save!
|
43
|
+
jenkins_pubkey_param_for host
|
44
|
+
host.power.start
|
45
|
+
|
46
|
+
output.update host: { id: host.id,
|
47
|
+
name: host.name,
|
48
|
+
ip: host.ip,
|
49
|
+
mac: host.mac,
|
50
|
+
params: host.params }
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def kt_org
|
56
|
+
::Organization.find(input[:options][:org_id]).name
|
57
|
+
end
|
58
|
+
|
59
|
+
def organization_param
|
60
|
+
org_cp = ::CommonParameter.find_by_name('kt_org')
|
61
|
+
if org_cp.nil?
|
62
|
+
::CommonParameter.create(:name => 'kt_org', :value => kt_org)
|
63
|
+
else
|
64
|
+
org_cp.update_attributes(:value => kt_org)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def keys_param
|
69
|
+
keys_cp = ::CommonParameter.find_by_name('kt_activation_keys')
|
70
|
+
if keys_cp.nil?
|
71
|
+
::CommonParameter.create(:name => 'kt_activation_keys', :value => input[:options][:activation_key][:name])
|
72
|
+
else
|
73
|
+
keys_cp.update_attributes(:value => input[:options][:activation_key][:name])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def jenkins_pubkey
|
78
|
+
::ForemanPipeline::JenkinsInstance.find(input.fetch(:options).fetch(:jenkins_instance_id)).pubkey
|
79
|
+
end
|
80
|
+
|
81
|
+
def jenkins_pubkey_param_for(host)
|
82
|
+
::HostParameter.create(:name => 'foreman_pipeline_jenkins_pubkey', :value => jenkins_pubkey, :host => host)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|