Cross-project build artifacts dependencies
With recently added cool feature of specifying
dependencies between stages (#14211 (closed)) it's now possible to re-use built artifacts across stages by adding a few lines in
.gitlab-ci.yml. I propose an extension to this feature, allowing to easily specify dependency on some build's some stage's artifact of other project.
Suppose I have a library project
my-library and some other project
my-exe which needs artifacts from
my-library's build stage during its build. So, under the proposal,
.gitlab-ci.yml may 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-x64 job of the build of
my-library project made for specified branch and commit (or specified tag), and unpack them into runner's working directory of
my-exe build (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.
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.
I believe it's currently possible to fetch library's artifacts during the executable's build using Gitlab API. I didn't do that yet, but it's on my list, and at first glance it requires setting up API keys and stuff (runner's token is not easily accessible in the build script, is it?), which is not really a pleasant task for, let's say, a C++ developer.
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 #4768 (closed) (better links for artifacts).