Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- VUE
- intellij
- Postman
- pagination
- Java
- minikube
- Seek_Keyset
- MYSQL에러
- springMVC
- SQL
- wappalyzer
- 스프링에러
- CloutNative
- frontend
- SpringBoot
- MySQL
- appleM1
- String
- gradle
- DB생성
- restful api
- offset
- NullPointerException
- Lombok
- K8S
- 우분투에war배포
- spring
- MySQL시작하기
- windows10
- 이클립스
Archives
- Today
- Total
미운 오리 새끼의 우아한 개발자되기
[CI & CD] Jenkins 에서 AWS Credentials 사용하기 본문
파이프라인 : BitBucket -> Jenkins (Build & Deploy) -> AWS ECS
SCM 에서 소스를 가져올 땐 BitBucket 의 Credentials 을 넣어주었다
그런데 문제는 Jenkins -> AWS 에 Deploy 를 할 때 AWS
1. Case 1 ) Access key, secret access key를 어디다가 넣어줘야하는지 몰랐고
2. Case 2) 넣어준다 하더라도 Jenkinsfile에서 어떻게 갖다 써야하는지 몰랐다.
사내 Jenkins 담당자는 Credentials 추가했다는데 SCM -> Credentials의 dropdown 에는 보이지도 않고 ㅜㅜ
하루를 꼬박... 바보같은 짓만 했다...
한글로 된 블로그를 참고해서 Jenkins UI 에서 Parameter 로 추가하면 된다는 걸 알았다. (Case 1 Closed)
이제 이걸 Jenkinsfile 에서 가져다 쓰려면 아래와 같이 하면 된다. (Case 2 Closed)
pipeline {
agent any
tools {
maven 'maven-3.6'
jdk 'jdk8'
}
stages {
stage('Prepare') {
steps {
script {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: '${awsCredentials}', // Jenkins UI 에 등록한 parameter 이름
accessKeyVariable: 'AWS_ACCESS_KEY_ID', // 이렇게만 써줘도 ACCESS KEY ID로 인식한다!
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]]) {
sh 'aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.ap-northeast-2.amazonaws.com/xxx'
}
}
}
}
// 다른 Stage 에서 aws cli 호출 시 이렇게 withCredentials 로 써줘야한다.
// 한번 쓴다고 다른 stage 에서 적용되진 않더라
stage('Aws ECS Deploy') {
steps {
script {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: '${awsCredentials}',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]]) {
def ecs_update_url = "aws ecs update-service --cluster xxx-ecs-cluster --service xxx-fargate-ecs-service --task-definition xxx:3"
sh ecs_update_url
}
}
}
}
}
}
-> jenkins 전체 파일이 아니다..! 예시를 위해 필요한 부분만 가져왔으니 고대로 쓰지말기~
44번의 실패와 첫번째 성공...