Namespaces: =: org.openstack.ci_cd_pipeline_murano_app std: io.murano sys: io.murano.system ci_cd_pipeline_murano_app: org.openstack.ci_cd_pipeline_murano_app puppet: org.openstack.ci_cd_pipeline_murano_app.puppet conf: io.murano.configuration Name: Jenkins Extends: std:Application Properties: name: Contract: $.string().notNull() ldap: Contract: $.class(OpenLDAP) gerrit: Contract: $.class(ci_cd_pipeline_murano_app:Gerrit) instance: Contract: $.class(puppet:PuppetInstance).notNull() cfplugin: Contract: $.bool() Default: false dockerplugin: Contract: $.bool() Default: false gitUser: Contract: $.string() gitEmail: Contract: $.string() systemConfigRepo: Contract: $.class(puppet:SystemConfig) Methods: initialize: Body: - $._environment: $.find(std:Environment).require() deploy: Body: - super($this, $.deploy()) - If: not $.getAttr(deployed, false) Then: - $._environment.reporter.report($this, 'Creating security group for Jenkins') - $securityGroupIngress: - ToPort: 8080 FromPort: 8080 IpProtocol: tcp External: true - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) - $._environment.reporter.report($this, 'Creating VM for Jenkins "{0}"'.format($.instance.name)) - $.instance.deploy() - $._environment.reporter.report($this, 'Jenkins VM "{0}" with id {1} created'.format($.instance.name, $.instance.openstackId)) # initialize System Config - If: $.systemConfigRepo = null Then: - $this.systemConfig: new(puppet:SystemConfig) Else: - $this.systemConfig: $.systemConfigRepo - $this.systemConfig.installOnTheNode($this.instance) - $resources: new(sys:Resources) - $template: $resources.yaml('DeployJenkins.template') - $._environment.reporter.report($this, 'Jenkins is deploying...') - $.instance.agent.call($template, $resources) - If: $.ldap != null Then: - $._environment.reporter.report($this, 'Jenkins waits OpenLDAP to be deployed...') - $.ldap.deploy() - $.connectLDAP() - If: $.cfplugin Then: - $._environment.reporter.report($this, 'Installing CF plugin...') - $template: $resources.yaml('InstallCFPlugin.template') - $.instance.agent.call($template, $resources) - If: $.dockerplugin Then: - $._environment.reporter.report($this, 'Installing Docker Build and Publish plugin...') - $template: $resources.yaml('InstallDockerPlugin.template') - $.instance.agent.call($template, $resources) - If: $.gitUser != null and $.gitEmail != null Then: - $.configureGitPlugin($.gitUser, $.gitEmail) - $.configureZMQPlugin() - $.configureMavenPlugin() - 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.createLabels() - $._upgradeGitPlugin() - $.configureUser() - $.installJJB() - If: $.instance.assignFloatingIp Then: - $host: $.instance.floatingIpAddress Else: - $host: $.instance.ipAddresses[0] - $._environment.reporter.report($this, 'Jenkins is available at http://{0}:8080'.format($host)) - $.setAttr(deployed, true) connectLDAP: Body: - $ldapInstance: $.ldap.instance - If: $ldapInstance.assignFloatingIp Then: - $ldapHost: $ldapInstance.floatingIpAddress Else: - $ldapHost: $ldapInstance.ipAddresses[0] - $data: ldap_ip: $ldapHost ldap_domain: $.ldap.domain ldap_root_user: $.ldap.ldapRootUser ldap_root_password: $.ldap.ldapRootPass - $this.instance.putHieraData($data) - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Installing jenkins LDAP plugin...') - $template: $resources.yaml('InstallPlugins.template').bind({plugins => ldap}) - $.instance.agent.call($template, $resources) - $._environment.reporter.report($this, 'LDAP plugin is installed.') - $._environment.reporter.report($this, 'Connecting Jenkins to OpenLDAP server...') - $template: $resources.yaml('ConnectLDAP.template') - $.instance.agent.call($template, $resources) - $._environment.reporter.report($this, 'Jenkins is connected to OpenLDAP server!') createGerritAccount: Body: - $key: $.instance.getHieraValue('jenkins_ssh_pubkey_contents') - $.gerrit.createAccount('Non-Interactive Users', 'jenkins', 'jenkins@mail.com', $key, 'jenkins') configureZMQPlugin: Body: - $._environment.reporter.report($this, 'Creating security group for ZMQ Event publisher') - $securityGroupIngress: - ToPort: 8888 FromPort: 8888 IpProtocol: tcp External: true - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) - $._environment.stack.push() - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Configure Jenkins ZMQ Event Publisher plugin...') - $template: $resources.yaml('ConfigureZMQ.template') - $.instance.agent.call($template, $resources) configureGearmanPlugin: Arguments: - host: Contract: $.string().notNull() - port: Contract: $.int() Default: 4730 Body: - $.instance.setHieraValue('gearman_host', $host) - $.instance.setHieraValue('gearman_port', $port) - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Configure Jenkins Gearman plugin...') - $template: $resources.yaml('ConfigureGearman.template') - $.instance.agent.call($template, $resources) configureGitPlugin: Arguments: - gitUser: Contract: $.string().notNull() - gitEmail: Contract: $.string().notNull() Body: - $.instance.setHieraValue('git_user', $gitUser) - $.instance.setHieraValue('git_user_email', $gitEmail) - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Configure Jenkins Git plugin...') - $template: $resources.yaml('ConfigureGit.template') - $.instance.agent.call($template, $resources) configureMavenPlugin: Body: - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Configure Jenkins Maven plugin...') - $template: $resources.yaml('ConfigureMaven.template') - $.instance.agent.call($template, $resources) installGerritPlugin: Body: - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Installing Gerrit Trigger plugin...') - $template: $resources.yaml('InstallGerritPlugin.template') - $.instance.agent.call($template, $resources) configureGerritPlugin: Body: - $resources: new(sys:Resources) - $._environment.reporter.report($this, 'Configure Jenkins Gerrit Trigger plugin...') - $template: $resources.yaml('ConfigureGerritPlugin.template') - $.instance.agent.call($template, $resources) _upgradeGitPlugin: Body: - $resource: new(sys:Resources) - $._environment.reporter.report($this, 'Upgrading jenkins git plugin...') - $template: $resource.yaml('InstallPlugins.template').bind({plugins => git}) - $.instance.agent.call($template, $resource) configureCredentials: Body: - $._environment.reporter.report($this, 'Configuring standard SSH credentials for jenkins slaves...') - $resources: new(sys:Resources) - $template: $resources.yaml('ConfigureCredentials.template') - $.instance.agent.call($template, $resources) # Return current credentials id. (see scripts/configure_credentials/files/credentials.xml) - $._environment.reporter.report($this, 'SSH Credentials are configured.') - Return: '8039f3e0-1eb6-4505-81bc-c616a31fd7d1' destroy: Body: - $.reportDestroyed() - $.setAttr(deployed, false) configureUser: Body: - $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') - $manifest: $resources.string('scripts/install_jjb.pp') - $this.instance.applyManifest($manifest, 180) - 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')