0

I'm trying to follow this jenkins tutorial:

https://www.youtube.com/watch?v=FonVQNqLWiE&list=PL6tu16kXT9PqIe2b0BGul-cXbmwGt7Ihw&index=7

but I'm trying to do that within a dockerized jenkins. To do so, instead of creating a windows virtual machine, I just run the official jenkins docker image:

$ docker pull jenkins/jenkins:lts
$ docker run -P jenkins/jenkins:lts

To follow it up to chapter #6, to make sure maven is available I enter into the container with this:

$ docker exec -it -u root amazing_bose bash

(amazing_bose is the random name that docker assigned to the machine) and then, inside it I do:

# apt-get update
# apt-get install maven
# which mvn
/usr/bin/mvn
# mvn --version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_232, vendor: Oracle Corporation
Java home: /usr/local/openjdk-8/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.9.184-linuxkit", arch: "amd64", family: "unix"

Build success

Until chapter #6 everything has worked fine. The repository is https://github.com/executeautomation/cucumberbasic and the compilation result in the docker's jenkins' console ends with:

Downloaded: https://repo.maven.apache.org/maven2/com/google/collections/google-collections/1.0/google-collections-1.0.jar (625 KB at 884.7 KB/sec)
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /var/jenkins_home/workspace/TestJenkinsXavi/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.532 s
[INFO] Finished at: 2019-11-15T12:40:01+00:00
[INFO] Final Memory: 17M/115M
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS

Build failure

Instead, in chapter #7, it proposes to build the verify maven target for this other project: https://github.com/executeautomation/SeleniumWithCucucumber

In here, in the video tutorial it successfully compiles, but when I do it I get this console ending:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.197 s
[INFO] Finished at: 2019-11-18T08:15:03+00:00
[INFO] Final Memory: 17M/160M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project CucumberBasics: Compilation failure: Compilation failure:
[ERROR] /var/jenkins_home/workspace/TestJenkinsXavi/src/main/java/com/ea/Main.java:[73,61] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /var/jenkins_home/workspace/TestJenkinsXavi/src/main/java/com/ea/Main.java:[118,50] method references are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable method references)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Build step 'Invoke top-level Maven targets' marked build as failure Finished: FAILURE

Question

So the question is:

As it is a closed container (jenkins/jenkins:lts) and it's a source code that is not mine (it's from the tutorial's author) I wonder what do I have to do to make it compile the verify target.

Xavi Montero
  • 9,239
  • 7
  • 57
  • 79

2 Answers2

2

The solution is to specify the source and target JDK levels on the Maven invocation:

-Dmaven.compiler.source=8 -Dmaven.compiler.target=8

In Jenkins, click the "Advanced" button for the Maven build and add these options to the line labelled "MAVEN_OPTS".

zb226
  • 9,586
  • 6
  • 49
  • 79
0

Your build fails with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project CucumberBasics: Compilation failure: Compilation failure:
[ERROR] /var/jenkins_home/workspace/TestJenkinsXavi/src/main/java/com/ea/Main.java:[73,61] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)

I assume your code has lambda functions in there. Try to execute your build with the -source 8 flag as specified in the log. That should fix the issue or at least give you the next issue to work on.

ckaserer
  • 4,827
  • 3
  • 18
  • 33
  • It is not a code that I own. It is a repo that is from a third-party and it is downloaded from inside a docker. In the video it compiles without touching any archives, so I think it is more a matter on how to tell jenkins to use that flag or how to know the good docker image to download instead of the `lts` or how to know the particular `maven` version I should checkout if I could control it via the àpt-get`. If it was about doing a "manual compilation" that would be easy. It's all about how to make jenkins to do the automated compilation without touching the source code. – Xavi Montero Nov 18 '19 at 11:11
  • So, simply updating the pom.xml similar to https://stackoverflow.com/questions/54461677/use-source-8-or-higher-to-enable-lambda-expressions is out of the question? – ckaserer Nov 18 '19 at 11:49