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

How to check if Job succeeded or failed?

Open PedroAlvarado opened this issue 2 years ago • 2 comments

We have a multi-step GitHub action. One of the steps is running a job (“job run”). We’d like to continue to the next GitHub action step only after the job completed successfully.

Is there a recommended(copilot idiomatic) approach to being able to implement such functionality?

Please note that we are using “on.schedule: “none””.

PedroAlvarado avatar May 29 '23 06:05 PedroAlvarado

Hey, this is a great feature request for us. It seems like a natural use case for a job status command. Thanks for surfacing this need so we can prioritize it.

In the meantime, can you work around your problem with these AWS CLI commands?

# Grab the ARN of the state machine some way (you can replace this with a variable, like so:
# STATE_MACHINE_ARN=arn:aws:states:$REGION:$ACCOUNT_ID:stateMachine:$COPILOT_APP-$COPILOT_ENV-$COPILOT_JOB
STATE_MACHINE_ARN=$(aws stepfunctions list-state-machines | jq -r '.stateMachines[].stateMachineArn')

# List the last execution of the state machine and parse its status
STATE_MACHINE_EXIT_CODE=$(aws stepfunctions list-executions --state-machine-arn $ARN --max-results 1 | jq -r '.executions[].status')

You can then do something with the STATE_MACHINE_EXIT_CODE variable.

If you have access to the state machine execution ARN, you can use aws stepfunctions describe-execution instead for similar results.

bvtujo avatar Jun 05 '23 19:06 bvtujo

@PedroAlvarado I came across a similar issue for one of my projects and wanted to know if you found any solution to your issue.

vshah11 avatar Feb 12 '24 20:02 vshah11