Search code examples
antgitlabgitlab-ci

Gitlab-CI how to reference source from another project?


I have two projects, first is SOURCES (technical base) and second is an ant software. I have create a gitlab-ci.yml on the second project but the build pipeline is always in error because sources libraries are not referenced.

In my build.xml, sources are referenced like this: ${SOURCES_DIRRECTORY}/folder/lib/library.jar In the gitlab-ci.yml I can set SOURCES_DIRRECTORY but putting the url of the other project doesn't seem to work.

A prohibited solution is to add the sources in an local lib folder. (so as not to duplicate)

Is it possible to reference another gitlab project from my CI ? Otherwise, how can I retrieve and use the artifact generated by the sources project to obtain the libraries on my software project?

Thank you for your answers


Solution

  • You can use the GitLab CI APIs to download the artifacts made in the other project.

    I do something similar in one of my project and it work for me

    curl -k --location --output artifacts.zip --header  "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/artifacts/devel/download?job=$STAGE_NAME"
    

    In this case i download the artifacts made by another branch in the same project, so I already have setted by default the variables and I can use JOB-TOKEN, instead you should use the PRIVATE-TOKEN that is an ACCESS TOKEN with the API permission grant. You should have something like that

    curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/main/download?job=test"