Apache Airflow Jenkins Provider

4.2.5 · active · verified Thu Apr 16

The Apache Airflow Jenkins Provider package integrates Apache Airflow with Jenkins, a popular open-source automation server. It allows users to orchestrate and monitor Jenkins jobs directly from Airflow Directed Acyclic Graphs (DAGs), enabling seamless integration of CI/CD pipelines and data workflows. The current version is 4.2.5, and it follows the release cadence of the Apache Airflow provider ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to trigger a Jenkins job using the `JenkinsJobTriggerOperator`. Before running, configure a Jenkins connection named 'jenkins_default' in your Airflow UI with the appropriate Jenkins server URL, username, and password. The example assumes a Jenkins job named 'my_sample_jenkins_job' exists and accepts 'PARAM1' and 'PARAM2' as build parameters.

from __future__ import annotations
import pendulum
from airflow.models.dag import DAG
from airflow.providers.jenkins.operators.jenkins_job_trigger import JenkinsJobTriggerOperator

# Ensure you have a Jenkins connection configured in Airflow UI:
# Conn Id: jenkins_default
# Conn Type: Jenkins
# Host: http://your-jenkins-server.com:8080
# Login: your_jenkins_username
# Password: your_jenkins_password

with DAG(
    dag_id='jenkins_job_example',
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    catchup=False,
    schedule=None,
    tags=['jenkins', 'example'],
) as dag:
    trigger_jenkins_job = JenkinsJobTriggerOperator(
        task_id='trigger_my_jenkins_job',
        jenkins_connection_id='jenkins_default',
        job_name='my_sample_jenkins_job',
        parameters={'PARAM1': 'value1', 'PARAM2': 'value2'},
        allowed_jenkins_states=['SUCCESS', 'UNSTABLE'],
        # Optional: You can also specify build_params for a specific build trigger
        # build_params={'token': 'YOUR_JENKINS_JOB_TOKEN'}
    )

view raw JSON →