Search code examples
amazon-web-servicesgitlabgitlab-ciamazon-ecs

I'm getting "command not found" error after running these commands in GitLab. I used these commands 2 days ago and they worked fine


I was using these commands for my deploy-job the other day and it worked fine. This is a new pipeline for a new project and now these commands aren't working. I'm getting errors in my pipeline after every command saying "command not found". Here's my gitlab-ci file for reference

variables:
  DOCKER_REGISTRY: 775362094965.dkr.ecr.us-west-2.amazonaws.com
  AWS_DEFAULT_REGION: us-west-2
  APP_NAME: flask-app
  DOCKER_HOST: tcp://docker:2375

stages:
  - build
  - deploy

build-job:
  stage: build
  image: 
    name: amazon/aws-cli
    entrypoint: [""]
  services:
    - docker:dind
  before_script:
    - amazon-linux-extras install docker
    - aws --version
    - docker --version
  script:
    - docker build -t $DOCKER_REGISTRY/$APP_NAME:latest . 
    - aws ecr get-login-password | docker login --username AWS --password-stdin $DOCKER_REGISTRY
    - docker push $DOCKER_REGISTRY/$APP_NAME:latest

deploy-job:
  stage: deploy
  script:
    - echo `aws ecs describe-task-definition --task-definition  $CI_AWS_ECS_TASK_DEFINITION --region us-west-2` > input.json
    - echo $(cat input.json | jq '.taskDefinition.containerDefinitions[].image="'$REPOSITORY_URI':'$IMAGE_TAG'"') >  input.json
    - echo $(cat input.json | jq '.taskDefinition') > input.json
    - echo $(cat input.json | jq  'del(.taskDefinitionArn)' | jq 'del(.revision)' | jq 'del(.status)' | jq 'del(.requiresAttributes)' | jq 'del(.compatibilities)' | jq 'del(.registeredAt)' | jq 'del(.registeredBy)') > input.json
    - aws ecs register-task-definition --cli-input-json file://input.json --region us-west-2 
    - revision=$(aws ecs describe-task-definition --task-definition $CI_AWS_ECS_TASK_DEFINITION --region us-west-2 | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/"$//' | cut -d "," -f 1)
    - aws ecs update-service --cluster $CI_AWS_ECS_CLUSTER --service $CI_AWS_ECS_SERVICE  --task-definition $CI_AWS_ECS_TASK_DEFINITION:$revision --region us-west-2

My build-job works fine, I'm just getting "command not found" with my deploy-job.


Solution

  • You need to specify an image outside of the build job or in the deploy job. Right now, you're only specifying an image inside your build-job.