Jenkins and Codemagic: A Strategic Collaboration for Mobile Development
Jenkins has established itself as a cornerstone in enterprise continuous integration and continuous delivery (CI/CD) systems. For organizations focused on backend services, multi-stage deployments, and complex polyglot pipelines, Jenkins offers the essential flexibility and control that engineering teams require. However, the conversation around replacing Jenkins is not one that most organizations want to entertain, nor is it necessary.
When it comes to mobile development, however, the challenges differ significantly.
Utilizing Jenkins for building iOS and Android applications presents unique infrastructure hurdles that the platform was not originally designed to address. These include maintaining macOS build agents, managing various versions of Xcode across a fleet of Mac minis, navigating the intricacies of Apple code signing in shared environments, and ensuring that build machines are consistently updated and secure. These challenges stem not from Jenkins itself but from the mobile infrastructure demands that are consuming valuable time from engineering teams.
Therefore, a more pertinent question arises: What if Jenkins could delegate mobile builds to infrastructure specifically designed for that purpose?
The Mobile Infrastructure Challenges That Jenkins Cannot Address
Jenkins operates as an infrastructure-agnostic solution, which works well for backend services running on Linux containers. However, when applied to mobile development, this characteristic results in substantial operational burdens.
The Mac Agent Tax
Each iOS build on Jenkins necessitates a macOS build agent. Due to Apple’s licensing regulations, macOS must run on Apple hardware, prompting organizations to invest in Mac minis, either through purchase or leasing from providers like MacStadium or AWS EC2 Mac instances. After acquiring the necessary hardware, the real challenges emerge:
Managing Xcode Versions becomes a recurring headache as Apple releases multiple updates annually, often requiring different versions for various projects. On bare-metal Jenkins agents, managing these parallel installations involves manual intervention, and unpredictable App Store updates can lead to discrepancies overnight.
Environment Drift exacerbates the situation. Jenkins agents, being long-lived, accumulate various states over time, such as cached CocoaPods and outdated provisioning profiles. This divergence can cause builds to pass on one agent while failing on another, creating frustrating debugging scenarios.
Security and Patching add additional layers of complexity. macOS security updates can disrupt keychain access crucial for code signing, and timely patching requires careful coordination to avoid interruptions in active builds. Each Mac machine must be carefully inventoried and secured to meet compliance requirements.
Scaling necessitates further hardware investment. Handling a surge in builds before a release may involve lengthy procurement processes, meaning that by the time new hardware is ready, the release may have already shipped.
None of these issues are inherent to Jenkins; they are a consequence of managing self-hosted macOS build infrastructure, resulting in a cost that organizations often underestimate.
A Hybrid Architecture: Jenkins and Codemagic
The integration between Jenkins and Codemagic is straightforward: Jenkins serves as the orchestrator, while Codemagic functions as the managed mobile build executor. Jenkins can trigger builds on Codemagic via API, while Codemagic returns build results through post-build script steps that can interact with any external system, including Jenkins itself.
Triggering Codemagic Builds from Jenkins
Codemagic provides a REST API, with a new v3 API currently being rolled out, allowing external systems to initiate builds, pass environment variables, and specify workflows and branches. A typical Jenkins pipeline stage to delegate iOS builds to Codemagic might look like this:
// Jenkinsfile stage that delegates iOS build to Codemagic
stage('iOS Build') {
steps {
script {
def response = sh(script: """
curl -s -w "\n%{http_code}" \
-H "Content-Type: application/json" \
-H "x-auth-token: ${CM_API_TOKEN}" \
--data '{
"appId": "${CM_APP_ID}",
"workflowId": "ios-release",
"branch": "${env.GIT_BRANCH}",
"environment": {
"variables": {
"BUILD_NUMBER": "${env.BUILD_NUMBER}",
"TRIGGERED_BY": "jenkins"
}
}
}' \
-X POST https://api.codemagic.io/builds
""", returnStdout: true).trim()
echo "Codemagic build triggered: ${response}"
}
}
}
Closing the Loop: Reporting Build Results Back to Jenkins
Codemagic’s codemagic.yaml configuration supports arbitrary shell scripts in the publishing section, allowing results to be reported back to Jenkins after each build completes, whether successful or not. This integration means Jenkins does not need to poll Codemagic for status updates; instead, the Codemagic build communicates back to Jenkins, providing necessary results and metadata for further actions such as deploying to TestFlight or notifying other systems.
Advantages of Using Codemagic
Clean Environments for Every Build
Each Codemagic build runs on a fresh, ephemeral virtual machine provisioned from a known-good image. The build environment is destroyed after the build completes, preventing any state from being carried over to subsequent builds, thus eliminating many common CI failures related to environment drift.
Modern Hardware Without Capital Expenditure
Codemagic provides access to the latest Apple silicon and high-performance Linux machines:
- Mac mini M2 – Standard macOS build machine
- Mac mini M4 – More powerful macOS build machine
- Mac Studio M4 Max – Optimal for large iOS and macOS projects requiring maximum compilation throughput
- Linux X2 and X4 – Essential for Android builds and running instrumentation tests
- Windows X2 – For Flutter Windows targets and cross-platform builds
Streamlined Xcode and Toolchain Management
Codemagic’s team manages Xcode updates, ensuring builds are compatible with new versions before general availability. Multiple versions of Xcode are pre-installed on each machine and can be selected via codemagic.yaml, eliminating the need for manual management.
Pre-Installed Software Ready for Use
Codemagic’s build machines come pre-configured with essential mobile development tools, such as Xcode, Android Studio, and various dependencies, alleviating the burden of maintaining these across a fleet of agents.
Compliance Considerations
While many organizations prefer self-hosted Jenkins solutions to satisfy security and compliance requirements, transitioning part of the pipeline to a cloud provider generates questions. Codemagic addresses these concerns directly.
Shared Pool Security as the Default
Codemagic’s standard build infrastructure is designed with security as a fundamental aspect:
- Ephemeral VMs: Each build operates in a fresh VM that is discarded post-build, ensuring the source code is never stored on Codemagic’s infrastructure.
- Encrypted Networking: All data in transit is secured using SSH and TLS 1.2+ protocols.
- Encrypted Credentials: Sensitive information is stored securely and accessed only during the build process.
- Physical Security: Infrastructure is housed in ISO 27001 certified data centers.
- SOC 2 Type 2 Certification: Codemagic has achieved SOC 2 Type 2 certification, demonstrating robust security practices.
- No Persistent Access: Codemagic employees have no access to user source code or secrets unless explicitly shared.
Dedicated Machines for Compliance Needs
For organizations requiring dedicated infrastructure, Codemagic offers an Enterprise plan with dedicated machine pools, including options for custom configurations and dedicated VPCs to meet stringent compliance requirements.
Cost Analysis: Self-Hosted Mac Fleet vs. Codemagic
The total cost of ownership for a self-hosted Jenkins Mac fleet frequently exceeds initial estimates, as hardware costs are just a fraction of the total expenses.
Typical Costs for a Self-Hosted Setup
| Cost Item | Annual Estimate |
|---|---|
| 3× Mac mini M4 hardware (amortized over 3 years) | ~$2,000 |
| Colocation or MacStadium hosting | ~$10,800–$14,400 |
| DevOps engineer time for maintenance | ~$7,680–$11,520 |
| Opportunity cost of build failures | Hard to quantify, but significant |
| Total | ~$20,480–$27,920+ |
Codemagic Pricing Overview
Codemagic’s pricing is transparent, with various plans available:
| Plan | Annual Cost | Features |
|---|---|---|
| Mac mini M4 Annual Fixed Plan | $5,400/year | 3 concurrencies, unlimited minutes, access to high-performance Linux and Mac machines |
| Mac Studio M4 Max Annual Fixed Plan | $9,000/year | 3 concurrencies on high-performance hardware |
| Enterprise | From $12,000/year | Dedicated hosts, custom images, compliance support |
When considering the cost of engineer time, even the most conservative estimates suggest that Codemagic’s annual plans are less expensive than maintaining a self-hosted fleet, especially when factoring in the time saved on infrastructure management.
Implications for Your Team
Integrating Codemagic with Jenkins does not necessitate a complete overhaul of your existing systems. It simply requires adding a curl command to your Jenkinsfile and a codemagic.yaml configuration file to your repository.
What You Retain
- Jenkins as your main CI/CD orchestrator
- Existing pipeline structure and reporting dashboards
- Familiarity of your team with Jenkinsfiles
- Jenkins handling backend and non-mobile builds
What You Gain
- Faster iOS and Android builds on modern hardware
- Ephemeral build environments free of state drift
- Managed Xcode and toolchain updates
- Audited infrastructure with compliance options
- Engineering time redirected to product development
What You Eliminate
- Management of Mac mini hardware and infrastructure
- Complex Xcode version handling
- Debugging time spent on environment drift
- Key-person risk associated with infrastructure maintenance
Getting Started with Codemagic
- Create a Codemagic account and link your mobile project repository.
- Define your build workflow in
codemagic.yaml, following the documentation. - Retrieve your API token from your Codemagic account.
- Add a trigger stage in your Jenkinsfile to call the Codemagic API.
- Implement a post-build callback in your
codemagic.yamlto relay results back to Jenkins. - Decommission your Mac agents after validating the integration.
Codemagic provides free onboarding support for teams transitioning to this integrated setup. For those considering the Enterprise plan, contact the sales team to discuss compliance and dedicated infrastructure options.
With Jenkins orchestrating the workflow and Codemagic managing mobile builds, your engineering team can focus on what truly matters: delivering quality products.
Chief Editor of DC City Beat — Washington, D.C.'s independent investigative newspaper covering the nation's capital with fearless public accountability and free access for all readers.









