【发布时间】:2020-04-26 00:06:23
【问题描述】:
我有一个构建映像并将其推送到 AWS ECR 的管道,我的管道的最后一个阶段是在 AWS ECS 中构建服务的 sh 命令。有没有办法将 Jenkins 创建的图像的名称推送到我的 cloudformation 堆栈,以便自动完成任务?
stage('Build image') {
steps {
script {
myapp = docker.build("${LOCATION}/${AWS_REPO_NAME}:${env.BUILD_ID}")
}
}
}
stage('Run image') {
steps {
withAWS(region:'${REGION}',credentials:'demo-ecr-credentials') {
sh "aws ecr get-login-password | docker login --username AWS --password-stdin ${LOCATION}/v2/"
sh "docker push ${LOCATION}/${AWS_REPO_NAME}:${env.BUILD_ID}"
}
}
}
stage('Build ECS') {
steps{
script {
sh 'aws cloudformation deploy --template-file cloudformation.yml
--stack-name jenkinstack '
}
}
}
}
}
这是我的 Cloudformation 堆栈的一部分:
TaskDefinition:
Type: 'AWS::ECS::TaskDefinition'
DependsOn:
- VPC
Properties:
ContainerDefinitions:
- Name: test
Cpu: '100'
Memory: "0.5GB"
Essential: 'true'
Image: !Join
- ''
- - !Ref 'AWS::AccountId'
- .dkr.ecr.us-east-1.amazonaws.com/
- hello-world
- ':'
- **${env.BUILD_ID}**
Memory: '300'
PortMappings:
- HostPort: 80
ContainerPort: 80
【问题讨论】:
标签: amazon-web-services jenkins amazon-ecs