automated terminal push
This commit is contained in:
33
Jenkinsfile
vendored
33
Jenkinsfile
vendored
@@ -121,9 +121,11 @@ pipeline {
|
|||||||
returnStdout: true
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
|
|
||||||
|
// Check force parameter first - this overrides everything
|
||||||
if (params.FORCE_INFRASTRUCTURE_DEPLOY) {
|
if (params.FORCE_INFRASTRUCTURE_DEPLOY) {
|
||||||
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
||||||
echo "🚨 FORCED: Infrastructure deployment requested via parameter"
|
echo "🚨 FORCED: Infrastructure deployment requested via parameter"
|
||||||
|
echo "✅ Deployment type set to: INFRASTRUCTURE (forced)"
|
||||||
} else if (infrastructureFiles == "initial") {
|
} else if (infrastructureFiles == "initial") {
|
||||||
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
||||||
echo "✅ First run detected. Deploying infrastructure."
|
echo "✅ First run detected. Deploying infrastructure."
|
||||||
@@ -275,15 +277,10 @@ pipeline {
|
|||||||
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) {
|
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) {
|
||||||
script {
|
script {
|
||||||
echo "🔍 SECURITY: Checking if infrastructure is ready for deployment..."
|
echo "🔍 SECURITY: Checking if infrastructure is ready for deployment..."
|
||||||
|
echo "🔍 Current deployment type: ${env.DEPLOYMENT_TYPE}"
|
||||||
|
|
||||||
// Check if infrastructure deployment was already forced
|
// Only check readiness if not forced
|
||||||
if (params.FORCE_INFRASTRUCTURE_DEPLOY) {
|
if (env.DEPLOYMENT_TYPE == "APPLICATION") {
|
||||||
echo "🚨 FORCED: Infrastructure deployment requested via parameter"
|
|
||||||
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
|
||||||
currentBuild.description = "INFRASTRUCTURE (forced) | ${env.IMAGE_TAG}"
|
|
||||||
return // Skip further checks since we're forcing deployment
|
|
||||||
}
|
|
||||||
|
|
||||||
def serviceExists = sh(
|
def serviceExists = sh(
|
||||||
script: """
|
script: """
|
||||||
aws ecs describe-services --cluster ${TF_VAR_cluster_name} --services ${TF_VAR_cluster_name}-service --region ${AWS_REGION} 2>/dev/null | grep -q 'ACTIVE' && echo 'true' || echo 'false'
|
aws ecs describe-services --cluster ${TF_VAR_cluster_name} --services ${TF_VAR_cluster_name}-service --region ${AWS_REGION} 2>/dev/null | grep -q 'ACTIVE' && echo 'true' || echo 'false'
|
||||||
@@ -303,9 +300,9 @@ pipeline {
|
|||||||
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
env.DEPLOYMENT_TYPE = "INFRASTRUCTURE"
|
||||||
currentBuild.description = "INFRASTRUCTURE (auto-detected) | ${env.IMAGE_TAG}"
|
currentBuild.description = "INFRASTRUCTURE (auto-detected) | ${env.IMAGE_TAG}"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo "📋 SECURITY: Infrastructure readiness assessment completed"
|
echo "📋 SECURITY: Infrastructure readiness assessment completed"
|
||||||
echo " ECS Service Exists: ${serviceExists}"
|
|
||||||
echo " Container Instances: ${instanceCount}"
|
|
||||||
echo " Final Deployment Type: ${env.DEPLOYMENT_TYPE}"
|
echo " Final Deployment Type: ${env.DEPLOYMENT_TYPE}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +311,10 @@ pipeline {
|
|||||||
|
|
||||||
stage('Deploy Infrastructure') {
|
stage('Deploy Infrastructure') {
|
||||||
when {
|
when {
|
||||||
expression { env.DEPLOYMENT_TYPE == "INFRASTRUCTURE" }
|
expression {
|
||||||
|
echo "🔍 Checking deployment type: ${env.DEPLOYMENT_TYPE}"
|
||||||
|
return env.DEPLOYMENT_TYPE == "INFRASTRUCTURE"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) {
|
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: env.AWS_CRED_ID]]) {
|
||||||
@@ -331,6 +331,17 @@ pipeline {
|
|||||||
-backend-config="key=${TF_BACKEND_PREFIX}" \\
|
-backend-config="key=${TF_BACKEND_PREFIX}" \\
|
||||||
-backend-config="region=${AWS_REGION}" \\
|
-backend-config="region=${AWS_REGION}" \\
|
||||||
-backend-config="dynamodb_table=${TF_DDB_TABLE}"
|
-backend-config="dynamodb_table=${TF_DDB_TABLE}"
|
||||||
|
|
||||||
|
echo "🔄 Planning infrastructure changes..."
|
||||||
|
terraform plan \\
|
||||||
|
-var="cluster_name=${TF_VAR_cluster_name}" \\
|
||||||
|
-var="vpc_cidr=${TF_VAR_vpc_cidr}" \\
|
||||||
|
-var="public_subnets=${TF_VAR_public_subnets}" \\
|
||||||
|
-var="instance_type=${TF_VAR_instance_type}" \\
|
||||||
|
-var="key_pair_name=${TF_VAR_key_pair_name}" \\
|
||||||
|
-var="jenkins_ip_cidr=${TF_VAR_jenkins_ip_cidr}" \\
|
||||||
|
-var="aws_region=${TF_VAR_aws_region}"
|
||||||
|
|
||||||
echo "🔄 Applying infrastructure changes..."
|
echo "🔄 Applying infrastructure changes..."
|
||||||
terraform apply -auto-approve \\
|
terraform apply -auto-approve \\
|
||||||
-var="cluster_name=${TF_VAR_cluster_name}" \\
|
-var="cluster_name=${TF_VAR_cluster_name}" \\
|
||||||
|
Reference in New Issue
Block a user