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

时间:2021-07-12 10:10:04

标签: gitlab gitlab-ci pipeline cicd

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

2 个答案:

答案 0 :(得分:0)

当您触发下游管道时,只需使用推送工件的作业的需求,然后将其传递给下游。

答案 1 :(得分:0)

假设您想将文件复制到另一个 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-job-artifacts-for-other-projects

相关问题