I am trying to build ci/cd withing gitlab runner docker image
build: script: - mvn install
but I face below error
$ mvn install bash: line 85: mvn: command not found
I am trying to build ci/cd withing gitlab runner docker image
build: script: - mvn install
but I face below error
$ mvn install bash: line 85: mvn: command not found
@ahmedyosry963 welcome to the forum!
In order to use Maven, you’ll need to select a Docker image to build inside of that has Maven included. To do that add an image:
tag to your .gitlab-ci.yml
. For a list of “official” Maven images, you can see the Maven listing on Docker Hub, as it will depend on the version of Java you are building for.
But in the end you’ll add something like this:
image: maven:3.6.3-jdk-11
You can also see a full working .gitlab-ci.yml
example for Java here.
Thanks a lot for you replay, and sorry for delay
i need to tell you that i have installed gitlab docker image and gitlab runner docker image , both of them different containers and runner registered with no problem.
what i need to do ?
-Build jar file
-Copy it to a special path to run it .
so i did the below but unfortunately it’s failed with error.
-------------------------------gitlab ci file-------------------------------
image: maven:latest
variables:
MAVEN_CLI_OPTS: “-s .m2/settings.xml --batch-mode”
MAVEN_OPTS: “-Dmaven.repo.local=.m2/repository”
cache:
paths:
build:
stage: build
script:
-------------------------------Error-------------------------------
Running with gitlab-runner 13.0.1 (21cb397c)
on java-runner s_9CedZv
Preparing the “shell” executor
00:00
Using Shell executor…
Preparing environment
00:00
Running on 0eb6dc3504ba…
Getting source from Git repository
00:01
Fetching changes with git depth set to 50…
Reinitialized existing Git repository in /home/gitlab-runner/builds/s_9CedZv/0/yousry/sample-ci/.git/
From http://X.X.X.X/yousry/sample-ci
It looks like you’ve set up the runner as a “shell” executor and not a docker executor, so the commands are actually running in the shell of the host, not inside of a Docker container.
See our docs on setting up a Docker based runner for more details on how to do that.
I appreciate your support, I tried docker executor and it worked fine thanks a lot, however, the reason for using runner as Shall executor is that I need to build a normal jar file then copy it to a specific path on the host server.
After changing the runner to docker how I will copy the jar file ?
Makes sense!
There’s a few options here:
config.toml
.mvn
command on the shell executor if you want, but you’ll have to install Maven on the host machine.I need to highlight that my runner is on docker image below is my environment details
As I will not only need to copy the jar file I need to take backup and run it, I would prefer using the 2nd option (Maven already installed on host server).
The problem now is :
Please if you recommend using the 1st option let me know with the steps.
@olearycrew Your support is highly appreciated.
@olearycrew can you please help me ?
Hello
I have to same problem
mvn command do not found by Gitlab
despite the image is maven
image: maven:3.6.3-jdk-11
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:
- whereis mvn
- whereis java
- mvn compile
And this is the result
Notice whereis mvn return empty result
Running with gitlab-runner 12.3.0 (a8a019e0)
on Ubuntu AWS eu-central-1 ngKQKuyR
Using Shell executor...
00:00
Running on ip-172-31-4-182...
00:00
Fetching changes with git depth set to 50...
00:00
Reinitialized existing Git repository in /app/gitlab-runner/builds/n/base/applications/web/.git/
From https://git.app/base/applications/web
* [new ref] refs/pipelines/8 -> refs/pipelines/8856
d3c67..8240d test-ci -> origin/test-ci
Checking out 85a24c as test-ci...
Skipping Git submodules setup
Checking cache for default...
00:00
Runtime platform arch=amd64 os=linux pid=12253 revision=a8a019e0 version=12.3.0
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
$ whereis mvn
mvn:
$ whereis java
java: /usr/share/java
$ mvn compile
bash: line 98: mvn: command not found
ERROR: Job failed: exit status 1
Have you an idea about this problem ?
I have the same problem, apparently it is that the maven image is not installed, in the same way I need help.
I solved it by installing maven and java on the same server.