我正在编写一个新的Jenkinsfile来使用我的管道,并且我正在尝试使用Maven进行构建。
我写的Jenkinsfile看起来像这样:
node {
stage('Mvn clean install') {
echo 'Start to : mvn clean install'
def mvnHome = tool name: 'mvn_3.6.1', type: 'maven'
sh "${mvnHome}/bin/mvn -version"
sh "${mvnHome}/bin/mvn clean install -P sonar"
}
}
字符串
生成期间发生的错误包括:
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ jmsight-management ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 119 source files to /var/lib/jenkins/workspace/jmsight-management-pipeline/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.009 s
[INFO] Finished at: 2019-09-04T17:32:13+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project jmsight-management: Fatal error compiling: invalid target release: 11 -> [Help 1]
型
关键是在服务器和Jenkins上运行mvn -version
的结果是不同的。
查看我的Jenkins控制台输出。
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Mvn clean install)
[Pipeline] echo
Start to : mvn clean install
[Pipeline] tool
[Pipeline] sh
+ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn_3.6.1/bin/mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T04:00:29+09:00)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn_3.6.1
Java version: 1.8.0_222, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre
Default locale: ko_KR, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"
型
当我直接在服务器上运行mvn -version
时。
[jmuser@cicd-vm-dev01 usr]$ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn_3.6.1/bin/mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T04:00:29+09:00)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn_3.6.1
Java version: 11.0.4, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-11.0.4.11-0.el7_6.x86_64
Default locale: ko_KR, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"
型
Java版本显示不同。我做错了什么?
2条答案
按热度按时间hyrbngr71#
要为Jenkins作业配置Java home,您需要以下内容
1.在Jenkins Global Tools中配置JDK。在JDK部分的
Manage -Jenkins -> Global Tool Configuration
中添加一个JDK。的数据
注意JAVA_HOME应该是有效的JDK,而不是JRE。
1.您可以使用以下代码片段设置JAVA_HOME。
字符串
这应该将
/jdks/jdk1.8.0_181
用作JAVA_HOME
33qvvth12#
为了进一步扩展@seenukarthi的答案,下面展示了如何在脚本管道中使用它:
字符串