copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Report exit code with `copilot svc exec` command

Open noefroidevaux opened this issue 2 years ago • 12 comments

Is there a way to get the exit code from the copilot svc exec command?

Currently, it only reports 0 even it's not the case. The behaviour of ssh command would report 1 in the following case:

> ~/Project copilot svc exec
SERVICE X found in environment Y
Execute `/bin/sh` in container X in task 123.

Starting session with SessionId: ecs-execute-command-456
/app # exit 1

Exiting session with sessionId: ecs-execute-command-456.

> ~/Project echo $?
0

It's maybe linked to https://github.com/aws/session-manager-plugin/issues/59 .

Is it the behaviour wanted for the copilot svc exec command? Is there a workaround to get the exit code?

noefroidevaux avatar Jan 04 '23 12:01 noefroidevaux

@noefroidevaux I agree with your speculation as Copilot internally use ssm plugin to exec into the service. There isn't any workaround that I found at the moment. But I will keep you posted if I find something.

paragbhingre avatar Jan 04 '23 20:01 paragbhingre

Thank you for your message @paragbhingre ! Do you have a way to give higher priority to the https://github.com/aws/session-manager-plugin/issues/59 internally?

My use case is to have a script run in the test_commands of the pipeline manifest:

stages:
  - name: xxx
    test_commands:
      - [...]
      - ./copilot-linux svc exec -c "./test.sh" --yes

But as copilot svc exec doesn't return the exit code of the script, the deployment always success even the script doesn't.

noefroidevaux avatar Jan 05 '23 07:01 noefroidevaux

@noefroidevaux Thank you for explaining your use case. I will definitely try, from my end, to pass this along to the concerned team. 

paragbhingre avatar Jan 06 '23 00:01 paragbhingre

Thank you @paragbhingre !

noefroidevaux avatar Jan 06 '23 07:01 noefroidevaux

@noefroidevaux There is a task exec command as well, which emits exit codes correctly. You can give it a try if it fits your requirements. 

paragbhingre avatar Jan 06 '23 17:01 paragbhingre

@noefroidevaux There is a task exec command as well, which emits exit codes correctly. You can give it a try if it fits your requirements.

I found a workaround with copilot task run, thank you for the suggestion! It takes more time, but it works.

@paragbhingre About the session manager plugin project... it seems without any activity since more than 6 months and issues open without activities. Do you know the status of this project internally? Is it abandoned by AWS? If it's the case, it could be a problem for the Copilot project, no?

noefroidevaux avatar Jan 24 '23 13:01 noefroidevaux

hi @noefroidevaux !

Do you know the status of this project internally? Is it abandoned by AWS? If it's the case, it could be a problem for the Copilot project, no?

The project is actively maintained! The Session Manager plugin is a critical dependency for Amazon ECS (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html) so clients should expect for it to be reliable 😌

efekarakus avatar Jan 24 '23 18:01 efekarakus

The project is actively maintained! The Session Manager plugin is a critical dependency for Amazon ECS (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html) so clients should expect for it to be reliable 😌

@efekarakus Indeed, it's a central project for other projects, that's why I don't understand that there is no activity for more than 6 months on the Session Manager plugin repo 😊 But thank you for the confirmation, it's good to know that it's actively maintained 👍

noefroidevaux avatar Jan 25 '23 08:01 noefroidevaux

This issue is stale because it has been open 60 days with no response activity. Remove the stale label, add a comment, or this will be closed in 14 days.

github-actions[bot] avatar Aug 29 '23 00:08 github-actions[bot]

I'm also struggling with this issue. The copilot task run workaround does not seem to be working for me, as it appears to return the exit code for deploying the task cloudformation stack, and copilot task exec behaves like copilot svc exec.

Any guidance on how to get these exit codes?

a-cid avatar Jan 12 '24 15:01 a-cid

Hello @a-cid. If you plan to use task run in your CICD and wish to block the pipeline when the execution fail, can you try using task run --follow flag?

iamhopaul123 avatar Jan 12 '24 18:01 iamhopaul123

Hi @iamhopaul123, that works! Thanks!

a-cid avatar Jan 12 '24 19:01 a-cid