Skip to main content

Astro CI/CD templates for Jenkins

Use the following CI/CD templates to automate deploying Apache Airflow DAGs from a Git repository to Astro with Jenkins.

The following templates for Jenkins are available:

Each template type supports multiple implementations. If you have one Deployment and one environment on Astro, use the single branch implementation. If you have multiple Deployments that support development and production environments, use the multiple branch implementation. If your team builds custom Docker images, use the custom image implementation.

For more information on each template or to configure your own, see Template overview. To learn more about CI/CD on Astro, see Choose a CI/CD strategy.

Prerequisites

Each CI/CD template implementation might have additional requirements.

Image deploy templates

To automate code deploys to a single Deployment using Jenkins, complete the following setup in a Git-based repository hosting an Astro project:

  1. In your Jenkins pipeline configuration, add the following environment variables:

    • ASTRO_API_TOKEN: The value for your Workspace or Organization API token.
    • ASTRONOMER_DEPLOYMENT_ID: The Deployment ID of your production deployment

    To set environment variables in Jenkins, on the Jenkins Dashboard go to Manage Jenkins > Configure System > Global Properties > Environment Variables > Add. To see Jenkins documentation on environment variables click here

    Be sure to set the value for your API token as secret.

  2. At the root of your Astro Git repository, add a Jenkinsfile that includes the following script:

    pipeline {
    agent any
    stages {
    stage('Deploy to Astronomer') {
    when {
    expression {
    return env.GIT_BRANCH == "origin/main"
    }
    }
    steps {
    checkout scm
    sh '''
    curl -LJO https://github.com/astronomer/astro-cli/releases/download/v1.26.0/astro_1.26.0_linux_amd64.tar.gz
    tar -zxvf astro_1.26.0_linux_amd64.tar.gz astro && rm astro_1.26.0_linux_amd64.tar.gz
    ./astro deploy env.ASTRONOMER_DEPLOYMENT_ID
    '''
    }
    }
    }
    post {
    always {
    cleanWs()
    }
    }
    }

    This Jenkinsfile triggers a code push to Astro every time a commit or pull request is merged to the main branch of your repository.

DAG deploy templates

The DAG deploy template uses the --dags flag in the Astro CLI to push DAG changes to Astro. These CI/CD pipelines deploy your DAGs only when files in your dags folder are modified, and they deploy the rest of your Astro project as a Docker image when other files or directories are modified. For more information about the benefits of this workflow, see Deploy DAGs only.

Single branch implementation

Use the following template to implement DAG-only deploys to a single Deployment using Jenkins.

  1. In your Jenkins pipeline configuration, add the following parameters:

    • ASTRO_API_TOKEN: The value for your Workspace or Organization API token.
    • ASTRONOMER_DEPLOYMENT_ID: The Deployment ID of your production deployment

    Be sure to set the values for your API token as secret.

  2. At the root of your Git repository, add a Jenkinsfile that includes the following script:

    pipeline {
    agent any
    stages {
    stage('Dag Only Deploy to Astronomer') {
    when {
    expression {
    return env.GIT_BRANCH == "origin/main"
    }
    }
    steps {
    checkout scm
    sh '''
    curl -LJO https://github.com/astronomer/astro-cli/releases/download/v1.26.0/astro_1.26.0_linux_amd64.tar.gz
    tar -zxvf astro_1.26.0_linux_amd64.tar.gz astro && rm astro_1.26.0_linux_amd64.tar.gz
    files=($(git diff-tree HEAD --name-only --no-commit-id))
    find="dags"
    if [[ ${files[*]} =~ (^|[[:space:]])"$find"($|[[:space:]]) && ${#files[@]} -eq 1 ]]; then
    ./astro deploy env.ASTRONOMER_DEPLOYMENT_ID --dags;
    else
    ./astro deploy env.ASTRONOMER_DEPLOYMENT_ID;
    fi
    '''
    }
    }
    }
    post {
    always {
    cleanWs()
    }
    }
    }

Was this page helpful?

Sign up for Developer Updates

Get a summary of new Astro features once a month.

You can unsubscribe at any time.
By proceeding you agree to our Privacy Policy, our Website Terms and to receive emails from Astronomer.