1

I'm trying to figure out how to use gitlab CI/CD with my maven java project and the yml-file. So first I tried to find the command, for example in javascript you have npm run test and it'll run the tests. But I can't seem to find the equivalent.

My yml-file:

stages: ["build", "test"]
build:
    stage: build
    script:
        - echo "Building..."
        - mkdir build
        - new-item build/info.txt
    artifacts:
        paths:
        - build/

test:
    stage: test
    script:
        - echo "Testing..."
        - Test-Path "build/info.txt" -PathType leaf

mkdir build basically makes a directory and builds it, right? It's hard to find the commands that automatically build the project and tests the project...anybody got any suggestions?

I am not sure what terminal I'm using in Intellij since 'mvn' was not recognized as an internal or external command, so I'm pretty sure I'm using powershell.

If I click on the side-maven button and run the verify it does work, but why doesn't mvn verify work in the terminal?

zhrgci
  • 584
  • 1
  • 6
  • 25

1 Answers1

0

Here is a simple maven build from

Gitlab docs


image: maven:latest

stages: 
  - build
  - test
  - run

variables: 
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" 

cache: 
  paths: 
    - .m2/repository/ 
    - target/ 

build: 
  stage: build
  script: 
    - mvn $MAVEN_CLI_OPTS compile 

test: 
  stage: test 
  script: 
    - mvn $MAVEN_CLI_OPTS test 

run: 
  stage: run
  script: 
    - mvn $MAVEN_CLI_OPTS package 
    - mvn $MAVEN_CLI_OPTS exec:java -Dexec.mainClass="com.example.app.App"

iTech
  • 18,192
  • 4
  • 57
  • 80
  • Ok so I had to basically do the JAVA_HOME and M2 stuff with maven, but I had to restart the runner so it would pick up on the new maven stuff I put in. I restarted the runner but now I get a different problem...do you have a clue? https://www.reddit.com/r/gitlab/comments/gnh0go/gitlabrunner_access_denied_or_specified_file_not/ – zhrgci May 21 '20 at 07:57