【问题标题】:Pass Container image value to AWS cloudformation template dynamically from jenkins从 jenkins 动态地将容器图像值传递给 AWS cloudformation 模板
【发布时间】:2020-11-01 19:22:07
【问题描述】:

我有一个 jenkins 管道,我正在执行存储在 Gitlab 中的云形成模板。但是我的 cloudformation 模板包含一个图像参数,我需要从 jenkins 文件中动态传递。任何人都可以帮助我如何做同样的事情。我用粗体突出显示它。

容器定义“:[ { "图片":"amazon/amazon-ecs-sample", ],

【问题讨论】:

    标签: amazon-web-services jenkins amazon-cloudformation amazon-ecs


    【解决方案1】:

    为此,您需要将 Image 值作为传递到 CloudFormation 堆栈的参数。

    在您的 CloudFormation 堆栈中创建一个名为“Image”的参数,如下所示

    "Parameters": {
      "Image": {
        "Type": String,
        "Description": "The image name to use within the container definition"
      }
    }
    

    然后在您的代码中,您可以使用Container Definition 中的Ref intrinsic function 引用它,如下所示

    ContainerDefinitions" : [ { "Image": { "Ref": "Image" }, ]
    

    当您使用 CLI 创建堆栈时,您会像下面这样创建堆栈

    aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters ParameterKey=Image,ParameterValue=amazon/amazon-ecs-sample
    

    如果您在 Jenkins 流水线中使用参数,您可以像下面这样替换图像名称

    aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters ParameterKey=Image,ParameterValue=${env.Image}
    

    【讨论】:

      猜你喜欢
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 2014-05-20
      相关资源
      最近更新 更多