Pass Container image value to AWS cloudformation template dynamically from jenkins Pass Container image value to AWS cloudformation template dynamically from jenkins jenkins jenkins

Pass Container image value to AWS cloudformation template dynamically from jenkins


To do this you would instead need to make the Image value a parameter passed into the CloudFormation stack.

In your CloudFormation stack create a parameter named "Image" such as below

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

Then in your code you can reference it using the Ref intrinsic function within the Container Definition like below

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

When you create the stack using the CLI you would create like this below

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

If you're using a parameter in the Jenkins Pipeline you could replace the image name like the below

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