Cannot pass artifacts between jobs in GitLab CI/CD

╄→гoц情女王★ 提交于 2021-01-28 13:53:41

问题


I have a GitLab project and my .gitlab-ci.yml looks like this:

stages:
  - build
  - deploy

image: registry.gitlab.com/myuser/myproj/ubuntuxenial:v1

before_script:
  - cd /home
  - mkdir docker
  - cd docker
  - git clone "https://xxx@github.com/myuser/myproj.git" repo
  - cd repo

render_site:
  stage: build
  artifacts:
    name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME--$CI_JOB_STAGE-$CI_COMMIT_REF_NAME"
    expire_in: 1 week
    paths:
      - home/docker/repo/
  script:
    - Rscript build.R

...

I have provided the essential parts of the file in the context of this issue. As you can see, this automation is intended to do the following:

  1. Clone a repository.
  2. Invoke a build command inside the repository (I am using R). This step will generate some output files in the repository folder.
  3. Make sure to publish artifacts, I want to publish the content of the whole repository repo folder.

Note I have set GitLab to use Docker images. I am using a Unix image I have uploaded in my registry.

Problem

The issue happens in the first job: render_site. Everything goes fine, the commands are executed and all builds fine. However, the last line in the log for that task is:

Uploading artifacts...
WARNING: home/docker/repo/: no matching files      
ERROR: No files to upload

Troubleshooting

I understand the issue is in the path I provide in .gitlab-ci.yml. I have tried the following:

  • home/docker/repo/
  • /home/docker/repo/
  • repo/

Nothing works. This path that we specify, what is it relative to??? The documentation mentions:

You can only use paths that are within the project workspace.

What does it mean? I am creating a container every time I push and I cd into different directories in the commands I specify in .gitlab-ci.yml, so what is the project workspace the documentation mentions?


回答1:


Problem solved. My question clearly came as a lack of understanding of GitLab and how a runner works. What I was missing is the fact that the runner, after creating a container out of the specified Docker image, will actually create, in the container, a folder with the commit.

Useless cloning

Therefore what I have in before_script is completely useless. And thanks to @ensc for pointing that in comments.

Project path

Coming to the question, the project path is exactly the directory created in the container where the repository is cloned at the specified commit.



来源:https://stackoverflow.com/questions/55313542/cannot-pass-artifacts-between-jobs-in-gitlab-ci-cd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!