Integrate Balena into Jenkins CI

Maybe posting it into projects will help…

Hi all,

I’d like to integrate the Balena infrastructure with Jenkins CI to cover the CD part in my CICD sandbox project, that I’ve been working on.

For the CI part I chose to use Jenkins that does the following: takes my code from git repository, creates and builds Docker image based on Dockerfile(s) (couple of base custom base images and a runtime one), runs the tests. Upon successful competition of all these tasks, the output is the newly created docker image label, that I push to local Docker registry in case of master branch, or simply remove the image in case of development git branch. The idea in this Jenkins pipeline is to ensure that the changes done in the dev branch are ‘valid’ to be merged with the master one.

So, with all this relatively covered (there is quite a few cool cosmetics that I’m working on, but mostly the pipeline will remain as explained), I’d like to level up my small world with the deployment process based on Balena. I’ve successfully managed to create my first ship in the fleet (kudos for naming strategy!), push the changes and deploy them to my freshly created device. And, at this point I’m pretty much stuck, because I’m not sure how to integrate these changes to already existing Jenkins pipeline.

On one hand I can move all the code that I’ve been working on into the Dockerfile (compile, build, run tests etc.) and just keep short one-liner in the Jenkins. But I really don’t like this approach, since there is a reason behind the Jenkins approach (with all awareness to Jenkins lacking of some features)

On the other hand, I’m looking through the documentation, and completely failing to connect the dots…

So, any advise would be more than welcomed!
Meanwhile I’ll continue to dive into Balena documentation.

Thanks in advance)

Hi there, just to summarize, you want the image you build by Jenkins to be pushed to your fleet? Looks like you need the deploy command from the CLI (, which you can run after a build has succeeded from your master branch. So, instead of (or along with) pushing the built image to your local Docker registry, you can run balena deploy ... and have the same image pushed to our registry and deployed to your devices.

Thanks @sradevski! sounds like I need to dive deeper and start reading on CLI. But how do I run my unit-tests? Right now I’m building a docker image, which might be solid candidate for the product, then I evaluate my testing rig (on this image candidate). Upon successful testing pass I ‘push’ the image forward. Is there any way to maintain this strategy using Balena tools set?

Hi @yuria ,

Yes, you should definitely be able to push the same image you’re testing on to the application. A brief example workflow would be:

  1. Create a Jenkins project which includes access to balena-cli and Docker
  2. Pull the code for your application, including Dockerfile.template, Dockerfile or docker-compose.yml
  3. Pull any test frameworks you require
  4. balena build the image from your application code
  5. Run tests on this image using any relevant framework (maybe you’re building an AMD64 compatible image for a NUC, for example, you could just docker run ... this locally and test against a framework
  6. balena deploy the already built and tested image to the balenaCloud
  7. Application is downloaded onto device

The two key balena CLI commands here are balena build which will build the Docker images locally on the machine carrying out the command (and can be used in the same was as any local Docker image), and balena deploy which will push the built image directly to the balenaCloud registry, along with any relevant docker-compose.yml files.

Hopefully this clarifies the process a bit more! The page Stevche posted above explains this a bit more.

Best regards, Heds

Thanks @hedss! Seems like this is exactly what I’m looking for right now!

You’re most welcome @yuria, please let us know if we can help if you have any future questions!

1 Like