Ruslan
Ruslan

Reputation: 21

How to copy files from projects artifact to another project using cicd

i go a CICD that make an artifact and save them in public folder i need to copy some files of these artifacts to another project what script i can't use or what the best way to do it?

Upvotes: 1

Views: 11670

Answers (2)

Romain TAILLANDIER
Romain TAILLANDIER

Reputation: 1995

Assuming, you want to copy file into another gitlab project. Once artifact is built in a job, in a stage (ie : build), it will be available in all jobs of the next stage (ie : deploy).

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:[email protected]/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

If your destination is not a git repository, you can simply replace by a scp directly to server, or any other copy strategy, directly in the script.

Another way to do it is to get the last artifact of project A, inside the ci of Project B. Please see https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#retrieve-job-artifacts-for-other-projects

Upvotes: 3

anynewscom
anynewscom

Reputation: 166

When you do trigger to downstream pipelines, just use needs from job that push artifacts, then it will be passed to downstream.

Upvotes: 0

Related Questions