I create chef bits that create jenkins build jobs. This way I can "create the thing that creates the things." I can reset the state of things by rm -rf *-config.xml jobs/* on the jenkins server, restart jenkins, then run chef-client and everything gets put back together automatically. This also allows me to change the run jobs in real time, but then reset everything when I'm done.
recipes/jenkins-builder.rb
pipelines = []
dashboards = []
region_name = "us-east-1"
domain_name = "opsautohtc.net"
deployment_name = "Ogashi"
pipelines.push({
:name => "Launch %s" % deployment_name,
:num_builds => 3,
:description => "
Prism
- Cloud: AWS
- Region: us-east-1
- Account: HTC CS DEV
- Owner: Bryan Kroger ( bryan_kroger@htc.com )
:refresh_freq => 3,
:first_job_name => "CloudFormation.%s.%s.%s" % [deployment_name, region_name, domain_name],
:build_view_title => "Launch %s" % deployment_name
})
cloudrim_battle_theater deployment_name do
action :jenkins_cloud_formation
az_name "us-east-1b"
git_url "git@gitlab.dev.sea1.csh.tc:operations/deployments.git"
region_name region_name
domain_name domain_name
end
cloudrim_battle_theater deployment_name do
action :jenkins_exec_helpers
az_name "us-east-1b"
git_url "git@gitlab.dev.sea1.csh.tc:operations/deployments.git"
region_name region_name
domain_name domain_name
end
dashboards.push({ :name => deployment_name, :region_name => "us-east-1" })
template "/var/lib/jenkins/jenkins-data/config.xml" do
owner "jenkins"
group "jenkins"
source "jenkins/config.xml.erb"
#notifies :reload, "service[jenkins]"
variables({ :pipelines => pipelines, :dashboards => dashboards })
end
cloudrim/providers/battle_theater.rb:
def action_jenkins_exec_helpers()
region_name = new_resource.region_name
domain_name = new_resource.domain_name
deployment_name = new_resource.name
proxy_url = "http://ops.prism.%s.int.%s:3128" % [region_name, domain_name]
proxy = "HTTP_PROXY='%s' http_proxy='%s' HTTPS_PROXY='%s' https_proxy='%s'" % [proxy_url, proxy_url, proxy_url, proxy_url]
job_name = "ExecHelper.chef-client.%s.%s.%s" % [deployment_name, region_name, domain_name]
job_config = ::File.join(node[:jenkins][:server][:data_dir], "#{job_name}-config.xml")
jenkins_job job_name do
action :nothing
config job_config
end
template job_config do
owner "jenkins"
group "jenkins"
source "jenkins/htc_pssh_cmd.xml.erb"
cookbook "opsauto"
variables({
#:cmd => "%s sudo chef-client -j /etc/chef/dna.json" % proxy,
:cmd => "%s sudo chef-client" % proxy,
:hostname => "ops.prism",
:domain_name => domain_name,
:region_name => region_name,
:deployment_name => deployment_name
})
notifies :update, resources(:jenkins_job => job_name), :immediately
end
[...]
end
No comments:
Post a Comment