Recover binary artifact in Continuous integration in Gitlab

Hi.

First time here. I’m working on a project that needs to integrate Continuous Integration (CI) and we are using PlatformIO on the desktop until now. Now we need to implement CI. We are using Gitlab for the CI. The yml file used is lsted below:

image: python:3.11

# Change cache directories to be inside the project directory since GitLab can only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  PLATFORMIO_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pio"
  #PROJECT_BUILD_DIR: "./bin"

cache:
  paths:
    - .cache/pip
    - .cache/pio

stages:
 - build
# - deploy
# - release

build_job:
  stage: build
  script: 
    - pio ci --board=esp32dev --keep-build-dir

  variables: 
    {PLATFORMIO_CI_SRC: "./src/main.cpp"}
  
  artifacts:
    paths:
      - /bin

before_script:
  - "pip install -U platformio"
>

The end of the output is listed below:

Linking .pio/build/esp32dev/firmware.elf
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   6.6% (used 21464 bytes from 327680 bytes)
Flash: [==        ]  20.4% (used 266985 bytes from 1310720 bytes)
Building .pio/build/esp32dev/firmware.bin
esptool.py v4.5.1
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
========================= [SUCCESS] Took 12.65 seconds =========================
Saving cache for successful job
00:13
Creating cache default-protected...
.cache/pip: found 451 matching artifact files and directories 
.cache/pio: found 22 matching artifact files and directories 
Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/70293950/default-protected 
Created cache
Uploading artifacts for successful job
00:02
Uploading artifacts...
./bin: found 2 matching artifact files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created  id=10245380078 responseStatus=201 Created token=67_nG1FqN
Cleaning up project directory and file based variables
00:01
Job succeeded

It seems like the artifacts were copied to the “bin” folder, but it is empty. Any comments or suggestions?

Just setting this will not make PlatformIO save output in that /bin folder. It will still generate the output firmware into, as also oiutput by the build log, .pio/build/esp32dev/firmware.bin, or in general, .pio/build/<environment name>/firmware.bin. The firmware.elf, firmware.map et cetera will also be in that folder.

So, you can just adapt the target path to e.g. .pio/build/esp32dev/firmware.bin if you just want that file as artifact.

When I change the artifacts sections to

artifacts:
paths:
.pio/build/esp32dev/firmware.bin

It can’t find the resulting file to give me as an artifact, as can be seen bellow:

Created cache
Uploading artifacts for successful job
00:01
Uploading artifacts…
WARNING: .pio/build/esp32dev/firmware.bin: no matching files. Ensure that the artifact path is relative to the working directory (/builds/llbuenoo/teste)
ERROR: No files to upload
Cleaning up project directory and file based variables
00:00
Job succeeded

It says that resulting file must me in the project structure, but the .pio folder where the artifact is located doesn’t belong to my folder structure and I have no idea where to find it. I’ve tryed many scripts to list the folder structure to copy the file, but no success.

Any more ideas or suggestions?

Oh, right. With pio ci, it creates a temporary project and compiles it in there.

Two options:

  • use the --build-dir option for pio ci to point to a build folder to use, then you again have a known path in which the firmware file will be generated (<chosen build directory>/.pio/build/esp32dev/firmware.bin)
  • if your project has a platformio.ini, use the regular pio run command, then the firmware will indeed be in .pio/build/esp32dev/firmware.bin.