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
Related
I'm trying to Dockerize a Gauge test automation project so I can run specs inside a Docker container. The project is written in Java and Spring Boot.
I saw this tutorial in Gauge documentation.
This is the DockerFile in the tutorial:
FROM ubuntu
# Install Java.
RUN apt-get update && apt-get install -q -y \
openjdk-8-jdk \
apt-transport-https \
gnupg2 \
ca-certificates
# Install gauge
RUN apt-key adv --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 023EDB0B && \
echo deb https://dl.bintray.com/gauge/gauge-deb stable main | tee -a /etc/apt/sources.list
RUN apt-get update && apt-get install gauge
# Install gauge plugins
RUN gauge install java && \
gauge install screenshot
ENV PATH=$HOME/.gauge:$PATH
As you see, there's no "ADD"/"COPY" there in the DokcerFile.
Is it just suggesting an alternative to install Gauge and the other packages on the host?
Any ideas on how to run the specs inside a Docker container?
Here is what I did to get the test running in the docker container.
I have a specs folder beside src in my project structure meaning the gauge tests will run using the JAR file but they're not part of the JAR file themselves.
--MyProject
----specs
----src
...
I used maven to run the test inside the container. That's why I preferred to build the project inside the container so I get the JAR file ready with the same version of maven I run the test with.
Here is the DockerFile. I developed a bash script to run the test. You may run the script with CMD or ENTRYPOINT:
FROM maven:3.6.1-jdk-8
# add any project resources needed
ADD env /home/e2e/env
ADD specs /home/e2e/specs
ADD src /home/e2e/src
ADD src/main/scripts/entrypoint.sh /home/e2e/
ADD pom.xml /home/e2e/
RUN ["chmod", "+x", "./home/e2e/entrypoint.sh"]
# Install Gauge, web browser and webdriver in your preferred way...
ENV PATH=$HOME/.gauge:$PATH
# I'm keeping the cntainer running. But it's all up to you.
CMD /home/e2e/entrypoint.sh && tail -f /dev/null
And then here is the simple entrypoint.sh script:
#!/bin/bash
cd /home/e2e/
mvn clean package
gauge --version
google-chrome --version
mvn -version
mvn gauge:execute -DspecsDir=specs/myTest.spec
Of course, you could just use a ready JAR instead of building it inside the container. Or you could build the JAR while creating the docker image.
I'm looking for an example .travis.yml file that would execute a Gradle build inside a Docker container that would run my Selenium tests. So far I've seen various blog posts and answers, but they are either in a language that I'm not looking for like JavaScript, or they use Maven instead of Gradle.
I finally got a working example after piecing it together from various blogs:
.travis.yml
sudo: required
dist: trusty
language: java
jdk:
- oraclejdk8
script:
- gradle clean test
before_install:
- docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm -e VNC_NO_PASSWORD=1 selenium/standalone-chrome-debug:latest
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
Since a few days travis does not support the jdk option oraclejdk10 anymore. So I tried to move to openjdk10. The problem is, that I need JavaFX support, and I get various error messages for various tries to get it working:
Try 1:
language: java
install: true
script: "cd Aggregation; mvn test -B"
sudo: false
jdk:
- openjdk10
notifications:
email:
recipients:
- junktogo#web.de
on_success: change
on_failure: always
Travis error:
Multiple packages like javafx.application do not exist
Try 2 (Install the openjfx package):
I added the following section:
before_install:
- sudo apt install -y openjfx
Travis error:
E: Unable to locate package openjfx
The command "sudo apt install -y openjfx" failed and exited with 100 during.
This problem remains even if adding sudo apt update.
Try 3:
before_install:
- sudo apt-get build-dep libopenjfx-java
- sudo apt-get --compile source libopenjfx-java
Travis error:
E: Unable to locate package libopenjfx-java
The command "sudo apt-get build-dep libopenjfx-java" failed and exited with 100 during.
As Jan S. suggested including JavaFX using a Maven dependency instead of trying to build it using Travis works just fine.
Add something like the following to your Maven dependencies section:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
Teavis build with OpenJDK 8
language: java
dist: bionic
jdk:
- openjdk8
before_install:
- sudo apt-get update -q
- sudo apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2
- chmod +x deploy.sh
after_success:
- ./deploy.sh
You need a proper setup of OpenJFX to bring it to work since JavaFX is not included in OpenJDK and also you should upgrade to OpenJDK 11 since Java 10 is EOL (End of Life).
Checkout the official documentation:
https://openjfx.io/
OpenJDK 11:
https://jdk.java.net/11/
I am trying to install dataloader on my Linux machine.
https://github.com/forcedotcom/dataloader
There is a command line on third line:
$ mvn clean package -DskipTests
When I typed that in, I got this error:
The program 'mvn' can be found in the following packages:
* maven
* maven2
Try: sudo apt-get install <selected package>
I am not sure what to do.
Dataloader needs Maven. It's a dependency manager for Java.
Thus you have to install Maven before being able to use it.
Just run sudo apt-get update && sudo apt-get install maven2 and mvn will be available on your computer.
Maven documentation (for more up to date installation instructions) : https://maven.apache.org/install.html
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"]