pipeline {
agent {
kubernetes {
defaultContainer 'aws'
yamlFile 'deploy/containers.yml'
}
}
options {
ansiColor('xterm')
timeout(210)
buildDiscarder logRotator(numToKeepStr: '128')
}
parameters {
string description: 'A deployed version of the container, available in the prod ECR', name: 'IMAGE', trim: true
string description: 'The name of the task definition to update', name: 'FAMILY', trim: true, defaultValue: 'REDACTED'
}
environment {
AWS_DEFAULT_REGION = 'us-east-2'
AWS_DEFAULT_OUTPUT = 'json'
}
stages {
stage('Prepare') {
steps {
sh 'rm -f task-definition.*.json'
writeJSON(file: 'task-definition.dev.json',
json: readYaml(text: readFile('deploy/task-definition.yml')
.replaceAll('@@IMAGE@@', params.IMAGE)
.replaceAll('@@FAMILY@@', params.FAMILY)))
sh 'echo DEV task definition:'
sh 'cat task-definition.dev.json'
}
}
stage('Development') {
environment {
AWS_ACCESS_KEY_ID = credentials('REDACTED')
}
steps {
sh 'aws ecs register-task-definition --cli-input-json file://`pwd`/task-definition.dev.json > task-output.dev.json'
script {
def taskOutput = readJSON file: 'task-output.dev.json'
def revision = taskOutput.taskDefinition.revision
sh "aws ecs update-service --cluster ${CLUSTER} --service ${SERVICE} --task-definition ${FAMILY}:${revision}"
}
}
post {
failure {
slackSend color: 'danger',
message: ":siren: Failed to deploy a new task definition for REDACTED in dev :siren: - ${env.RUN_DISPLAY_URL}"
}
success {
slackSend message: ":thinking_face: A new REDACTED task definition is ready to deploy to staging: ${env.RUN_DISPLAY_URL}" }
}
}
}
post {
always {
sh 'rm -f *.json'
}
}
}