A way to implement Pipeline as a code practice
Pipeline as code is a practice that defines deployment pipelines using source code like java or typescript, allowing teams to manage builds, tests, and deployments in a version-controlled manner
In this scenario i created a pipeline in a single file with java and typescript
Let’s see what is inside
- hello-world contains a simple spring boot application used to test pipeline
- modules folder contains java and typescript pipeline called JavaBuild as Dagger.io module
- tools is used by Tilt and a Docker Compose to define all resources used by pipeline: jenkins, gitea, nexus (behind nginx) and jaeger.
Of course docker is mandatory
Dagger.io offer a lot of sdk so just choose your best option and create it, i used java and typescript.
The pipeline executed by Jenkins is described below
- Checkout of Hello World source code
- Checkout of Dagger Module source code
- Run Dagger module (JavaBuild) as a command with parameters with (Dagger Cli)
- A Dagger Engine will executed inside a container (Server)
- Dagger Cli just wait the result of pipeline (Client)
- At the end on Nexus should have the builded image
Jenkins Pipeline
Zoom image will be displayed
Pipeline Execution Graph
Zoom image will be displayed
Gitea is used as a local git to develop/update/fix pipeline
Zoom image will be displayed
Nexus as Artifact/Docker Registry
Zoom image will be displayed
Zoom image will be displayed
Now let’s see in details the JavaBuild class which contains “pipeline”.
It contains a main method publish: test, deploy(artifact), buildImage and publish
Every step described before is a public method annotated too with Function, so is possible to call them singularly from Dagger Cli or combine them like publish to define pipeline.
Zoom image will be displayed
The advantage of this approach are
- Local and Isolated environment to run pipeline 🔁
- Debug, is possible to run a single step of pipeline or put some terminal breakpoint to see what happens
- Share, your teammates could change and test the pipeline at the same time 🔁
- Portability to another executor like Gitlab/Github
- Dagger Module leave control to Devops
- Community is very active ⭐
On the contrary
- Learning Curve, at start is little bit hard understand how it works. You will reach a good understanding after some tries
- Is necessary to know what offer the SDK
- Every step is executed on a Docker container, could be hard to manage them
Here the link to repository robertonav20/dagger-modules in case you would try it! 💻
Many thanks to Dagger.io community on Discord for the support received!
.png)

![AI-powered humanoid robot demo [video]](https://news.najib.digital/site/assets/img/broken.gif)