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
- An Astro project hosted in a Git repository that Jenkins can access.
- An Astro Deployment.
- A Deployment API token, Workspace API token, or Organization API token.
- Access to Jenkins.
Each CI/CD template implementation might have additional requirements.
Image deploy templates
Single branch
Multiple branch
Custom Image
To automate code deploys to a single Deployment using Jenkins, complete the following setup in a Git-based repository hosting an Astro project:
-
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.
-
At the root of your Astro Git repository, add a Jenkinsfile that includes the following script:
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.
If you stage multiple commits to dag files and push them all at once to your remote branch, the template only deploys dag code changes from the most recent commit. It will miss any code changes made in previous commits.
To avoid this, either push commits individually or configure your repository to Squash commits for pull requests that merge multiple commits simultaneously.
Single branch implementation
Use the following template to implement dag-only deploys to a single Deployment using Jenkins.
-
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.
-
At the root of your Git repository, add a
Jenkinsfile
that includes the following script: