Jenkins
Jenkins integration for triggering pipeline jobs via Ctrlplane
Setup Overview
Setting up the Ctrlplane Jenkins integration involves the following steps in order:
- Install the Plugin - Add the Ctrlplane plugin to your Jenkins instance
- Configure Global Settings - Set up the API connection and agent configuration
- Create a Jenkins Pipeline Job - Define your Jenkins pipeline job with the Ctrlplane integration
- Link to Ctrlplane Deployment - Configure the Jenkis to trigger for your Ctrlplane Deployment
Following this sequence is important as each step depends on the previous one being completed successfully.
Introduction
The Ctrlplane Jenkins integration allows you to trigger Jenkins pipeline jobs directly from Ctrlplane Deployments. This plugin installs a component within your Jenkins instance that acts as a Ctrlplane “Job Agent”, periodically polling your Ctrlplane workspace for pending jobs assigned to it.
Architecture & Air-Gapped Environments
The following is a diagram of the architecture:
This polling design has a key advantage for security and network configuration:
- Egress Only: The Jenkins instance only needs outbound (egress) network access to reach the Ctrlplane API URL you configure.
- No Ingress Required: Ctrlplane never needs to initiate a connection into your Jenkins instance. This means Jenkins can run in a restricted or air-gapped network environment, provided it has a route to communicate outwards to the Ctrlplane API. No inbound firewall rules or network exposures are necessary for Jenkins related to this plugin.
Getting Started
Prerequisites
- A running Jenkins instance (version 2.426.3 or newer recommended).
- A Ctrlplane account and workspace.
Installation
- Download: Obtain the latest plugin release (
ctrlplane-plugin.hpi
) from the plugin’s GitHub releases page. - Upload: Navigate to your Jenkins instance: Manage Jenkins -> Plugins -> Advanced settings tab.
- Deploy: Under the Deploy Plugin section (or Upload Plugin in
newer Jenkins versions), click Choose File, select the downloaded
ctrlplane-plugin.hpi
file, and click Deploy. - Restart Safely: Jenkins needs to be restarted for the plugin to become
active.
- Recommended: Check the box “Restart Jenkins when installation is complete and no jobs are running” if available during the upload process.
- Manual Restart: Alternatively, go to Manage Jenkins, click “Prepare for Shutdown” to allow running jobs to complete, and then manually restart the Jenkins service when it’s safe.
Configuration (Global Jenkins Settings)
Once Jenkins restarts with the plugin installed, you need to configure it to connect to your Ctrlplane workspace:
-
Navigate to Manage Jenkins -> System.
-
Scroll down to find the Ctrlplane Plugin section.
-
Fill in the following fields:
- API URL: The base URL of your Ctrlplane API endpoint
(e.g.,
https://app.ctrlplane.dev
). - API Key: An API key generated within your Ctrlplane
workspace with permissions to interact with jobs and agents.
- Get your API key from
<Workspace Name> > Workspace Settings > API Keys
.
- Get your API key from
- Agent ID: A unique name to identify this specific Jenkins
instance within Ctrlplane (e.g.
jenkins-agent
). This name will appear in Ctrlplane when selecting a Job Agent. - Agent Workspace ID: The UUID of the Ctrlplane Workspace this Jenkins
agent should belong to.
- Get your workspace ID from
<Workspace Name> > Workspace Settings > General
- Get your workspace ID from
- Polling Interval (seconds): The frequency (in seconds) at which the Jenkins Job Agent will poll the Ctrlplane API for new jobs.
- API URL: The base URL of your Ctrlplane API endpoint
(e.g.,
-
Click Save.
Setting up a Jenkins Pipeline Job
Before you can link a Ctrlplane Deployment to your Jenkins agent, you need to create and configure a Jenkins pipeline job that can process the Ctrlplane job data.
When the Jenkins Job Agent (plugin) detects a pending job in Ctrlplane, it will:
- Detect the pending job via polling.
- Trigger the specified Jenkins pipeline job.
- Automatically inject the following parameters into the Jenkins job:
JOB_ID
: The UUID of the triggering Ctrlplane job.
- Report the job status back to Ctrlplane.
Accessing Job Details in Jenkinsfile
Your Jenkins pipeline can use the injected JOB_ID
parameter to fetch more
details about the Ctrlplane job using the custom pipeline step ctrlplaneGetJob
provided by this plugin. This step uses the API URL and Key configured globally
in Jenkins, so you don’t need to manage credentials within the pipeline itself
for this purpose.
You can then use the job details in your Jenkins pipeline job to:
- Build your application
- Run tests
- Deploy to a target environment
Linking Ctrlplane Deployment to Jenkins Agent
After configuring the Jenkins global settings and creating your pipeline job, you can now link a Ctrlplane Deployment to use your Jenkins agent.
To configure which Jenkins Job a Ctrlplane Deployment should use as part of its workflow, you need to:
- Verify Agent in Ctrlplane: Navigate to your Ctrlplane workspace Agent UI. The URL might look like
http://{CTRLPLANE_URL}/{WORKSPACE_ID}/job-agents
. You should see the Agent ID you configured listed there. - Configure Ctrlplane Deployment:
- Go to the specific Deployment in Ctrlplane that you want to trigger
Jenkins jobs from (e.g.,
http://{CTRLPLANE_URL}/{WORKSPACE_ID}/systems/{SYSTEM_NAME}/deployments/{DEPLOYMENT_NAME}/workflow
). - In the Deployment’s workflow configuration, find the Job Agent setting. Select the Agent ID of your Jenkins instance from the dropdown list.
- Configure the Job URL Path. This is crucial. It tells the plugin
which specific Jenkins job to trigger. The format must be the full
path from the Jenkins root URL, including all
/job/
segments for folders or multibranch pipelines.- Example (Freestyle/Pipeline Job): If your Jenkins job URL is
http://myjenkins.com:8080/job/MySimpleJob/
, the Job URL Path would be/job/MySimpleJob/
. - Example (Folder/Multibranch): If your Jenkins job URL is
http://myjenkins.com:8080/job/MyOrg/job/MyRepo/job/main/
, the Job URL Path would be/job/MyOrg/job/MyRepo/job/main/
.
- Example (Freestyle/Pipeline Job): If your Jenkins job URL is
- Save the Deployment workflow configuration in Ctrlplane.
- Go to the specific Deployment in Ctrlplane that you want to trigger
Jenkins jobs from (e.g.,
This setup allows Ctrlplane to orchestrate deployments by triggering specific
Jenkins jobs, while the Jenkins jobs can securely retrieve necessary context
from Ctrlplane using the provided JOB_ID
and the custom pipeline step.