我在gitlab配置中创建了以下工件
Building Artifacts:
stage: Building Artifacts
cache:
key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
paths:
- node_modules/
script:
- npm run build
artifacts:
name: "staging_api"
paths:
- dist/
only:
- master
问题是:工件总是以staging_api.zip文件名创建,并且其中总是有一个名为dist的目录,然后该目录下的文件。相反,我需要所有的文件直接在staging_api.zip中,而不是有子目录(dist)。如何做到这一点?
工件总是在工作区中出现时捆绑在zip中。没有办法改变这个行为。
因此,使工件出现在工件zip中的不同结构中(如在根目录中)的唯一方法是在工作空间中安排工件的文件,并更改artifacts:paths:
规则以匹配这些文件。
在您的情况下,如果您将dist/*
文件移动到工作区根目录,如果您不知道构建生成的文件/目录的名称,这可能会带来挑战。克服这一挑战的一种可能方法是使用artifacts:untracked:
,它会自动将所有未跟踪的文件添加到工件中。这可以选择性地与artifacts:exclude:
结合使用,以忽略某些未跟踪的文件(例如node_modules
,build
等)。
因此你可以这样做:
script:
# ...
- mv dist/* ./ # move files from dist to workspace root
artitacts:
untracked: true # artifact all untracked files
exclude: # exclude files that should not be uploaded
- build/**/*
- node_modules/**/*
- ".cache/**/*"
# add any other files you want to exclude that are untracked
# repository files (tracked files) are already excluded