Search code examples
javaspring-bootgitlabgitlab-cigitlab-ci-runner

How to run spring-boot application using GitLab runner?


I have a spring-boot maven application I've been running locally as:

mvn spring-boot:run

I want to be able to run this in GitLab runner so that when I push the code to master, it automatically copies the latest up there and runs the application.

My GitLab runner is configured in shell mode right now, and I have inside of the .gitlab-ci.yml file a deploy task that runs just that:

mvn spring-boot:run

The issue I am running into is after the application starts, I can see that it is running... but it never shows as success or completed. It just hangs there (because the terminal is still running when you execute that command?)

Question is, is there an alternate set of commands I should be running to get my spring-boot application to update and run each time I push to master? What is it i should be putting into my gitlab-ci.yml (or other files). Note that I am not using docker or kubernetes... just shell.

Sample gitlab CI:

run-deploy:
  stage: deploy
  script:
    - mvn $MAVEN_CLI_OPTS spring-boot:run 

Trying nohup with that also fails. - nohup mvn $MAVEN_CLI_OPTS spring-boot:run &


Solution

  • I believe you can use the run stage for this. It would look something like

    run:
      stage: run
      script:
        - mvn $MAVEN_CLI_OPTS spring-boot:run
    

    You can see an example of this here.

    Make sure you also define the stages to include run as the docs state

    If no stages are defined in .gitlab-ci.yml, then the build, test and deploy are allowed to be used as job’s stage by default. (see stages)

    Is the sample file you provided above your entire configuration file or only a snippet of it? If so, I can adjust my answer to fit your needs. Thanks!