copilot-cli
copilot-cli copied to clipboard
Report exit code with `copilot svc exec` command
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 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.
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 Thank you for explaining your use case. I will definitely try, from my end, to pass this along to the concerned team.
Thank you @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.
@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?
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 😌
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 👍
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.
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?
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?
Hi @iamhopaul123, that works! Thanks!