CD part XVI: Create release profile and deployment job in jenkins

Johan Tuitel

  • 24/02/2017
  • 17 minuten leestijd
Johan Tuitel

CD part XVI: Create release profile and deployment job in jenkins

For creating release artifacts and store them in Nexus, we need to create a release profile in our project.

creating a release profile in maven

  1. configure the pom.xml of the AccountStatusWebservice
  2. navigate to AccountStatusWebservice and open pom.xml
  3. add release profile to the profiles section
    <profile>
        <id>release</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>http://localhost:8072/manager/text</url>
                        <server>WebServiceTest</server>
                        <path>/accountStatusWebservice</path>
                    </configuration>
                </plugin>
                <!-- Archiver plugin configurations -->
                <!--JAR Archiver configurations. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>                       
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Created-By>${java.vm.name} ${java.version} (${java.vm.vendor})</Created-By>
                                <SCM-Revision>${buildNumber}</SCM-Revision>
                                <SCM-TimeStamp>${timestamp}</SCM-TimeStamp>
                                <Implementation-Vendor-ArtifactId>${project.artifactId}</Implementation-Vendor-ArtifactId>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <!-- WAR Archiver configurations. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>                        
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Created-By>${java.vm.name} ${java.version} (${java.vm.vendor})</Created-By>
                                <SCM-Revision>${buildNumber}</SCM-Revision>
                                <SCM-TimeStamp>${timestamp}</SCM-TimeStamp>
                                <Implementation-Vendor-ArtifactId>${project.artifactId}</Implementation-Vendor-ArtifactId>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <!-- EAR Archiver plugin -->
                <plugin>
                    <artifactId>maven-ear-plugin</artifactId>
                    <groupId>org.apache.maven.plugins</groupId>                       
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Created-By>${java.vm.name} ${java.version} (${java.vm.vendor})</Created-By>
                                <SCM-Revision>${buildNumber}</SCM-Revision>
                                <SCM-TimeStamp>${timestamp}</SCM-TimeStamp>
                                <Implementation-Vendor-ArtifactId>${project.artifactId}</Implementation-Vendor-ArtifactId>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <!-- Plugin required to generate additional information into the artifacts -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>buildnumber-maven-plugin</artifactId>                        
                    <configuration>
                        <!-- Make the timestamps human readable and consistent -->
                        <timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
                        <!-- Speed, retrieve SCM revision only once during build -->
                        <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
                        <!-- SVN Is not required to execute a build -->
                        <revisionOnScmFailure>SCM-NOTAVAILABLE</revisionOnScmFailure>
                    </configuration>
                </plugin>
                <!-- Source plugin configuration -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>                    
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Created-By>${java.vm.name} ${java.version} (${java.vm.vendor})</Created-By>
                                <SCM-Revision>${buildNumber}</SCM-Revision>
                                <SCM-TimeStamp>${timestamp}</SCM-TimeStamp>
                                <Implementation-Vendor-ArtifactId>${project.artifactId}</Implementation-Vendor-ArtifactId>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <!-- Javadoc plugin configuration -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>                        
                    <configuration>
                        <source>1.8</source>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Created-By>${java.vm.name} ${java.version} (${java.vm.vendor})</Created-By>
                                <SCM-Revision>${buildNumber}</SCM-Revision>
                                <SCM-TimeStamp>${timestamp}</SCM-TimeStamp>
                                <Implementation-Vendor-ArtifactId>${project.artifactId}</Implementation-Vendor-ArtifactId>
                            </manifestEntries>
                        </archive>
                        <detectJavaApiLink>false</detectJavaApiLink>
                        <detectLinks>false</detectLinks>
                    </configuration>
                    <executions>
                        <execution>
                            <id>aggregate</id>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                            <phase>site</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.owasp</groupId>
                    <artifactId>dependency-check-maven</artifactId>
                    <version>1.3.5</version>                       
                    <executions>
                        <execution>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
  1. check the profile by executing the command mvn clean install -Prelease

creating a deployment job in jenkins

  1. we start the tomcat instance for jenkins by executing the tomcat jenkins - start.cmd script
  2. open a browser and navigate to: http://localhost:8075/jenkins/
  3. click in the sidemenu on New Job
  4. for this exercise, we are using the account status webservice
  5. call this item: wsaccountstatusdeployto_test
  6. select the first radiobutton create a freestyle project
  7. in the Source Code Management section select the Git radiobutton
  8. enter the url: https://bitbucket.org/johantuitel/easywebservices.git
  9. select the credentials you have made for your bitbucket account
  10. in my case it was j.tuitel@developers.nl/*(bitbucket account)

set git url and credentials

  1. after that we need to set the correct branch in the field Branches to build
  2. enter: develop

  3. add a build step and select Invoke Top-level Maven
  4. maven version: apache-maven-3.3.9
  5. target: clean install -Pdevelop
  6. POM: AccountStatusWebservice\pom.xml

  7. add a build step and select Invoke Top-level Maven
  8. maven version: apache-maven-3.3.9
  9. target: mvn javadoc:jar source:jar deploy -Prelease
  10. POM: AccountStatusWebservice\pom.xml

  11. add a build step and select Invoke Top-level Maven
  12. maven version: apache-maven-3.3.9
  13. target: mvn tomcat7:undeploy -Prelease
  14. POM: AccountStatusWebservice\pom.xml

  15. add a build step and select Invoke Top-level Maven
  16. maven version: apache-maven-3.3.9
  17. target: mvn tomcat7:deploy -Prelease
  18. POM: AccountStatusWebservice\pom.xml

test deployment job in jenkins

  1. navigate to C:\tools\tomcat-scripts
  2. execute the tomcat ws test - start.cmd file
  3. now the server is started we need to execute the deployment job
  4. navigate to http://localhost:8075/jenkins/job/ws_account_status_deploy_to_test/
  5. click on Build
  6. test if the webservice is deployed succefully by entering http://localhost:8072/accountStatusWebservice/accountstatus?wsdl in the browser
  7. this is very nice, YEAH