Email ico
Glassfish

Auto deploy war to Glassfish with jenkins

Devendra Nationalwala | 21 Jul 2022

The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

You may run jenkins throgh docker image over docker or kubernetes container.

To manually run jenkins, you can download the jenkins war from this link. Following are the prerequisite for this tutorial if you are not using docker:

Once the war file is downloaded, you may run following command to run the jenkins:

java -jar /path/to/jenkins.war --httpPort=9096

In above command I have set --httpPort argument to run jenkins on port 9096. The command will launch jenkins in a default browser of your pc and you will see following screen on startup.

After the initialization process, you will get the location of the file that has the password of an admin user.

Once you log in, you can choose how you want to install the required plugins. I would suggest you choose "suggested plugins" if you are unsure which plugins are needed to complete your task.

Once plugin installation is complete, you can create an admin user.

At last, you can set host/domain for Jenkins.

After login, you will see the Jenkins dashboard screen. To deploy the war to the GlassFish server, we need to install a plugin named Deploy to container. To install the plugin, click Manage Jenkins in left navigation bar. Then click manage plugins under System Configuration.

On this screen, you will see installed jenkins plugins and updates available for plugins. To install new plugin, click the Available tab. Search for Deploy to container and click Install without restart.

We have installed required plugins. Redirect to dashboard to create first task. Click New Item in left navigation bar.

Enter task/job/project name. Select Freestyle Project. Click Ok.

Steps to configure job:

As our job is ready now, you can run it with multiple ways like:

I will show that how we can invoke it from bitbucket pipeline.

bitbucket-pipelines.yml

With above pipeline, when you push a commit to master branch, it will invoke the Jenkins Job URL.

Additional Configuration

Above configuration could run the job successfully. However, if there's any error in build, you may also need to configure mvn and jdk version in jenkins. To configure them, go to Dashboard > Manage Jenkins > Global Tool Configuration

Related articles

Auto deploy maven project to glassfish with CLI or cron - Read Now