Continuous Integration, Environment Variables, Build Variables

Hi,

I was wondering if anyone has recommendations or resources for the following:

  1. Integrate a particle project into a CI system such as Jenkins or other
  2. How to pass environment variables into project when compiling
  3. How to pass device specific variables into a project when compiling. i.e provide a unique BLE serviceID to two devices when compiling

Thanks

Nolan

Hi Nolan,
I work a lot with Jenkins, but I never used it for a Particle project so far.
However, I can tell you what I would do.
1- a Jenkins Agent (linux based) with Particle CLI installed would build, test and then flash my devices
2- I think this resource and this other resource can help.
From one of those:

you can use the command line parameter -D with gcc to #define a value at compile time.

$ gcc file.c -o file -D"THE_VERSION_STRING=${THE_VERSION_STRING}"

aw crap, I see now that I do not know how to use any -D using the Particle CLI, so what I mentioned above may not help much.

Perhaps someone with better knowledge of the build like @m_m would know?
Hope I was able to get you closer, but I’m not sure.
Gustavo.

Hey,
Another idea for #2 and #3 , a little bit of brute force approach, but I think it can do what you need.

You can have the pipeline to add to your project.ino file the defines before building it.
Example:

mv project.ino project.original
cat "#DEFINE blesetting1 123" > project.ino
cat "#DEFINE blesetting2 345" >> project.ino
cat project.original >> project.ino
 -- THEN BUILD NOW --

If I remember well, one bracket > creates the file and double brackets >> add content to the file.

Cheers!
Gustavo.

Most of my libraries have automated test on TravisCI, but it would work with any similar system.

For example in JsonParserGeneratorRK:

There are three files related to CI:

  • .travis.yml - specific to TravisCI to configure the VM
  • package.json - loads the build tool
  • build.yml - specifies the Device OS and devices to target

The build tool takes the build.yml file and calls the regular cloud compiler to test the build.

It’s primarily designed to test libraries, but it can be used to test apps as well (build the target . instead of an examples path).

Thanks @rickkas7, does your build tool also enable the ability to pass in variables/values to be included in compilation?

There’s no way to pass an environment variable into a cloud compile so there are really only two options:

  • Generate a .h file that is used by the cloud compile.
  • Do a local gcc-arm build within your CI. With a local build, you’re communicating with GNU make directly so you have more flexibility.

Thanks @rickkas7 and @gusgonnet for the feedback and recommendations. I’ll give these approaches a shot.