Add a specific file of a project into the release GitLab

I’m developing embedded firmware using C and IAR as IDE.

On compiling, the IDE generates a .hex file in a specific folder which (let’s say it’s /Obj basically is the full code compiled. It can be flashed directly to the microcontroller.

Now, once I got to generate a Release on GitLab, it creates 4 Assets in the form of

  • Source code (zip)
  • Source code (tar.gz)
  • Source code (tar.bz2)
  • Source code (tar)

Now, I would like to add my .hex file in it as a single file when I generate the release.

I can use all the CI/CD features inside Gitlab as I would like do it automatically when I generate the release

Is there a way to do it?

1 Like

It seems a solution is to use the generation of artifacts as explained here `.gitlab-ci.yml` keyword reference | GitLab

Now, how can I trigger the creation of the artifact when I create a Release?

Hi Nico,

I have similar situation :slight_smile:

The way how I do it is the following:

I have a build job that compiles code and creates an executable. I assume you have the same / similar. You can save this artifact using the artifacts keyword, e.g.

  stage: build
     - echo "I am building my code here and it produces a .hex in out/somefile.hex"
      - out/*.hex

Now, the thing is - artifacts don’t last forever. It’s a good habit instead of just linking the artifact to Release, upload it to Package registry. There is a Generic one, so you can put there whatever you want.

So, the next thing I do before I create a release (or paralel to it), I upload those artifacts to package registry (reference):

upload package:
  stage: package
  image: curlimages/curl:latest
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file out/somefile.hex "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/somefile/0.0.1/somefile.hex"'
    - main

Normally, your artifacts will automatically be downloaded from previous stages, so you don’t need to do anything additionally about it:

By default, jobs in later stages automatically download all the artifacts created by jobs in earlier stages. You can control artifact download behavior in jobs with dependencies.

Then, you have a release job. You can do this in a few ways, but let’s say you use release-cli - it can tag your branch and create a release with links to your packages:

  stage: release
    - release-cli create --name release-branch-$CI_JOB_ID --description "Some description" --tag-name 0.0.1 --assets-link '{"name":"Binary","url":"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/somefile/0.0.1/somefile.hex","link_type":"package"}'
    - main

To be honest, I never tried to link packages directly with CLI, but according to the docs it should work. Also, you don’t need to use it in script like I did in example, you can also specify some fields directly in yaml… have a look here.

If you don’t want to do it with release-cli, then you can also do it directly with GitLab API, e.g. using curl. But in that case you have to create release first and then add assets link afterwards - have a look at Releases API docs and Releases Links API docs.

Now, it’s up to you to decide how you version your binaries, how to pass in the that version, description, certificates (if running on premise), etc… but the general idea is here.

P.S. I didn’t test any of the jobs above, use it just as a reference :smiley:

1 Like

Hi Paula,

First of all, thanks for your extensive explanation. It will definitely be super helpful.

About my specific issue, we generate the .HEX, so the binaries, internally with our IDE (C compiler on IAR) and it will be committed with the source code as well.

I think in this scenario I just need the release stage where I pass the path on where to find the binary on my project.

Thanks again, btw; I’ll give it a try :slight_smile: