.gitlab-ci.yml - 控制使用哪个java版本

时间:2016-04-05 08:20:08

标签: gitlab-ci gitlab-ci-runner

我的项目有以下.gitlab-ci.yml文件

image: maven:3-jdk-7

build:
  script: "mvn install -B"

从以下输出开始

gitlab-ci-multi-runner 1.0.4 (014aa8c)
WARNING: image is not supported by selected executor and shell
Using Shell executor...
Running on pauloconnell-HP-ZBook-15...
Fetching changes...
....
HEAD is now at 95ddd4f maven settings
....
   c8a639e..d881b78  master     -> origin/master
Checking out 95ddd4fc as master...
HEAD is now at 95ddd4f... maven settings
$ mvn install -B

但随后出现错误,其中java 8用于构建

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.260s
[INFO] Finished at: Mon Apr 04 18:55:47 IST 2016
[INFO] Final Memory: 77M/967M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:apt-maven-plugin:1.0-alpha-5:process (default) on project om-interface-eircom: Unable to locate the apt compiler in:
[ERROR] /usr/lib/jvm/java-8-oracle/jre/../lib/tools.jar
[ERROR] Please ensure you are using JDK 1.5 or above and
[ERROR] not a JRE (the com.sun.tools.apt.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.

我在本地安装了java 8,但我希望docker图像定义可以控制它。

有人可以建议我如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

我建议使用docker runner而不是shell,然后用具有java 8的图像替换“image:maven:3-jdk-7”?例如:

image: openjdk

当您使用maven并且不安装它时,可能需要其图像:

image: maven

答案 1 :(得分:0)

今天做了一些挖掘,第一个警告是关键

WARNING: image is not supported by selected executor and shell

表示我试图通过'shell'跑步者执行'docker''image'。我编辑了文件

/etc/gitlab-runner/config.toml

来自

/etc/gitlab-runner/config.toml
concurrent = 1

[[runners]]
name = "runner"
url = "http://10.139.11.103:8987/ci"
token = "xxxx"
tls-ca-file = ""
executor = "shell"
[runners.ssh]
[runners.docker]
  image = ""
  privileged = false
[runners.parallels]
  base_name = ""
[runners.virtualbox]
  base_name = ""

删除所有泊坞窗和其他跑步者设置,并添加了“环境”标签

concurrent = 1

[[runners]]
  name = "runner"
  url = "http://10.139.11.103:8987/ci"
  token = "xxxx"
  tls-ca-file = ""
  executor = "shell"
  shell="bash"
  environment= ["JAVA_HOME=/usr/lib/jvm/java-7-oracle/"]

最后一项任务是将'.gitlab-ci.yml'文件更新为

maven-package:
  script: "mvn install -B"

调用'maven-package'模块。