Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI/CD runner : mvn command not found

Maven is well installed on my gitlab-runner server. When executing mvn clean directly on my repo it works, when running my pipeline using Gitlab UI got this error :

bash: line 60: mvn: command not found

ERROR: Job failed: exit status 1

I notice that I tried to fix the problem by adding the before_script section in the .gitlab-ci.yml file :

before_script:    
- export MAVEN_HOME=/usr/local/apache-maven

I add also the line :

environment = ["MAVEN_HOME=/usr/local/apache-maven"]

on the config.toml file.

the problem still persist, my executor is : shell.

Any advice!

like image 731
FuSsA Avatar asked Sep 27 '18 11:09

FuSsA


4 Answers

I managed to fix the problem using this workaround:

  script:
    - $MAVEN_HOME/bin/mvn clean
like image 86
FuSsA Avatar answered Sep 28 '22 02:09

FuSsA


Just add the maven docker image, add below line as first line:

image: maven:latest or image: maven:3-jdk-10 or image: maven:3-jdk-9

refer: https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/

like image 33
Bikas Katwal Avatar answered Sep 28 '22 02:09

Bikas Katwal


For anyone experiencing similar issues, it might be a good idea to restart the gitlab runner ".\gitlab-runner.exe restart". Especially after fiddling with environmental variables.

like image 40
OMA Avatar answered Sep 28 '22 01:09

OMA


There is an easier way:
Making changes in ~/.bash_profile not ~/.bashrc.


According to this document:

.bashrc it is more common to use a non-login shell

This document saying:

For certain executors, the runner passes the --login flag as shown above, which also loads the shell profile.

So it should not be ~/.bashrc, you can also try ~/.profile which It can hold the same configurations, which are then also accessible by other shells


In my scenario I do following things:

1. Set gitlab-runner's user password.

passwd gitlab-runner

2. Login gitlab-runner.

su - gitlab-runner

3. Make changes in .bash_profile

like image 45
Kevin Avatar answered Sep 28 '22 02:09

Kevin