Maven not found while using Gitlab-ci-multi-runner - java

I've been trying to set up GitLab-CI to build Maven Java projects in Raspbian, but whenever It tries to run the build script it fails because it can't find Maven. I used this guide to install the runner.
Build trace:
Running with gitlab-ci-multi-runner 1.10.4 (b32125f)
WARNING: image is not supported by selected executor and shell
Using Shell executor...
Running on raspberrypi...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/f09314a8/0/RBian/TestProject'...
Checking out 54d2e140 as master...
Skipping Git submodules setup
$ mvn clean package
bash: line 22: mvn: command not found
ERROR: Build failed: exit status 1
.gitlab-ci.yml
image: maven:3-jdk-8
build:
script: "mvn clean package"
artifacts:
name: "TestProject"
paths:
- "target/*.jar"
Does anyone know what causes this?
EDIT: Modifying /etc/default to add $MAVEN_HOME/bin to $PATH did the trick.

Try adding MAVEN_HOME path into config.toml environment field.
environment = ["MAVEN_HOME=/path/to/maven"]

Related

Providing full path to java in gitlab config

In my gitlab-ci.yml configuration I have the following snippet:
before_script:
- java -jar /home/gitlab-runner/tools/ciVersioner-1.0.jar $MAJOR $MINOR $CI_COMMIT_SHORT_SHA
script:
- mvn --projects employees --also-make clean package -DskipTests
after_script:
- echo $HOSTNAME $WHOAMI
artifacts:
paths:
- employees/target/*.jar
expire_in: 30 days
It does not work but for a different reason (since java versions are incompatible).
Here's the output:
The solution was to install a newer java 11.
I did so and changed the configuration correspondingly:
before_script:
- /opt/java11/jdk-11/bin/java -jar /home/gitlab-runner/tools/ciVersioner-1.0.jar $MAJOR $MINOR $CI_COMMIT_SHORT_SHA
script:
- mvn --projects employees --also-make clean package -DskipTests
after_script:
- echo $HOSTNAME $WHOAMI
artifacts:
paths:
- employees/target/*.jar
expire_in: 30 days
However, with this configuration nothing works at all:
But if I execute this command in VM environment directly, it works as expected.
Is there a limitation on using full qualified path in the yml file or maybe it has to do with something else?
Before you updated java the job fail at the java command, so it didn't try to execute mvn.
However, when the first problem is solved, you get a new issue and now with mvn command.
I guess the runner cannot recognize mvn because maven is not installed.
You could try adding the following to the before_script section:
- apt-get update && apt-get install maven
This is will depend on the linux distribution, use yum instead if the runner is on redhat or centos

Jenkins mvn: command not found Build step 'Execute shell' marked build as failure

I set up Jenkins with two Execute shell builds Java -version and mvn -version. Console output shows the below error.
My Global tool config is:
Terminal output for Java -version and mvn version, Java_Home and Maven_Home is:
This is my .bash_profile:
So Java and Maven is installed correctly. Java home and Maven home commands returns null but Jenkins build passed for Java -version, fails only for mvn -version. What am I doing wrong here?

How to run maven command in AWS Device Farm

I am trying to run my java mobile project in device farm using maven.
When I run this command on my local machine in the right directory it works:
mvn test -D "cucumber.options="src/test/java/cucumber/features" --glue
cucumber.steps --tags #InstallApp"
I put this command on the yaml file in the aws device farm but it doesn't work.
This is the error I get:
[DeviceFarm] echo "Start Appium TestNG test"
Start Appium TestNG test
[DeviceFarm] mvn test -D
"cucumber.options="src/test/java/cucumber/features" --glue
cucumber.steps
--tags #InstallApp"
[INFO] Scanning for projects...
[INFO] BUILD FAILURE
[ERROR] The goal you specified requires a project to execute but there
is
no POM in this directory (/tmp/scratchncneoU.scratch/test-
packageO6o8s7).
Please verify you invoked Maven from the correct directory. -> [Help 1]
How can I run this maven command in device farm? Where is the pom located there?
Thanks
After typing this command in the yaml file:
[DeviceFarm] java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -D"cucumber.options="classpath:features" --glue cucumber.steps --tags #InstallApp" org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10
I get an error of: Couldn't find the testng.xml in the jar file although I have this in my pom:
<directory>${project.basedir}/src/test/java/cucumber</directory>
</testResource>
</testResources>
What can it be?
The mvn command fails because your deployment package doesn't contain the whole project. From the sound of things with the current deployment package you should be able to do what you want with this command:
- java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH -D"cucumber.options="src/test/java/cucumber/features" --glue cucumber.steps
--tags #InstallApp" org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10
Otherwise, if you want to use maven you'll need to zip up the whole project and include it's pom.xml. So for example using the sample cucumber java tests
git clone https://github.com/aws-samples/aws-device-farm-appium-cucumber-tests-for-sample-app.git
zip -r deployment_package.zip aws-device-farm-appium-cucumber-tests-for-sample-app
Then you should be able to use maven in the testspec.yml file. For example, I could run the following command for the sample: mvn clean test after going to the project dir and then to get the results I had to export the target directory.
test:
commands:
# Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH/aws-device-farm-appium-cucumber-tests-for-sample-app
- mvn clean test
...
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_TEST_PACKAGE_PATH/aws-device-farm-appium-cucumber-tests-for-sample-app/target
- $DEVICEFARM_LOG_DIR
However, you'll need to upload the zip file as an APPIUM_NODE test type to avoid the test package parser there.
HTH
-James

Gradlew init - no such file or directory

I'm trying to build my Java app using Docker file. There is a step that does next:
RUN ./gradlew init
There is such file gradlew.bat for my Windows machine. And if I execute it from PowerShell all goes well.
FROM openjdk:8-jdk-alpine as builder
WORKDIR home
#get gradle wrapper
ADD gradle /home/gradle
COPY gradlew ./
COPY gradlew.bat ./
RUN ./gradlew init <--- gives error
Running command from Docker file give me next error. What I do wrong?
Well it's not a problem in your dockerfile. I created dummy scripts to mimic your build steps, they go through fine:
$ docker build .
.
.
Step 6 : RUN ./gradlew init
---> Running in 0228bf5340d9
This is dummy output: init
---> 7835d2972bf9
Removing intermediate container 0228bf5340d9
Successfully built 7835d2972bf9
Apparently a problem with gradlew instead, also reported here
Hope this helps.
The first thing you should check is the line breaking of your gradlew file. Changing it to LF will solve your issue.

Travis Ci build failed for a java maven project

I'm using Travic CI as a tool for coutinuous integration on a java maven project and my .travis.yml file is configured this way :
language: java
sudo: false
script: mvn clean verify
But when I execute, I get this error :
The travis ci build could not complete due to an error
The command "eval mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V" failed.
Anyone have an idea on how to fix this problem ?
Thanks
It seems you are using maven-compiler-plugin 1.8 in you pom.xml. The supported version of travis-ci server is 7, so change it to 1.7
link

Categories

Resources