728x90
Jenkins Pipeline을 이용하여 AWS ECS를 실행하는 방법에 대해 정리해본다.
ECR 업로드 할 때 처럼 AWS CLI를 이용할텐데 아래 페이지에 접속을 해보면 API 설명이 잘 나와 있다.
https://docs.aws.amazon.com/cli/latest/reference/ecs/index.html
ecs — AWS CLI 1.27.26 Command Reference
Note: You are viewing the documentation for an older major version of the AWS CLI (version 1). AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. F
docs.aws.amazon.com
ECS 실행 명령어
aws ecs run-task --cluster {클러스터명} --network-configuration '{"awsvpcConfiguration": {"subnets": [{서브넷}],"securityGroups": [{보안그룹}]}}' --overrides '{"containerOverrides": [ {"name": "{컨테이너명}", "command" : [{어플리케이션 파라미터}]}]}' --task-definition {작업 정의} --launch-type FARGATE
- cluster : 클러스터명
- subnets : 서브넷
- securityGroups : 보안그룹(sg)
- containerOverrides
- name : 컨테이너 명
- command : 어플리케이션 실행 시 넘겨 줄 파라미터 - task-definition : 작업 정의
Jenkins Pipeline
전체 소스는 아래와 같다
pipeline {
agent any
environment {
registryCredential = 'AWS'
}
stages{
stage ('ECS Deploy') {
steps {
script{
try {
withAWS(credentials: registryCredential) {
sh '''
aws ecs run-task --cluster {클러스터명} --network-configuration '{"awsvpcConfiguration": {"subnets": [{서브넷}],"securityGroups": [{보안그룹}]}}' --overrides '{"containerOverrides": [ {"name": "{컨테이너명}", "command" : [{어플리케이션 파라미터}]}]}' --task-definition {작업 정의} --launch-type FARGATE
'''
}
} catch (error) {
print(error)
currentBuild.result = 'FAILURE'
sh "exit 1"
}
}
}
}
}
}
'CI & CD > Jenkins' 카테고리의 다른 글
Jenkins Execute Shell에서 cd 명령어 (2) | 2023.05.10 |
---|---|
Jenkins pipeline을 이용해서 ECR에 Docker Image 업로드 (0) | 2022.12.02 |
Jenkins Pipeline 셋팅하기 (0) | 2022.03.31 |
Mac OS에 Jenkins 설치하기 (0) | 2022.03.04 |