Files
azure-production/Jenkinsfile

65 lines
2.0 KiB
Plaintext
Raw Normal View History

2025-06-22 02:54:36 +00:00
pipeline {
agent any
environment {
2025-06-22 03:09:01 +00:00
// Fetch the ACR login server from Terraform outputs
ACR_LOGIN_SERVER = sh(script: 'terraform output -raw container_registry_url', returnStdout: true).trim()
RESOURCE_GROUP = 'Prod-Native-American-Empires'
CONTAINER_APP = 'skennen'
2025-06-22 02:54:36 +00:00
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
2025-06-22 03:09:01 +00:00
stage('Build Docker Image') {
2025-06-22 02:54:36 +00:00
steps {
2025-06-22 03:09:01 +00:00
script {
// Build the .NET 8 Minimal API image with a build number tag and latest
docker.build("skennen:${env.BUILD_NUMBER}", '-f dotnet8-minimal-api/Dockerfile dotnet8-minimal-api')
}
2025-06-22 02:54:36 +00:00
}
}
2025-06-22 03:09:01 +00:00
stage('Tag & Push to ACR') {
2025-06-22 02:54:36 +00:00
steps {
2025-06-22 03:09:01 +00:00
withCredentials([usernamePassword(
credentialsId: 'acr-creds',
usernameVariable: 'ACR_USER',
passwordVariable: 'ACR_PASS')]) {
sh '''
docker login $ACR_LOGIN_SERVER -u $ACR_USER -p $ACR_PASS
docker tag skennen:${BUILD_NUMBER} $ACR_LOGIN_SERVER/skennen:${BUILD_NUMBER}
docker tag skennen:${BUILD_NUMBER} $ACR_LOGIN_SERVER/skennen:latest
docker push $ACR_LOGIN_SERVER/skennen:${BUILD_NUMBER}
docker push $ACR_LOGIN_SERVER/skennen:latest
'''
}
2025-06-22 02:54:36 +00:00
}
}
2025-06-22 03:09:01 +00:00
stage('Deploy to Container App') {
2025-06-22 02:54:36 +00:00
steps {
2025-06-22 03:09:01 +00:00
withCredentials([azureServicePrincipal(
credentialsId: 'azure-sp',
subscriptionIdVariable: 'AZ_SUB',
clientIdVariable: 'AZ_CLIENT_ID',
clientSecretVariable: 'AZ_CLIENT_SECRET',
tenantIdVariable: 'AZ_TENANT_ID')]) {
2025-06-22 02:54:36 +00:00
sh '''
2025-06-22 03:09:01 +00:00
az login --service-principal -u $AZ_CLIENT_ID -p $AZ_CLIENT_SECRET --tenant $AZ_TENANT_ID
az account set --subscription $AZ_SUB
az containerapp update \
--name $CONTAINER_APP \
--resource-group $RESOURCE_GROUP \
--image $ACR_LOGIN_SERVER/skennen:latest
2025-06-22 02:54:36 +00:00
'''
}
}
}
}
post {
always {
cleanWs()
}
}
2025-06-22 03:09:01 +00:00
}