使用 AWSCLI 从 Jenkins 更新 ECS 集群

Update ECS cluster from Jenkins using AWSCLI

我有 ECS fargate cluster.I 正在使用 CICD 将图像推送到 ECR 存储库,然后更新 cluster.I 我正在使用存储库中的最新标签。

通过使用下面的方式,我以前是手动完成的。 创建新版本的任务定义 ----> 使用新版本的任务定义更新服务 ---> 使用旧版本停止任务。

现在,当我尝试从 Jenkins 自动执行此操作时,我正在使用 AWSCLI。

我有一个 question.If 我使用下面的命令它会创建一个新版本的任务定义和更新服务吗?或者我必须先创建一个新版本的任务定义。

  aws ecs update-service --cluster ec2cluster_name --service service_name --force-new-deployment

如果您是 updating/using 相同的图像标记,那么当您执行 forceNewDeployment 时,它将从存储库中获取最新图像并更新 ECS 服务。

ecs-update-service 文档说:

If your updated Docker image uses the same tag as what is in the existing task definition for your service (for example, my_image:latest ), you do not need to create a new revision of your task definition. You can update the service using the forceNewDeployment option. The new tasks launched by the deployment pull the current image/tag combination from your repository when they start.

https://docs.aws.amazon.com/cli/latest/reference/ecs/update-service.html

以上命令不会创建新的任务定义,要创建任务定义请查看 register-task-definition