Complete the code to define the two environments used in blue-green deployment.
def deployTo[1]() { echo 'Deploying to environment' }
The blue-green deployment pattern uses two environments named 'blue' and 'green'. Here, 'blue' is used as the environment name.
Complete the code to switch traffic to the new environment in blue-green deployment.
stage('Switch Traffic') { steps { script { sh 'kubectl [1] service blue-service green-service' } } }
In blue-green deployment, 'kubectl patch' is used to switch the service from blue to green environment smoothly.
Fix the error in the Jenkins pipeline step to deploy to the green environment.
stage('Deploy Green') { steps { [1] 'deploy-green.sh' } }
The 'sh' step runs shell scripts in Jenkins pipelines on Unix-like agents. Here, it correctly runs 'deploy-green.sh'.
Fill both blanks to create a Jenkins stage that deploys to blue and green environments sequentially.
stage('Deploy Both') { steps { [1] 'deploy-[2].sh' } }
The 'sh' step runs shell scripts. The script name includes the environment name, here 'blue'.
Fill all three blanks to define a Jenkins pipeline snippet that deploys to green, switches traffic, and verifies deployment.
pipeline {
agent any
stages {
stage('Deploy Green') {
steps {
[1] 'deploy-green.sh'
}
}
stage('Switch Traffic') {
steps {
script {
sh 'kubectl [2] service blue-service green-service'
}
}
}
stage('Verify') {
steps {
[3] 'curl -f http://green.example.com/health'
}
}
}
}The 'sh' step runs shell commands for deployment and verification. 'kubectl patch' switches traffic to green.