Created
October 17, 2025 20:14
-
-
Save cnolanminich/edd853827cbb84d00ef74dda41c3f171 to your computer and use it in GitHub Desktop.
example hybrid jenkinsfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pipeline { | |
| agent any | |
| environment { | |
| // Dagster Cloud Configuration | |
| DAGSTER_CLOUD_ORGANIZATION = 'your-org-name' // Replace with your Dagster+ org name | |
| DAGSTER_CLOUD_API_TOKEN = credentials('dagster-cloud-api-token') // Jenkins credential ID | |
| DAGSTER_BUILD_STATEDIR = "${WORKSPACE}/build_state" | |
| // AWS ECR Configuration | |
| AWS_REGION = 'us-west-2' // Replace with your AWS region | |
| AWS_ACCOUNT_ID = credentials('aws-account-id') // Jenkins credential ID | |
| ECR_REGISTRY = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" | |
| ECR_REPOSITORY = 'dagster-cloud-image' // Replace with your ECR repository name | |
| IMAGE_TAG = "${GIT_COMMIT.take(7)}-${BUILD_NUMBER}" | |
| // AWS Credentials | |
| AWS_ACCESS_KEY_ID = credentials('aws-access-key-id') // Jenkins credential ID | |
| AWS_SECRET_ACCESS_KEY = credentials('aws-secret-access-key') // Jenkins credential ID | |
| // Project Configuration | |
| PROJECT_DIR = '.' | |
| LOCATION_NAME = 'quickstart_etl' // Replace with your code location name | |
| } | |
| stages { | |
| stage('Checkout') { | |
| steps { | |
| echo "Checking out code from Git repository..." | |
| checkout scm | |
| script { | |
| // Create build state directory | |
| sh "mkdir -p ${DAGSTER_BUILD_STATEDIR}" | |
| } | |
| } | |
| } | |
| stage('Install Dependencies') { | |
| steps { | |
| echo "Installing dagster-cloud CLI and dependencies..." | |
| sh ''' | |
| python3 -m pip install --upgrade pip | |
| pip install dagster-cloud | |
| ''' | |
| } | |
| } | |
| stage('Dagster Cloud - Configuration Check') { | |
| steps { | |
| echo "Validating dagster_cloud.yaml configuration..." | |
| sh ''' | |
| dagster-cloud ci check --project-dir=${PROJECT_DIR} | |
| ''' | |
| } | |
| } | |
| stage('Dagster Cloud - Initialize Build Session') { | |
| steps { | |
| echo "Initializing Dagster Cloud build session..." | |
| sh ''' | |
| dagster-cloud ci init --project-dir=${PROJECT_DIR} | |
| ''' | |
| } | |
| } | |
| stage('AWS ECR - Login') { | |
| steps { | |
| echo "Logging into AWS ECR..." | |
| sh ''' | |
| aws ecr get-login-password --region ${AWS_REGION} | \ | |
| docker login --username AWS --password-stdin ${ECR_REGISTRY} | |
| ''' | |
| } | |
| } | |
| stage('Docker - Build Image') { | |
| steps { | |
| echo "Building Docker image..." | |
| sh ''' | |
| docker build . \ | |
| -t ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} \ | |
| -t ${ECR_REGISTRY}/${ECR_REPOSITORY}:latest \ | |
| --build-arg DAGSTER_CLOUD_ORGANIZATION=${DAGSTER_CLOUD_ORGANIZATION} | |
| ''' | |
| } | |
| } | |
| stage('Docker - Push to ECR') { | |
| steps { | |
| echo "Pushing Docker image to ECR..." | |
| sh ''' | |
| docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} | |
| docker push ${ECR_REGISTRY}/${ECR_REPOSITORY}:latest | |
| ''' | |
| } | |
| } | |
| stage('Dagster Cloud - Update Build Output') { | |
| steps { | |
| echo "Updating build session with Docker image tag..." | |
| sh ''' | |
| dagster-cloud ci set-build-output \ | |
| --location-name=${LOCATION_NAME} \ | |
| --image-tag=${IMAGE_TAG} | |
| ''' | |
| } | |
| } | |
| stage('Dagster Cloud - Deploy') { | |
| steps { | |
| echo "Deploying to Dagster Cloud..." | |
| sh ''' | |
| dagster-cloud ci deploy | |
| ''' | |
| } | |
| } | |
| stage('Cleanup') { | |
| steps { | |
| echo "Cleaning up Docker images..." | |
| sh ''' | |
| docker rmi ${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG} || true | |
| docker rmi ${ECR_REGISTRY}/${ECR_REPOSITORY}:latest || true | |
| ''' | |
| } | |
| } | |
| } | |
| post { | |
| success { | |
| echo "✅ Dagster Cloud deployment completed successfully!" | |
| echo "View your deployment at: https://${DAGSTER_CLOUD_ORGANIZATION}.dagster.cloud" | |
| } | |
| failure { | |
| echo "❌ Dagster Cloud deployment failed. Check the logs above for details." | |
| } | |
| always { | |
| // Clean up build state directory | |
| sh "rm -rf ${DAGSTER_BUILD_STATEDIR} || true" | |
| // Clean up Docker build cache (optional) | |
| // sh "docker system prune -f || true" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment