Code Pipeline: The image URI contains invalid characters

0

Hi everyone

I have Buildspec in CodeBuild like this:

version: 0.2

phases:
  post_build:
    commands:
      - echo '[{ "imageUri":"$IMAGE_URI" , "name":"$CONTAINER_NAME"   }]' > imagedefinitions.json

artifacts:
  files: 
    - imagedefinitions.json

When I set IMAGE_URI variable in Codepipeline this give me error "The image URI contains invalid characters" in Deploy process

My IMAGE_URI example: ****.dkr.ecr.ap-southeast-1.amazonaws.com/demo-ecr:pythonapp

How can I fix this ?

Thanks

Nam
已提問 4 個月前檢視次數 230 次
2 個答案
1
已接受的答案

I have fixed this by change single quote to double quote: echo "[{\ "name\ ":\ "$CONTAINER_NAME\ ",\ "imageUri\ ":\ "$IMAGE_URI\ "}]" > imagedefinitions.json

  • Each " inside "" add \ before example: \ " (no space because comment not show \ before " so I add space)
Nam
已回答 4 個月前
1

Hi, to better investigate the issue I would recommend to add a command into your post_build step in order to show the content to the "imagedefinitions.json" file to double check if the interpolation of the variable actually works correctly.

version: 0.2

phases:
  post_build:
    commands:
      - echo '[{ "imageUri":"$IMAGE_URI" , "name":"$CONTAINER_NAME"   }]' > imagedefinitions.json
      - cat imagedefinitions.json

artifacts:
  files: 
    - imagedefinitions.json
AWS
已回答 4 個月前
  • Thanks for comment. I fixed by change ' to " in echo. I worked

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南