Deploy to Wildfly using Jenkins Pipeline in Windows

First, create a Jenkins pipeline lets call it first . Now open the pipeline and go to configure . Scroll down to the Pipeline section where we can write our script. Let's select Pipeline script a pipeline definition. Now we will write our pipeline script in the script snippet.

In this example, we’ll be working on a maven project. So to build a maven project, we’ll use Maven tool and for that, we need to configure Jenkins first.

So click onManage Jenkis from dashboard. Go toGlobal Tool Configuration under the system configuration tab. Here we will add JDK and Maven installations.

If you want to install the JDK from the website, you’ll need to check the Install automatically field. You also need to provide login credentials as you cant download any JDK from their website without an account. To add the credentials click on the highlighted text Please enter your username/password and enter your oracle username and password.

Similarly, we’ll be installing maven. Here we can select the preferred maven version. Here I’ve used the same name as the maven version so that I can use it later with less confusion.

We are done with tool configuration now let's go back to our pipeline script.
Here I will be cloning a private git repo. So I need to save the credentials beforehand. To do that, find Credentials from Manage Jenkins menu.

Click on Add credentials and add your repo username and pass. I’ll be saving the credentials with id name bitbucket which will be used in the pipeline script later.

Now in the script, lets use the credentials to clone the project. We can use the same or multiple stages for each task such as pull, build and deploy.

pipeline {
agent any
stages {
stage('Pull') {
steps {
git credentialsId: 'bitbucket', url: 'https://name@bitbucket.org/project'
}
}
}
}

Lets add another stage Build to build the project with mvn clean package .

stage('Build') {
steps {
bat 'mvn clean package'
}
}

Now let's save the pipeline and build it from Jenkins dashboard to see if it works.

So far we have successfully pulled and deployed our project. Now it's time to deploy.

For that, we’ll be using a plugin https://github.com/jenkinsci/wildfly-deployer-plugin. Let's clone the project in your local machine. Then build the project with the following command mvn clean package . If the build is successful, we see atarget folder.

In the target directory, we need to rename wildfly-deployer.hpi to wildfly-deployer.jpi . Let's copy the wildfly-deployer.jpi to C:\Users\<username>\AppData\Local\Jenkins\.jenkins\plugins .
Again come back to thetarget directory of that project and from there traverse to wildfly-deployer\WEB-INF\lib . There we’ll see some jars like this-

From there, we need to copywildfly-cli-8.2.1.Final.jar to C:\Users\<username>\AppData\Local\Jenkins\war\WEB-INF\lib . Now let's restart Jenkins withlocalhost:8080/safeRestart .

We are all set to use this plugin. So now let's deploy.
To use this plugin, let's create a new Freestyle Poject and name it deploy .

Now in configure page of deploy job, scroll down to Build section and click on Add build step and select Deploy WAR/EAR to Wildfly .

Be careful with the WAR/EAR files location path. If wildfly is running on a different server, only insert the ip address without http or https protocol. And if it is running inDomain mode , you need to add the server group as well.

All done here, let's go back to our pipeline script.
We will now call this deploy job from our pipeline. Let's add a stage for that.

stage('Deploy') {
steps {
build 'deploy-cms'
}
}

So, our final pipeline script should look something like this.

pipeline {
agent any
stages {
stage('Pull') {
steps {
git credentialsId: 'bitbucket', url: 'https://name@bitbucket.org/project'
}
}
stage('Build') {
steps {
bat 'mvn clean package'
}
}
stage('Deploy') {
steps {
build 'deploy'
}
}
}
}

let's save the pipeline and build it.

Done. You’ve successfully deployed in wildfly through a pipeline.

Software Engineer(QA) @TigerIT Bangladesh Ltd

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store