Build and commit to repository via CI

I’m a bit puzzled on how to solve this, I have a private repository that contains a node module that I use in other projects. The problem is that I’m just using a private git repository, and thus I need to create a build first locally, and then commit that build.

Would it be possible to skip this step, and let the CI create a build, and then commit those files to my repository? That way I can at least separate my commit messages, and will be sure I always have the latest build.

I know I can use git commands in the CI, however when I make a new commit, wouldn’t this just trigger the CI again?


I would avoid raw Git commands and use the REST API instead. This grants you the possibility to upload a specific file to a repository.

One thing which may be needed is the authorization token, since you’re coming from a private repo pushing to a different other repository, not necessarily in the same group.
This token can e.g. be passed via environment variables in the project settings. Depending the public projects which need this binary build, a different solution might be needed. If it is just for 2-3 in the same group, it should work though with the same or different tokens, or a specific user created with just these permissions for the auth token.

Your first step should be to ensure that the private project has a .gitlab-ci.yml and builds the artifacts. Then add another stage and job which does the upload step, e.g. with curl’ing the generated file.

Best would be to use a test repository and see how the uploads and generated commits work there. If you are satisfied, change the target to the production repositories.

For running the builds, I’d suggest to run the upload job only for tagged releases, not for master or branch pushes. This avoids noise in the public repos.


Hi Michael,

Thanks for the detailed response, is there any reason why you would avoid raw git commands? I need to push these files to the same repository, so I would assume the CI already had access to it.

I already have an existing pipeline that generates the artifacts, they’re just not being used yet. I’ll take your advice and quickly try this on a test repo.

Good advice on running it only against tagged releases, that also gives me better control over it.

Nice Guideline


I was under the impression that you are having a private repository with hidden source code, and just want to publish the binary build into a secondary public repository. E.g. a compiled Java class, or shared library.

If you can solve that just within the same repository, that’s also fine but requires a stronger control over when the CI is run, e.g. on special tags for this binary release.