为什么Gitlab-CI在下一阶段会删除工件? [英] Why does Gitlab-CI remove artifact during next stage?

查看:688
本文介绍了为什么Gitlab-CI在下一阶段会删除工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指定依赖项后, Gitlab-CI 在进入下一阶段时仍会从工作目录中删除工件。我已经尝试了此代码的所有不同变体,我认为这些变体都可以工作,但没有成功。此外,我已经阅读了数小时,但仍未成功。

After having specified dependencies, Gitlab-CI still removes the artifact from the working directory when entering the next stage. I've tried all different variations of this code which I think should work but have been unsuccessful. Additionally, I've been reading up on this for hours with no success yet.

Gitlab 11.6.0

Gitlab 11.6.0

stages:
    - build_app
    - build_container
    - test
    - release
    - deploy

variables:
  IMAGE_TEST_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  IMAGE_RELEASE_NAME: $CI_REGISTRY_IMAGE:latest

build_app:
  stage: build_app
  script:
    - echo "compile the program"
    - zip zipfile.zip helloworld.txt 
    - pwd
    - ls -al
  artifacts:
    paths:
      - /zip

build_container:
  stage: build_container
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
  dependencies:
    - build_app
  script:
    - pwd
    - ls -al
    - docker build --pull -t $IMAGE_TEST_NAME .
    - docker push $IMAGE_TEST_NAME

test:
  stage: test
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
  script: 
    - docker pull $IMAGE_TEST_NAME
    - docker run $IMAGE_TEST_NAME yum install unzip -y && unzip /helloworld.zip && cat /helloworld.txt

release:
  stage: release
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
  script:
    - docker pull $IMAGE_TEST_NAME
    - docker tag $IMAGE_TEST_NAME $IMAGE_RELEASE_NAME
    - docker push $IMAGE_RELEASE_NAME
  only:
    - master

deploy:
  stage: deploy
  script:
    - ./deploy.sh
  only:
    - master
  when: manual

<$ c出现错误$ c> build_container 阶段:

Running with gitlab-runner 11.6.1 (8d829975)
  on gitrunner-shell trtHcQTS
Using Shell executor...
Running on gitrunner.example.com...
Fetching changes...
Removing zipfile.zip #################### <------------- this right here
HEAD is now at 07e787e Update .gitlab-ci.yml
Checking out 07e787ec as newFeature...
Skipping Git submodules setup
$ echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
WARNING! Your password will be stored unencrypted in /home/gitlab-runner/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ pwd
/home/gitlab-runner/builds/trtHcQTS/0/dhealy/docker-helloworld-test
$ ls -al
total 12
drwxrwxr-x 3 gitlab-runner gitlab-runner   80 Jan 22 12:10 .
drwxrwxr-x 4 gitlab-runner gitlab-runner   70 Jan 21 17:48 ..
-rw-rw-r-- 1 gitlab-runner gitlab-runner   57 Jan 22 12:10 dockerfile
drwxrwxr-x 5 gitlab-runner gitlab-runner  138 Jan 22 12:10 .git
-rw-rw-r-- 1 gitlab-runner gitlab-runner 1450 Jan 22 12:10 .gitlab-ci.yml
-rw-rw-r-- 1 gitlab-runner gitlab-runner   11 Jan 22 12:10 helloworld.txt
$ docker build --pull -t $IMAGE_TEST_NAME .
Sending build context to Docker daemon    151kB

Step 1/3 : FROM centos:7
7: Pulling from library/centos
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Image is up to date for centos:7
 ---> 1e1148e4cc2c
Step 2/3 : COPY zip/helloworld.zip /
COPY failed: stat /var/lib/docker/tmp/docker-builder929937870/zip/helloworld.zip: no such file or directory
ERROR: Job failed: exit status 1

我期望 helloworld.zip 将在下一个阶段 build_container 中存在于工作目录中。

I'm expecting that helloworld.zip will existing in the working directory during the next stage, build_container.

推荐答案

删除zip文件是完全正常的,因为在每个作业开始时,源都与当前提交同步。

It's perfectly normal that your zip file is removed because at the start of every jobs the sources are synchronized with the current commit.

您的问题来自zip文件的工件路径,该路径在build_app作业中不正确。您应输入:

Your problem come from the artifact path of your zip file which is incorrect in build_app job. You should write:

artifacts:
  paths:
  - zipfile.zip

这篇关于为什么Gitlab-CI在下一阶段会删除工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