diff --git a/.gitignore b/.gitignore index e56810a..e70c7f1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ pip-log.txt etc/*.conf tools/lintstack.head.py tools/pylint_exceptions +*.zip #Linux swap file *.swp diff --git a/murano-apps/Jenkins/package/Classes/Jenkins.yaml b/murano-apps/Jenkins/package/Classes/Jenkins.yaml index 26da9ab..033a839 100644 --- a/murano-apps/Jenkins/package/Classes/Jenkins.yaml +++ b/murano-apps/Jenkins/package/Classes/Jenkins.yaml @@ -88,17 +88,25 @@ Methods: - If: $.gerrit != null Then: + - If: $.gerrit.instance.assignFloatingIp + Then: + - $host: $.gerrit.instance.floatingIpAddress + Else: + - $host: $.gerrit.instance.ipAddresses[0] + - $.instance.setHieraValue('gerrit_host', $host) - $.installGerritPlugin() - $._environment.reporter.report($this, 'Wait while Gerrit is being deployed...') - $.gerrit.deploy() - $._environment.reporter.report($this, 'Creating "jenkins" account in Gerrit...') - $.createGerritAccount() - - $.configureGerritPlugin($.gerrit) + - $.configureGerritPlugin() - $.gerrit.createLabelVerified() - $._upgradeGitPlugin() - $.configureUser() + - $.installJJB() + - If: $.instance.assignFloatingIp Then: - $host: $.instance.floatingIpAddress @@ -191,17 +199,7 @@ Methods: - $.instance.agent.call($template, $resources) configureGerritPlugin: - Arguments: - - gerrit: - Contract: $.class(ci_cd_pipeline_murano_app:Gerrit).notNull() Body: - - If: $gerrit.instance.assignFloatingIp - Then: - - $host: $gerrit.instance.floatingIpAddress - Else: - - $host: $gerrit.instance.ipAddresses[0] - # Set gerrit related properties. - - $.instance.setHieraValue('gerrit_host', $host) - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Configure Jenkins Gerrit Trigger plugin...') - $template: $resources.yaml('ConfigureGerritPlugin.template') @@ -224,3 +222,20 @@ Methods: - $resources: new(sys:Resources) - $template: $resources.yaml('JenkinsUser.template') - $.instance.agent.call($template, $resources, 100) + + installJJB: + Body: + - $resources: new(sys:Resources) + - $linux: new(conf:Linux) + - $._environment.reporter.report($this, 'Installing and configuring Jenkins Job Builder...') + - $script: $resources.string('scripts/update_jobs.sh') + - $linux.putFile($.instance.agent, $script, '/usr/local/bin/update_jobs.sh') + - $script: $resources.string('scripts/install_jjb.pp') + - $linux.putFile($.instance.agent, $script, '/usr/local/bin/install_jjb.pp') + - $linux.runCommand($.instance.agent, 'puppet apply /usr/local/bin/install_jjb.pp') + - If: $.gerrit != null + Then: + - $._environment.reporter.report($this, 'Switching to project-config from installed Gerrit...') + - $script: $resources.string('scripts/switch_to_local_project_config.sh') + - $linux.putFile($.instance.agent, $script, '/usr/local/bin/switch_to_local_project_config.sh') + - $linux.runCommand($.instance.agent, 'bash /usr/local/bin/switch_to_local_project_config.sh') \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/configure_ldap/manifests/init.pp b/murano-apps/Jenkins/package/Resources/scripts/configure_ldap/manifests/init.pp index d2c8c58..0fbcdbe 100644 --- a/murano-apps/Jenkins/package/Resources/scripts/configure_ldap/manifests/init.pp +++ b/murano-apps/Jenkins/package/Resources/scripts/configure_ldap/manifests/init.pp @@ -16,17 +16,4 @@ class configure_ldap ( mode => '0644', content => template('configure_ldap/config.erb'), } - file { '/etc/jenkins_jobs/jenkins_jobs.ini': - ensure => present, - }-> - file_line { 'Provide valid username to jjb config': - path => '/etc/jenkins_jobs/jenkins_jobs.ini', - line => "user=${admin_name}", - match => "^user=gerrig.*$", - }-> - file_line { 'Provide valid password to jjb config': - path => '/etc/jenkins_jobs/jenkins_jobs.ini', - line => "password=${admin_password}", - match => "^password=.*$", - } } \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/install_jjb.pp b/murano-apps/Jenkins/package/Resources/scripts/install_jjb.pp new file mode 100644 index 0000000..ee5904b --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/install_jjb.pp @@ -0,0 +1,33 @@ +node default { + + $username = hiera('ldap_root_user', 'jenkins') + $password = hiera('ldap_root_password', '') + $project_config_repo = hiera('project_config_repo') + + if ! defined(Class['project_config']) { + class { 'project_config': + url => $project_config_repo, + base => '', + } + } + class { '::jenkins::job_builder': + url => 'http://localhost:8080', + username => $username, + password => $password, + jenkins_jobs_update_timeout => 1200, + git_revision => 'master', + git_url => 'https://git.openstack.org/openstack-infra/jenkins-job-builder', + config_dir => $::project_config::jenkins_job_builder_config_dir, + require => $::project_config::config_dir, + extensions => [ + {'name' => 'job_builder', 'parameters' => [{'name' => 'ignore_cache', 'value' => 'True'}]} + ], + } + cron { "update_list_of_jobs": + user => 'root', + ensure => present, + command => "bash /usr/local/bin/update_jobs.sh", + hour => '*', + minute => '*/5', + } +} \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/site.pp b/murano-apps/Jenkins/package/Resources/scripts/site.pp index 19a774d..2bc1525 100644 --- a/murano-apps/Jenkins/package/Resources/scripts/site.pp +++ b/murano-apps/Jenkins/package/Resources/scripts/site.pp @@ -1,16 +1,13 @@ node default { - if ! defined(Class['project_config']) { - class { 'project_config': - url => hiera('project_config_repo'), - } - } - - class { 'openstack_project::jenkins': + class { 'openstackci::jenkins_master': + logo => 'openstack.png', + serveradmin => 'webmaster@${::fqdn}', jenkins_password => '', jenkins_ssh_private_key => hiera('jenkins_ssh_private_key_contents'), + jenkins_ssh_public_key => hiera('jenkins_ssh_pubkey_contents'), ssl_cert_file => '/etc/ssl/certs/ssl-cert-snakeoil.pem', ssl_key_file => '/etc/ssl/private/ssl-cert-snakeoil.key', - ssl_chain_file => '', + manage_jenkins_jobs => false, } } \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh b/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh new file mode 100644 index 0000000..7cd0249 --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/switch_to_local_project_config.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Cloning 'project-config' from deployed Gerrit + +GERRIT_URL=`hiera -c /etc/puppet/hiera.yaml gerrit_host` +su jenkins -c "git clone ssh://jenkins@$GERRIT_URL:29418/open-paas/project-config /tmp/project-config/" + +# Removing old project-config + +rm -rf /etc/project-config + +# Creating of new /etc/project-config folder and changing its owner +# to 'jenkins' to have an ability to pull new changes under 'jenkins' + +cp -R /tmp/project-config/ /etc/ +chown -R jenkins:jenkins /etc/project-config +cp -R /etc/project-config/jenkins/jobs/* /etc/jenkins_jobs/config + +# Updating jobs' config + +/usr/local/bin/jenkins-jobs update --delete-old /etc/jenkins_jobs/config + +# Removing temporary folder + +rm -rf /tmp/project-config diff --git a/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh b/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh new file mode 100644 index 0000000..3db214d --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/update_jobs.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +cd /etc/project-config + +# Check whether we have local Gerrit installed or not. +# If yes, then 'git pull' should be executed under 'jenkins' user + +GERRIT_URL=`hiera -c /etc/puppet/hiera.yaml gerrit_host` + +if [ $GERRIT_URL != "nil" ]; then + echo "Pulling changes from installed Gerrit" + su jenkins -c "git pull" +else + echo "Pulling changes from upsteam Gerrit" + git pull +fi + +cp -R /etc/project-config/jenkins/jobs/* /etc/jenkins_jobs/config +/usr/local/bin/jenkins-jobs update --delete-old /etc/jenkins_jobs/config