Gitlab CI/CD runner : mvn command not found
Solution 1
I managed to fix the problem using this workaround:
script:
- $MAVEN_HOME/bin/mvn clean
Solution 2
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/
Solution 3
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.
Solution 4
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
Related videos on Youtube
FuSsA
° Look.. If you had.. One shot.. Or one opportunity.. To seize everything you ever wanted.. In one moment.. Would you capture it.. Or just let it slip !
Updated on September 16, 2022Comments
-
FuSsA over 1 year
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!