首页 > 解决方案 > 使用 ci/cd 命令行在 gitlab 中提取或解压缩文件

问题描述

实际上,我在 gitlab 上有我的 zip 文件,我想使用 gitlab CI/CD 提取这些文件。我在 .gitlab-ci.yml 中尝试过这个:

image: docker

stages:
  - build
  - test

services:
  - docker:dind

build:
  before_script:
  - apk add p7zip

  script:
  - cd \kmfs
  - 7z x -oChassisA ChassisA.zip

输出

$ apk add p7zip
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/3) Installing libgcc (6.4.0-r9)
(2/3) Installing libstdc++ (6.4.0-r9)
(3/3) Installing p7zip (16.02-r3)
Executing busybox-1.28.4-r3.trigger
OK: 11 MiB in 17 packages
$ cd \kmfs
$ 7z x -oChassisA ChassisA.zip

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Xeon(R) CPU @ 2.30GHz (306F0),ASM,AES-NI)

Scanning the drive for archives:
1 file, 3638943 bytes (3554 KiB)

Extracting archive: ChassisA.zip
--
Path = ChassisA.zip
Type = zip
Physical Size = 3638943

Everything is Ok

Folders: 1
Files: 4
Size:       24070952
Compressed: 3638943
Job succeeded

它执行成功,但提取的文件未反映在 gitlab 存储库中,我无法使用在测试阶段编写的节点 js 代码访问这些文件。

因此,如果有人建议我使用命令或从 nodejs 代码中提取 gitlab 本身的 .zip 文件,那就太好了...

标签: continuous-integrationextractunzip

解决方案


您需要使用工件作为工作的一部分来声明提取的 zip 的路径。这将允许后续作业访问这些文件。

artifacts:
when: always
expire_in: 1 week
paths:
  - zip files folder structure after its extracted

推荐阅读