在詹金斯码头工人

时间:2019-11-18 08:51:05

标签: maven docker jenkins lambda compilation

我正在尝试遵循这个詹金斯教程:

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

但是我正在尝试在dockerized jenkins中做到这一点。为此,我没有运行Windows虚拟机,而是运行了官方的jenkins docker镜像:

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

要继续进行第6章的操作,请确保maven可用,我以此输入容器:

$ docker exec -it -u root amazing_bose bash

({amazing_bose是docker分配给机器的随机名称),然后在其中执行:

# 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"

建立成功

直到第6章,一切正常。存储库为https://github.com/executeautomation/cucumberbasic,泊坞窗的詹金斯控制台中的编译结果以以下结尾:

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

构建失败

相反,在第7章中,它建议为另一个项目https://github.com/executeautomation/SeleniumWithCucucumber

建立verify Maven目标。

在这里,在视频教程中,它可以成功编译,但是当我这样做时,我得到了这个控制台结尾:

[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

构建步骤“调用顶级Maven目标”将构建标记为失败     完成:失败

问题

所以问题是:

由于它是一个封闭的容器(jenkins / jenkins:lts),并且它不是我的源代码(来自本教程的作者),我想知道如何做才能使其编译verify目标。

2 个答案:

答案 0 :(得分:1)

解决方案是在Maven调用上指定源和目标JDK级别:

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

在Jenkins中,单击Maven构建的“高级”按钮,并将这些选项添加到标有“ MAVEN_OPTS”的行中。

答案 1 :(得分:0)

您的构建失败并

[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)

我假设您的代码中有lambda函数。尝试使用日志中指定的-source 8标志执行构建。那应该可以解决该问题,或者至少可以给您解决下一个问题。