<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
enable-openshift-ci: full example using openshift-java-client
</h3>
<span style="margin-bottom: 10px;">
modified by <a href="https://community.jboss.org/people/adietish">Andre Dietisheim</a> in <i>JBoss Tools</i> - <a href="https://community.jboss.org/docs/DOC-19828">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>This wiki entry will show you a complete example using the <a class="jive-link-external-small" href="https://github.com/openshift/openshift-java-client">openshift-java-client</a>. The openshift-java-client is a java library that allows you talk to the OpenShift PaaS programmatically. </p><p>This article will develop a command line tool in java, that takes a project on your disk and sets up a <a class="jive-link-external-small" href="http://jenkins-ci.org/">jenkins</a> build for it on OpenShift. </p><p>The example is hosted on github at <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci">https://github.com/adietish/enable-openshift-ci</a> and you may freely reuse, redistribute or modify the code since it's licensed under the <a class="jive-link-external-small" href="http://www.eclipse.org/legal/epl-v10.html">Eclipse Public License</a>.</p><h1>Requirements</h1><ul><li>your project is required to build with maven and has to be committed to a git repository</li><li>you need an account on <a class="jive-link-external-small" href="https://openshift.redhat.com/app/">OpenShift</a>. (If you have no account yet, you'd have to <a class="jive-link-external-small" href="https://openshift.redhat.com/app/account/new">signup</a> first)</li><li>you require 3 free application slots (given that you have a default quota of 3 applications).</li><li>you need to have git available on your command-line (enable-openshift-ci is using it to deploy)</li></ul><h1>Usage</h1><pre class="jive-pre"><code class="jive-code">-p     the project (folder) that we'll enable CI for
-pw   the OpenShift password
-u     the OpenShift user
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>You have to tell enable-openshift-ci where it'll find your project (<strong>-p</strong>), your OpenShift user (<strong>-u</strong>) and password (-<strong>pw</strong>). </p><p>An exemplary call using the jar would look the following:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code">java -jar target/enable-openshift-ci-0.0.1-SNAPSHOT-jar-with-dependencies.jar -p <PATH_TO_PROJECT> -a test -u <USER> -pw <PASSWORT></code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Calling it using maven would look like this:</p><p>mvn test -Du=<USER> -Dpw=<PASSWORD> -Dp=<PATH_TO_PROJECT></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Given that my project at /home/adietish/git/kitchensink is a maven project and already within a git repository, it will log into my OpenShift account <MYACCOUNT>/<MYPASS>. It will then create an application kitchensink and merge it's initial content into my local proect. It will then create a jenkins application on OpenShift, add a jenkins-client cartridge to the kitchensink application and push the local project to OpenShift. This push will then trigger the build on the jenkins instance.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>Implementation</h1><h2>Openshift-java-client</h2><p>First of all enable-openshift-ci requires the <a class="jive-link-external-small" href="https://github.com/openshift/openshift-java-client">openshift-java-client</a>. The client library is available as artifact from maven central. Enable-openshift-ci is a maven project, we can add the openshift-java-client to its classpath by simply using the following snippet in the pom:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><dependency>          <groupId>com.openshift</groupId>          <artifactId>openshift-java-client</artifactId>          <version>2.0.0</version></dependency></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>A few classes</h2><ul><li><a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/Main.java">Main</a>: Bootstrapping</li><li><a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/Parameters.java">Parameters</a>: Parses, validates and holds the command line parameters</li><li><a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java">OpenShiftCI</a>: Creates the OpenShift CI, pushes your project to it</li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2><a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/Parameters.java">Parameters</a>: Talk to me via command line parameters</h2><p>To keep the example simple, we'll stick to a GUI-less programm, that you control by command-line arguments. The <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/Parameters.java">Parameters</a> class holds all parameters that were given at the command line. It'll check them for validity and offer them for further processing.</p><p>What's important in this context is that the Parameters class will ensure that your project exists, that it is a <a class="jive-link-external-small" href="http://maven.apache.org/">maven</a> project and that it is shared with a <a class="jive-link-external-small" href="http://git-scm.com/">git</a> repository.  I used the <a class="jive-link-external-small" href="http://jcommander.org/">JCommander</a> library by Cédric Beust. It allows me to annotate instance variables and get the parsing, validation, conversion and usage printing done very easily. For the sake of brevity, I'll skip any further detailled discussion.</p><h2><a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java">OpenShiftCI</a>: I want my CI instance!</h2><p>The <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java">OpenShiftCI</a> class is where it all happens. It'll connect to your <a class="jive-link-external-small" href="https://openshift.redhat.com/app/">OpenShift</a> account, create your Jenkins instance and push your project to it. <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L57">OpenShiftCI#create</a> looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">IUser user = createUser();
IDomain domain = getOrCreateDomain(user);
IApplication application = getOrCreateApplication(project.getName(), domain);
IApplication jenkinsApplication = getOrCreateJenkins(domain);
waitForApplication(jenkinsApplication);
waitForApplication(application);
embedJenkinsClient(application);
ensureQuotaNotReached(domain);
deployToOpenShift(application);
</code></pre><h2>Let's get in touch with OpenShift</h2><p>Before enable-openshift-ci can manipulate resources on OpenShift, it has to connect to it. It asks the <a class="jive-link-external-small" href="https://github.com/openshift/openshift-java-client/blob/master/src/main/java/com/openshift/client/OpenShiftConnectionFactory.java">OpenShiftConnectionFactory</a> for a new connection. The first required parameter is the url of the OpenShift PaaS. You may either hard code it or ask the OpenShift configuration for it:</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>new</b></font> OpenShiftConfiguration().getLibraServer()
</code></pre><p>The connection factory also asks for a meaningful client id. We'll use <span style="color: #dd1144; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">"enable-openshift-ci"</span>. </p><p>Last but not least, you also have to give it your OpenShift credentials.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">   String openshiftServer = <font color="navy"><b>new</b></font> OpenShiftConfiguration().getLibraServer();
   IOpenShiftConnection connection = <font color="navy"><b>new</b></font> OpenShiftConnectionFactory().getConnection(<font color="red">"enable-openshift-ci"</font>, <font color="red">"<user>"</font>, <font color="red">"<password>"</font>, openshiftServer);
