如何使用cicd将文件从项目工件复制到另一个项目



我使用CICD制作工件并将其保存在公用文件夹中我需要将这些工件的一些文件复制到另一个项目什么脚本我不能用或者最好的方法是什么?

假设您想将文件复制到另一个gitlab项目中。一旦工件在一个作业中构建,在一个阶段(即:构建(,它将在下一阶段的所有作业中可用(即:部署(。

build-artifact:
stage: build
script:
- echo "build artifact"
artifacts:
name: "public"
paths:
- "public/"
deploy_artifact:
stage: deploy
script:
- cd public/   # here are your artifact files.
- ls -l
- cd ..
# now implement copy strategy, 
# for example in a git repo :
- git clone https://myusername:mypassord@myrepo.gitlab.com/mygroup/another_project.git
- cd another_project
- cp ../public/source_file ./target_file
- git add target_file
- git commit -m "added generated file"
- git push

如果您的目的地不是git存储库,您可以简单地在脚本中用直接到服务器的scp或任何其他复制策略来替换。

另一种方法是在项目B的ci中获取项目A的最后一个工件。请参阅https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#retrieve-其他项目的作业工件

当您触发到下游管道时,只需使用推送工件的作业中的需求,然后它就会被传递到下游。

最新更新