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.
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:This
-
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
- At the root of your Astro Git repository, add a Jenkinsfile that includes the following script:
Jenkinsfile
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
-
At the root of your Git repository, add a
Jenkinsfilethat includes the following script:
Jenkinsfile