Cross-project build artifacts dependencies
Problem to Solve
With recently added cool feature of specifying
dependencies between stages (gitlab-ce#14211) it's now possible to re-use built artifacts across stages by adding a few lines in
.gitlab-ci.yml. What's missing though is an extension to this feature, allowing to easily specify dependency on some build's some stage's artifact from another project.
Currently in the build for executable project I'm simply re-building libraries' code every time I build an executable, which is waste of time and resources. The feature of cross-project dependencies would solve the problem elegantly and make life easier, i.e. no need for additional API keys, curl'ing, secure variables, etc. It also may help others requesting features like gitlab-ce#4768 (better links for artifacts).
To implement this behavior, we'll add new keywords for
needs which can reference another project/ref/artifacts as follows:
generate_content: needs: - project: this_project ref: master artifacts_from: last_succesful artifacts_job: generate_cache
This will bring in the last successfully built artifacts from the
generate_cache job on the
master branch of the project
The following is the original proposal in the issue.
Suppose I have a library project
my-libraryand some other project
my-exewhich needs artifacts from
my-library's build stage during its build. So, under the proposal,
.gitlab-ci.ymlmay look something like this:
... # build job of my-exe project build:linux: stage: build dependencies: - project: quyse/my-library # mandatory, name of the project commit: 123456789abcdef123456789abcdef123456789a # optional, commit hash in my-library repository branch: master # optional, branch name in my-library repository tag: v1.1 # optional, tag name in my-library repository # could be other filters job: linux-x64 # mandatory, job name defined in .gitlab-ci.yml in my-library script: ... ...
So here CI is supposed to fetch artifacts of the
linux-x64job of the build of
my-libraryproject made for specified branch and commit (or specified tag), and unpack them into runner's working directory of
my-exebuild (in the same way as it does currently).
- There's no ambiguity with current usage of
dependenciesfield: string value may still mean dependency on some other stage of the same project, and only if it's a YAML map value, then it's an external (cross-project) dependency.
tagfields are all optional, and work as a filter, they may be used simultaneously to resolve ambiguity: for example there could be multiple builds corresponding to the single commit (in different branches), and of course there're multiple builds corresponding to the single branch. (Actually even with both
tagspecified it could still be multiple builds, for example, if build has been retried, or branch deleted/re-pushed, or whatever). So if there're multiple builds, CI can just use the latest one.
- Probably CI must always use the latest successful build (from the list of builds matching the filter), i.e. the build where all the stages (not marked with
allow_failure) are successful, not just the one we are using artifacts from. (Just not sure if such a concept already exists).
- If there's no matching builds of the library, the dependent build must wait until one appears (essentially, in the same way as dependent stages are waiting for their dependencies currently).
- CI runner should fetch artifacts using its API token, so it should be allowed to access private projects it has been added to (or if it's added to the group, or whatever other rules apply here).
- It looks reasonable that this feature will only work across projects of the single Gitlab server.