[JAVA] Automatically deploy to WildFly with Jenkins when SVN commits

I want to automate build and deploy tasks when committing SVN

It's not a new story, but I couldn't find an article that realized the content of the subject, so I'll make a note of how to do it. It is assumed that Java, Maven, Jenkins, Subversion, and WildFly are properly installed in the execution environment.

environment

I am trying in the following environment. CentOS 7.3 Java 1.8 WildFly 10.0.0.Final Maven 3.3.9 (Maven 3.1.1 or higher is required to use WildFly Maven Plugin 1.1.0.Final) WildFly Maven Plugin 1.1.0.Final Jenkins 2.46.3 Subversion 1.7.14

Introducing WildFly Maven Plugin

Introduce "WildFly Maven Plugin" to deploy from maven to WildFly. The following is a description example of pom.

pom.xml


<build>
  <plugins>
    <plugin>
      <groupId>org.wildfly.plugins</groupId>
      <artifactId>wildfly-maven-plugin</artifactId>
      <version>1.1.0.Final</version>
      <configuration>
        <hostname>Hostname of the server running WildFly</hostname>
        <port>WildFly management console port number</port>
        <username>Username to log in to the management console</username>
        <password>Password to log in to the management console</password>
      </configuration>
    </plugin>
  </plugins>
</build>

The default hostname is "localhost", so if you're running Jenkins and WildfFly on the same server, you probably don't need to specify it. Also, the default port is "9990", so if you haven't changed it, you don't need to specify it. Details of Config can be found here [https://docs.jboss.org/wildfly/plugins/maven/latest/deploy-mojo.html)

Create a job in Jenkins

Create a job to run on SVN commit. What the job does is check out the source from SVN, build and deploy with maven. The following is an example of job settings.

Source code control

WS000004.JPG

Build trigger

Set the authentication token required to call a job from SVN. You can check the token from [Jenkins]> [Username]> [Settings]> [API Token]. WS000006.JPG

Build

First, build with "clean install" and deploy with "wildfly: deploy". WS000007.JPG

Create SVN hook script

At SVN commit, create a "post-commit" script to perform the above job. If the created script does not have execute permission, post-commit hook failed (exit code 255) with no output. Please note that an error like this will appear.

$ cd [Repository root directory]/hooks/
$ vi post-commit

#!/bin/sh
api_token=TOKEN_NAME

curl https://[URL confirmed by build trigger]?token=$api_token

$ chmod 774 post-commit

Done

Now when you commit to SVN, Jenkins will automatically build and deploy to WildFly.

Recommended Posts

Automatically deploy to WildFly with Jenkins when SVN commits
A story about PKIX path building failed when trying to deploy to tomcat with Jenkins
Deploy your application to WildFly
How to automatically generate ER diagram when migrating with Rails6
Automatically deploy Web applications developed in Java using Jenkins [Tomcat application]
Changed comments automatically generated by Xcode and AppCode
Automatically deploy to WildFly with Jenkins when SVN commits
How to check CircleCI code and automatically deploy to Heroku
Deploy to EC2 with CircleCi + Capistrano
When I try to sign up with devise, it automatically redirects to root_path
Deploy to heroku with Docker (Rails 6, MySQL)
Deploy Java web app to Azure with maven
Deploy Rails to ECS Fargate with AWS Copilot
How to log in automatically when Ubuntu restarts