Hey everyone! 👋
I wanted to share our team's recent journey of untangling ourselves from a particularly gnarly Jenkins setup. For years, our build notifications relied on the venerable `email-ext` plugin with a set of templates that had... evolved. They were complex, nested with conditional logic for different branches and failure types, and had become a genuine pain point. Every time we needed to tweak the formatting or add a new project, it felt like deciphering an ancient scroll. 😅
We decided to migrate this notification layer out of Jenkins entirely during our move to GitLab CI. The goal was to replace hundreds of lines of Groovy template code with something maintainable, portable, and simple. Here's the step-by-step walkthrough of how we did it.
**The Old Pain:**
Our `email-ext` templates were doing too much:
* Constructing HTML tables with build status, commit messages, and test result summaries.
* Branch-specific logic (e.g., `main` branch failures got a different audience than feature branches).
* Embedding links to artifacts and specific failed test logs.
* All of this was stored in Jenkins' config files, opaque to most of the team.
**The New Simplicity: A Small Python Script.**
Instead of translating the templates, we wrote a single, focused Python script that our GitLab CI pipeline calls at the end of every job. The script's only job is to gather the context GitLab already provides and format a clean Slack message (we switched channels, but email would work the same).
The magic is in using the CI platform's native environment variables and metadata. For example:
* `CI_PROJECT_URL`, `CI_COMMIT_SHA`, `CI_JOB_STATUS` give us the core "what happened and where."
* We use the GitLab API (with a `$CI_JOB_TOKEN`) to fetch a few extra details if needed, like the commit message.
* The script then structures this into a straightforward JSON payload for Slack's webhook.
**Key Steps in the Migration:**
1. **Audit & Prioritize:** We listed every piece of information our old emails contained. We asked: "Who *actually* uses this?" We cut about 40% of the data points immediately.
2. **Script Prototyping:** We built the script locally, using env vars we simulated. The core logic is just string formatting and a few `if` statements.
3. **Secrets Migration:** The Slack webhook URL moved from Jenkins' credential store to GitLab's protected CI/CD variables. This was a simple copy-paste with improved access controls.
4. **Pipeline Integration:** We added one line to our `.gitlab-ci.yml` in an `after_script` block to call the script, ensuring it runs even on job failure.
5. **Phased Rollout:** We tested it on a low-traffic project first, then gradually updated pipeline templates across our repos.
**How Long It Actually Took:**
* **Planning & Audit:** 2 days (spread over a week)
* **Script Development & Testing:** 1 day
* **Pipeline Updates & Secret Migration:** 1 afternoon
* **Full Rollout Across 30+ Projects:** 1 week (done incrementally)
The result? A script under 100 lines that anyone on the team can read and modify. It's version-controlled alongside our code, and it's completely agnostic of the CI runner. If we ever move platforms again, this notification script comes with us for free.
Let me know if you've tackled similar legacy notification systemsβI'd love to hear what you replaced them with!
Clean data, happy life.