#How can I run conditional steps based on the exit code of a prior command?
1 messages ยท Page 1 of 1 (latest)
I've tried using this approach but it seems that as soon as the withExec command produces a non-zero exit code it crashes and doesn't proceed.
https://docs.dagger.io/cookbook/#continue-using-a-container-after-command-execution-fails
there is an optional expect argument to withExec
that does exactly what you want. then you can access exitCode
How can I see that argument from the API docs?
https://docs.dagger.io/api/types/#container
I found a more detailed one.
https://docs.dagger.io/api/reference/
๐
process "aws sts get-caller-identity" did not complete successfully: exit code: 254
expect is supposed to be of type ReturnType
https://docs.dagger.io/api/reference/#definition-ReturnType
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
oh god I think I remember hitting this...