</code></pre><p>Once you have your connection you can get your user instance which will allow you to create your domain and applications:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">IUser user = connection.getUser();
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In enable-openshift-ci you'll find this initizalization in <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L75">OpenShiftCI#createUser</a>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>Now I need a domain</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>All resources on OpenShift are bound to a domain. We therefore have to make sure we have a domain in a first step. We actually check if you have a domain and create one if you dont. <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L84">OpenShiftCI#getOrCreateDomain</a>:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" id="LC84" style="padding: 0 0 0 10px; background-color: #ffffcc;"><span class="n">IDomain</span> <span class="n">domain</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">user</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getDefaultDomain</span><span class="o" style="font-weight: bold;">();</span></p><p class="line" id="LC86" style="padding: 0 0 0 10px;"><span class="k" style="font-weight: bold;">if</span> <span class="o" style="font-weight: bold;">(</span><span class="n">domain</span> <span class="o" style="font-weight: bold;">==</span> <span class="kc" style="font-weight: bold;">null</span><span class="o" style="font-weight: bold;">)</span> <span class="o" style="font-weight: bold;">{</span></p><p class="line" id="LC87" style="padding: 0 0 0 10px;"><span class="n">   domain</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">user</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">createDomain</span><span class="o" style="font-weight: bold;">(</span><span class="n">DEFAULT_DOMAIN_NAME</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC89" style="padding: 0 0 0 10px;"><span class="o" style="font-weight: bold;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>Let's get an application for my project</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>We now need an application for the project we want to enable jenkins for. The application will provide us the infrastructure that we need for our application (the git-repository, the application server etc.). Enable-openshift-ci now checks if there's an application with the very same as the project.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">IApplication</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">application</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="o" style="font-weight: bold;">=</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">domain</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getApplicationByName</span><span class="o" style="font-weight: bold;">(</span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">name</span><span class="o" style="font-weight: bold;">);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>If there's already one, it'll check for it's type (the cartridge).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">ICartridge</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">JBOSSAS_7</span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">.equals<span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; font-weight: bold; background-color: #ffffff;">(</span>application</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getCartridge</span><span class="o" style="font-weight: bold;">())</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Enable-openshift-ci requires a maven aka java project. We therefore need a jbossas-7 application on OpenShift. We therefore fail if the application that we found does not match the required cartridge. If there's no application with the given name yet, we'll create a new one.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">IApplication application</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="o" style="font-weight: bold;">=</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">domain</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">createApplication</span><span class="o" style="font-weight: bold;">(</span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">name</span><span class="o" style="font-weight: bold;">,</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">ICartridge</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">JBOSSAS_7</span><span class="o" style="font-weight: bold;">);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>You can have a look at the implementation in <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L94">OpenShiftCI#getOrCreateApplication</a> to spot all details.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>OpenShift, gimme my CI instance!</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>We now created an application that OpenShift builds whenever we push to it's git repository. The build is executed within the git push. To have a jenkins CI instance doing that work, we'd have to add a jenkins application and connect both. We'll show you how in the upcoming steps:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L110">OpenShiftCI#getOrCreateJenkins</a> first checks if there are any jenkins applications within your domain.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">List</span><span class="o" style="font-weight: bold;"><</span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">IApplication</span><span class="o" style="font-weight: bold;">></span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">jenkinsApplications</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="o" style="font-weight: bold;">=</span><span style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"> </span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">domain</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getApplicationsByCartridge</span><span class="o" style="font-weight: bold;">(</span><span class="n" style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;">ICartridge</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">JENKINS_14</span><span class="o" style="font-weight: bold;">);</span></p><p><span class="o">if(jenkinsApplications.isEmpty()) {</span><span class="o" style="font-weight: bold;"><br/></span></p><p><span class="o">   ...</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>If it spots an jenkins instance, itll leave this step alone, it wont need another jenkins application. If there's none yet, it'll create a new jenkins-application and print it's url and credentials OpenShift setup for us:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" id="LC115" style="padding: 0 0 0 10px;"><span class="n">IApplication jenkins</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">domain</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">createApplication</span><span class="o" style="font-weight: bold;">(</span><span class="n">DEFAULT_JENKINS_NAME</span><span class="o" style="font-weight: bold;">,</span> <span class="n">ICartridge</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">JENKINS_14</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC116" style="padding: 0 0 0 10px;"><span class="n">System</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">out</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">println</span><span class="o" style="font-weight: bold;">(</span><span class="n">jenkins</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getCreationLog</span><span class="o" style="font-weight: bold;">());</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>We now have to connect both applications. We have to tell the application for your project to build within our jenkins instance, the one we found or created in the prior step. Before doing so, we have to make sure both applications are reachable and eventually <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L116">wait</a> for them to become ready:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" id="LC118" style="padding: 0 0 0 10px;"><span class="n">Future</span><span class="o" style="font-weight: bold;"><</span><span class="n">Boolean</span><span class="o" style="font-weight: bold;">></span> <span class="n">applicationAccessible</span> <span class="o" style="font-weight: bold;">= </span><span class="n">application</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">waitForAccessibleAsync</span><span class="o" style="font-weight: bold;">(</span><span class="n">WAIT_TIMEOUT</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC120" style="padding: 0 0 0 10px;"><span class="k" style="font-weight: bold;">if</span> <span class="o" style="font-weight: bold;">(!</span><span class="n">applicationAccessible</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">get</span><span class="o" style="font-weight: bold;">())</span> <span class="o" style="font-weight: bold;">{</span></p><p class="line" id="LC120" style="padding: 0 0 0 10px;"><span class="o">   </span><span class="o">...</span><span class="o" style="font-weight: bold;"><br/></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Once they're both ready, we can <a class="jive-link-external-small" href="https://github.com/adietish/enable-openshift-ci/blob/master/src/main/java/com/openshift/client/example/enableci/OpenShiftCI.java#L126">add the jenkins-cartridge</a> to our project application. It'll tell OpenShift to build my application in the jenkins that is available in the very same domain. Since we eventually reused an existing application, we also check if the application we found already has a jenkins cartridge and only add a fresh one if there's none yet.</p><p>The embedded cartridge we get back offers a creation log, that shows at what url the jenkins jobs may be reached at.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" id="LC128" style="padding: 0 0 0 10px;"><span class="n">IEmbeddedCartridge</span> <span class="n">jenkinsClient</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">application</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getEmbeddedCartridge</span><span class="o" style="font-weight: bold;">(</span><span class="n">IEmbeddableCartridge</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">JENKINS_14</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC129" style="padding: 0 0 0 10px;"><span class="k" style="font-weight: bold;">if</span> <span class="o" style="font-weight: bold;">(</span><span class="n">jenkinsClient</span> <span class="o" style="font-weight: bold;">==</span> <span class="kc" style="font-weight: bold;">null</span><span class="o" style="font-weight: bold;">)</span> <span class="o" style="font-weight: bold;">{</span></p><p class="line" id="LC130" style="padding: 0 0 0 10px;"><span class="n">     jenkinsClient</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">application</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">addEmbeddableCartridge</span><span class="o" style="font-weight: bold;">(</span><span class="n">IEmbeddableCartridge</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">JENKINS_14</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC131" style="padding: 0 0 0 10px;"><span class="n">     System</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">out</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">println</span><span class="o" style="font-weight: bold;">(</span><span class="n">jenkinsClient</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: #008080;">getCreationLog</span><span class="o" style="font-weight: bold;">());</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h2>And now let's have a build fiest!</h2><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Enable-openshift-ci now setup all infrastructures that it needed, it can now get over to trigger the build. OpenShift is git based, deploying to OpenShift is git pushing to the git repository of an application. OpenShift builds whenever you push to it. Enable-openshift-ci will therefore operate on the git repo of the local project and push its content to the OpenShift application. This git push to the OpenShift git repo will trigger the build in the jenkins CI on OpenShift.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>It first makes sure the local git repo has no outstanding modifications and tells the git command line tool on your path to add and commit everything:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" id="LC149" style="padding: 0 0 0 10px;"><span class="n">exec</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: #dd1144;">"git add ."</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC150" style="padding: 0 0 0 10px;"><span class="n">exec</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: #dd1144;">"git commit -a -m 'deploying'"</span><span class="o" style="font-weight: bold;">);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>It then adds the uri of the application git repo to the local repo:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span class="n" style="font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">exec</span><span class="o" style="font-weight: bold; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">(</span><span class="s" style="color: #dd1144; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">"git remote add openshift -f "</span><span style="font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;"> </span><span class="o" style="font-weight: bold; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">+</span><span style="font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;"> </span><span class="n" style="font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">application</span><span class="o" style="font-weight: bold; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">.</span><span class="na" style="color: #008080; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">getGitUrl</span><span class="o" style="font-weight: bold; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; background-color: #ffffff;">());</span></p><p class="line" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px;">And then merges the initial content of this git repo into the local project recursively and then pushes the merged result to the OpenShift application:</p><p class="line" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p class="line" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px;"><span class="n">exec</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: #dd1144;">"git merge openshift/master -s recursive -X ours"</span><span class="o" style="font-weight: bold;">);</span></p><p class="line" id="LC153" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px;"><span class="n">exec</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: #dd1144;">"git push openshift HEAD -f --progress"</span><span class="o" style="font-weight: bold;">);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>Conclusion</h1></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Comment by <a href="https://community.jboss.org/docs/DOC-19828">going to Community</a></p>
        <p style="margin: 0;">Create a new document in JBoss Tools at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2128">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>