Build, test, and publish a Docker Image for a Java HTTP server application
In this tutorial, you will create a Harness CI pipeline for a Java HTTP server application that does the following:
- Build and test the application.
- Publish a Docker image.
- Pull the published Docker image, then pull and run it as a Background step.
- Run a connectivity test against the running application.
If you don't have a Harness account yet, you can create one for free at app.harness.io
Create your pipeline
- Fork the repository https://github.com/keen-software/jhttp into your GitHub account.
- Follow the Get Started wizard in Harness CI.
- New account
- Existing account
Sign up for a new Harness account. Select the Continuous Integration module after your initial sign in. This brings you to the Get Started wizard.
Log in to your Harness account. You can either create a new project or select an existing project, and then select the Continuous Integration module. In the Project pane, expand the Project Setup menu, and then select Get Started.
- When you are prompted to select a repository, search for jhttp, select the repository that you forked in the earlier step, and then select Configure Pipeline.
- Select Starter Pipeline, and then select Create Pipeline.
Docker Hub connector
You need a Docker Hub connector. This connector is used to authenticate and publish the Java HTTP server image to your Docker Hub account.
If you have not created a Docker Hub connector yet, follow these steps.
- From the left pane, expand the Project Setup, and then select Connectors.
- Select + New Connector, and then select Docker Registry.
- In the Name field, enter Docker Hub, and then select Continue.
- In the Docker Registry URL field, enter https://index.docker.io/v2/.
- For Provider Type, select DockerHub.
- In the Username field, enter your Docker Hub username.
- In the Password field, select Create or Select a Secret. Follow the prompts to add your Docker Hub access token, and then click Continue.
- At the next screen, select Connect through Harness Platform, and then select Save and Continue.
- After Harness performs a validation test, select Finish.
- In your list of connectors, note the ID of the connector that you just created. If you named the connector
Docker Hub, the ID should be
Your connector needs an access token with Read, Write, Delete permissions.
Modify the pipeline
From the left pane, select Pipelines, and then select your jhttp pipeline from the list.
Switch from the Visual view to the YAML view, and then select Edit YAML.
A starter pipeline is created with a single stage. It should look similar to this:
name: Build jhttp
name: Echo Welcome Message
command: echo "Welcome to Harness CI"
Replace the sample
stages section with the following
- name: DOCKERHUB_USERNAME
description: Your Docker Hub username
name: Run Tests
postCommand: mvn package -DskipTests
name: Build and Push an image to Docker Registry
name: Run Connectivity Test
name: Run Java HTTP Server
name: Test Connection to Java HTTP Server
until curl --max-time 1 http://localhost:8888; do
This configuration requires the Docker Hub connector ID to be
Docker_Hub. If your connector ID is different, replace
Docker_Hub with the correct ID.
Select Save in the YAML editor.
Run your pipeline
In the Pipeline Studio, select Run.
Enter your Docker Hub username in the
In the Build Type field, select Git Branch, and then enter main in the Branch Name field.
Select Run Pipeline.
Observe each step of the pipeline execution. When the first stage completes, test results appear on the Tests tab.
When the second stage completes, you should see the successful
curlcommand in the Test Connection to Java HTTP Server step.
For a comprehensive guide on application testing, Harness provides O'Reilly's Full Stack Testing book for free at https://harness.io/resources/oreilly-full-stack-testing.