Build, test and deploy with Jenkins

To build and deploy this website we use Jenkins (available here:

Automatically build after GitHub commits

Install the GitHub plugin in Jenkins.

In your the Jenkins pipeline configuration of your project select the option ‘GitHub hook trigger for GITScm polling’.

You have to add a WebHook to your GitHub project that points to your Jenkins installation.

Jenkins Pipeline Script

In the pipeline we use the following script, the credentials for Docker Hub / Docker Cloud are stored in Jenkins.

def dockerImage

node {
    stage ('Build from GitHub') {
    git branch: 'master', url: '';
    sh 'mvn clean install';
    archiveArtifacts 'server/target/*.war';      
stage('SonarQube analysis') {
    withSonarQubeEnv('SonarQube Local') {
    sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar'

stage('Build Docker image') {
    sh 'docker system prune -a -f';
     dockerImage ='javaee/java-demo', '.');
stage('Push Docker Image to Docker Cloud')
  docker.withRegistry('', 'docker-hub')