diff --git a/murano-apps/Jenkins/package/Classes/Jenkins.yaml b/murano-apps/Jenkins/package/Classes/Jenkins.yaml index 67384e8..2980aea 100644 --- a/murano-apps/Jenkins/package/Classes/Jenkins.yaml +++ b/murano-apps/Jenkins/package/Classes/Jenkins.yaml @@ -20,6 +20,10 @@ Properties: cfplugin: Contract: $.bool() Default: false + gitUser: + Contract: $.string() + gitEmail: + Contract: $.string() Methods: initialize: @@ -64,6 +68,7 @@ Methods: - $.instance.agent.call($template, $resources) - $.configureZMQPlugin() + - $.configureGitPlugin($.gitUser, $.gitEmail) - If: $.instance.assignFloatingIp Then: @@ -123,6 +128,33 @@ Methods: - $template: $resources.yaml('ConfigureGearman.template') - $.instance.agent.call($template, $resources) + configureGitPlugin: + Arguments: + - gitUser: + Contract: $.string() + - gitEmail: + Contract: $.string() + Body: + # Set defaults if not provided. + - If: $gitUser in ['', null] + Then: + - $gitUsername: 'user' + Else: + - $gitUsername: $gitUser + + - If: $gitEmail in ['', null] + Then: + - $gitUserEmail: 'user@mirantis.test' + Else: + - $gitUserEmail: $gitEmail + + - $.instance.setHieraValue('git_user', $gitUsername) + - $.instance.setHieraValue('git_user_email', $gitUserEmail) + - $resources: new(sys:Resources) + - $._environment.reporter.report($this, 'Configure Jenkins Git plugin...') + - $template: $resources.yaml('ConfigureGit.template') + - $.instance.agent.call($template, $resources) + destroy: Body: - $.reportDestroyed() diff --git a/murano-apps/Jenkins/package/Resources/ConfigureGit.template b/murano-apps/Jenkins/package/Resources/ConfigureGit.template new file mode 100644 index 0000000..d63389e --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/ConfigureGit.template @@ -0,0 +1,19 @@ +FormatVersion: 2.1.0 +Version: 1.0.0 +Name: Configure Git + +Body: | + return configureGit().stdout + +Scripts: + configureGit: + Type: Application + Version: 1.0.0 + EntryPoint: configure_git.sh + Files: + - configure_git/templates/hudson.plugins.git.GitSCM.xml.erb + - configure_git/manifests/init.pp + - configure_git.pp + Options: + captureStdout: true + captureStderr: true \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/configure_git.pp b/murano-apps/Jenkins/package/Resources/scripts/configure_git.pp new file mode 100644 index 0000000..80b5090 --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/configure_git.pp @@ -0,0 +1,6 @@ +node default { + class { 'configure_git': + git_user => hiera('git_user'), + git_user_email => hiera('git_user_email') + } +} \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/configure_git.sh b/murano-apps/Jenkins/package/Resources/scripts/configure_git.sh new file mode 100644 index 0000000..244e98b --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/configure_git.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# No error if already exists. +mkdir -p /etc/puppet/modules/configure_git +mkdir -p /etc/puppet/modules/configure_git/manifests/ +mkdir -p /etc/puppet/modules/configure_git/templates/ + +cp configure_git/manifests/init.pp /etc/puppet/modules/configure_git/manifests/ +cp configure_git/templates/hudson.plugins.git.GitSCM.xml.erb /etc/puppet/modules/configure_git/templates/ + +puppet apply configure_git.pp diff --git a/murano-apps/Jenkins/package/Resources/scripts/configure_git/manifests/init.pp b/murano-apps/Jenkins/package/Resources/scripts/configure_git/manifests/init.pp new file mode 100644 index 0000000..f525a57 --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/configure_git/manifests/init.pp @@ -0,0 +1,17 @@ +class configure_git ( + $git_user = undef, + $git_user_email = undef +) { + service { 'jenkins': + ensure => running, + enable => true, + } + file { '/var/lib/jenkins/hudson.plugins.git.GitSCM.xml': + notify => Service['jenkins'], + ensure => present, + owner => 'jenkins', + group => 'jenkins', + mode => '0644', + content => template('configure_git/hudson.plugins.git.GitSCM.xml.erb'), + } +} \ No newline at end of file diff --git a/murano-apps/Jenkins/package/Resources/scripts/configure_git/templates/hudson.plugins.git.GitSCM.xml.erb b/murano-apps/Jenkins/package/Resources/scripts/configure_git/templates/hudson.plugins.git.GitSCM.xml.erb new file mode 100644 index 0000000..7fe3b19 --- /dev/null +++ b/murano-apps/Jenkins/package/Resources/scripts/configure_git/templates/hudson.plugins.git.GitSCM.xml.erb @@ -0,0 +1,7 @@ + + + 1 + <%= git_user %> + <%= git_user_email %> + false + \ No newline at end of file diff --git a/murano-apps/Jenkins/package/UI/ui.yaml b/murano-apps/Jenkins/package/UI/ui.yaml index 5ccc18e..5769643 100644 --- a/murano-apps/Jenkins/package/UI/ui.yaml +++ b/murano-apps/Jenkins/package/UI/ui.yaml @@ -6,6 +6,8 @@ Application: name: $.appConfiguration.name ldap: $.appConfiguration.OpenLDAP cfplugin: $.appConfiguration.cfplugin + gitUser: $.appConfiguration.gitUser + gitEmail: $.appConfiguration.gitEmail instance: ?: type: io.murano.opaas.puppet.PuppetInstance @@ -45,6 +47,20 @@ Forms: required: false description: >- Specify OpenLDAP domain for authentication + - name: gitUser + type: string + label: Git username + required: false + regexpValidator: '^[-_\w]+$' + description: >- + Enter a desired name for git user + - name: gitEmail + type: string + label: Git user email + required: false + regexpValidator: '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' + description: >- + Enter a desired email for git user - instanceConfiguration: fields: - name: title