0

I got a little project assigned to me with a particular use case and a very short time window. I have to run Jenkins on a Windows 2019 Server VM instance in Google Cloud, clone a spring boot/Maven application from GitHub, build, test, and run the application. This is my first time working with Jenkins and spring boot/Maven so I am kinda stuck in how to progress.

I have a Jenkinsfile in my repo and have succesfully cloned, built, tested, and ran the application, the only problem is during the "run" stage of the build it runs indefinitely until I manually abort the build. Is there a way to finish the pipeline build but leave the application running? Below is my Jenkinsfile.

    pipeline {
  agent any
  stages {
    stage("Clean Up"){
      steps{
        deleteDir()
      }
    }
    stage("Clone Repo"){
      steps {
        bat "git clone https://github.com/CBoton/spring-boot-hello-world.git"
      }
    }
    stage("Build"){
      steps {
        dir("spring-boot-hello-world") {
          bat "mvn clean install"
        }
      }
    }
    stage("Test") {
      steps {
        dir("spring-boot-hello-world") {
          bat "mvn test"
        }
      }
    }
    stage("Run") {
        steps {
          dir("spring-boot-hello-world") {
            bat "mvn spring-boot:run"
        }
      }
    }
  }
}

Thanks in advance for any suggestions.

Cheers

1 Answers1

1

You want to start the process for the Run stage in the background so the Jenkins pipeline can continue/terminate while the background process is still running.

If it were Linux, running a process in the background would be supported by Bash by ending a command with &, eventually supported by a nohup to ensure it is not killed when the pipeline (parent job) gets killed. It is explained in more detail at https://www.maketecheasier.com/run-bash-commands-background-linux/.

It seems to me you are running all this in Windows. Here the start command seems to do the job. See How to run a command in the background on Windows?

To my taste running the service as you do means it has no error correction with it. If it fails neither the system nor you would notice, not to talk about automatically bringing up the service after failure or system reboot. Try to run it as a service. That means your pipeline would install it as a service, then start the service. The Service Control Manager would watch and ensure that the command is running and keeps running. Tools like Procrun can help you in this case.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • Thanks for the comment Hiran. I got some clarification today and they actually want a jar file to be produced at the end of the build rather than the application to run after build, now I just have to figure that out. Thanks again. – Curtis Botonis Aug 21 '22 at 02:00