#How can I run conditional steps based on the exit code of a prior command?

1 messages ยท Page 1 of 1 (latest)

wheat grotto
#

For instance if I run aws sts get-caller-identity it will return a non-zero exit code if the credentials have expired.

Therefore if exit code is non-zero I want to run a conditional step to refresh the token.

left solar
#

that does exactly what you want. then you can access exitCode

wheat grotto
#

๐Ÿ‘

#
process "aws sts get-caller-identity" did not complete successfully: exit code: 254
#

I've set it to ReturnType.ANY but it still fails

#

Because ReturnType.ANY only allows exit codes 0-127?

#
โ”‚ โœ” .withEnvVariable(name: "AWS_PROFILE", value: "test"): Container! 0.0s
โ”‚ โœ” .withEnvVariable(name: "CACHEBUSTER", value: "1743770462890"): Container! 0.0s
โ”‚ โœ˜ .withExec(args: ["aws", "sts", "get-caller-identity"], expect: ANY): Container! 3.3s
โ”‚ โ”ƒ                                                                                                                                                            
โ”‚ โ”ƒ An error occurred (ExpiredToken) when calling the GetCallerIdentity operation: The security token included in the request is expired                       
โ”‚ ! process "aws sts get-caller-identity" did not complete successfully: exit code: 254
#
โ”‚ โœ” .withMountedCache(
โ”‚ โ”‚ โ”‚ cache: โœ” cacheVolume(key: "aws"): CacheVolume! 0.0s
โ”‚ โ”‚ โ”‚ path: "/root/.aws"
โ”‚ โ”‚ ): Container! 0.0s
โ”‚ โœ” .withEnvVariable(name: "AWS_PROFILE", value: "test"): Container! 0.0s
โ”‚ โœ” .withEnvVariable(name: "CACHEBUSTER", value: "1743770783486"): Container! 0.0s
โ”‚ โœ” .withExec(args: ["exit", "1"], expect: ANY): Container! 0.3s
โ”‚ โœ” .withExec(args: ["exit", "127"], expect: ANY): Container! 0.2s
โ”‚ โœ” .withExec(args: ["exit", "254"], expect: ANY): Container! 0.2s
โ”‚ โœ˜ .withExec(args: ["aws", "sts", "get-caller-identity"], expect: ANY): Container! 3.2s
โ”‚ โ”ƒ                                                                                                                                                            
โ”‚ โ”ƒ An error occurred (ExpiredToken) when calling the GetCallerIdentity operation: The security token included in the request is expired                       
โ”‚ ! process "aws sts get-caller-identity" did not complete successfully: exit code: 254
left solar
#

oh god I think I remember hitting this...