问题描述
我有一个GitLab项目,我的 .gitlab-ci.yml
看起来像这样:
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://[email protected]/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:
- 克隆存储库.
- 在存储库中调用构建命令(我正在使用R).此步骤将在存储库文件夹中生成一些输出文件.
- 确保发布工件,我想发布整个存储库
repo
文件夹的内容.
- Clone a repository.
- Invoke a build command inside the repository (I am using R). This step will generate some output files in the repository folder.
- Make sure to publish artifacts, I want to publish the content of the whole repository
repo
folder.
注意,我已将GitLab设置为使用Docker映像.我正在使用我在注册表中上传的Unix映像.
Note I have set GitLab to use Docker images. I am using a Unix image I have uploaded in my registry.
问题发生在第一个作业中: render_site
.一切顺利,命令已执行且所有构建均正常.但是,该任务的日志的最后一行是:
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
问题排查
我了解问题出在我在 .gitlab-ci.yml
中提供的路径中.我尝试了以下方法:
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:
是什么意思?我每次按 .gitlab-ci.yml
中指定的命令将 cd
推入不同目录时,都会创建一个容器,所以 project是什么工作区文档中提到的内容?
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?
推荐答案
问题已解决.我的问题显然是由于对GitLab以及跑步者的工作方式缺乏了解.我所缺少的是,运行程序从指定的Docker映像创建容器之后,实际上将在容器中创建包含提交的文件夹.
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.
因此,我在 before_script
中拥有的东西完全没有用.感谢@ensc在注释中指出这一点.
Therefore what I have in before_script
is completely useless. And thanks to @ensc for pointing that in comments.
问题来了,项目路径正是在容器中创建的目录,在该容器中存储库在指定的提交处被克隆.
Coming to the question, the project path is exactly the directory created in the container where the repository is cloned at the specified commit.
这篇关于无法在GitLab CI/CD中的作业之间传递工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!