【问题标题】:Hi everyone, I have a question about Jenkins pipeline and AWS大家好,我有一个关于 Jenkins 管道和 AWS 的问题
【发布时间】: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


    【解决方案1】:

    您可以在云形成堆栈中为图像名称提供参数(即yml格式)

    --parameter-overrides使用这个可以传递jenkins生成的对应值。

    【讨论】:

    • 能否提供一个简短的例子。
    猜你喜欢
    • 2020-01-03
    • 2022-11-02
    • 2020-12-01
    • 2022-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    相关资源
    最近更新 更多