找不到在gitlabRunner中下载的文件

时间:2019-03-10 18:11:40

标签: java gradle gitlab gitlab-ci unzip

我正在为gradle项目设置GitLab CI。下载gradle之后,即使下载成功,unzip命令也会报告未找到zip文件。我添加了一个ls只是为了查看目录的内容,而我的zip文件不存在。下面是我的.gitlab-ci.yml文件

image: docker:latest

stages:
  - build 

before_script:
  - cd /usr/lib
  - curl https://services.gradle.org/distributions/gradle-2.10-bin.zip -o gradle-2.10-bin.zip
  - unzip "gradle-2.10-bin.zip"
  - ln -s "/usr/gradle-2.10/bin/gradle" /usr/bin/gradle
  - rm "gradle-2.10-bin.zip"
  - export GRADLE_HOME=usr/lib/gradle-2.10
  - export PATH=$PATH:$GRADLE_HOME/bin

build_job:
  image: java:8
  stage: build
  script:
    - gradle -v

这是作业的错误输出

  

$解压缩“ gradle-2.10-bin.zip”解压缩:找不到或打开   gradle-2.10-bin.zip,gradle-2.10-bin.zip.zip或   gradle-2.10-bin.zip.ZIP。错误:作业失败:退出代码1

1 个答案:

答案 0 :(得分:1)

这不是该命令的完整错误输出,这是:

$ unzip "gradle-2.10-bin.zip"
Archive:  gradle-2.10-bin.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of gradle-2.10-bin.zip or
        gradle-2.10-bin.zip.zip, and cannot find gradle-2.10-bin.zip.ZIP, period.

如果我们检查该文件为空。如果我们对该网址执行curl -I,则会得到301,因此您需要在该curl命令中添加-L才能遵循重定向:

curl -L https://services.gradle.org/distributions/gradle-2.10-bin.zip