18

I am running a jenkins pipeline with the following command:

kubectl exec -it kafkacat-5f8fcfcc57-2txhc -- kafkacat -b cord-kafka -C -t BBSim-OLT-0-Events -o s@1585031458

which is running fine on the terminal of the machine the pipeline is running on, but on the actual pipeline I get the following error: "Unable to use a TTY - input is not a terminal or the right kind of file"

Any tips on how to go about resolving this?

Shrey Baid
  • 223
  • 1
  • 2
  • 9

5 Answers5

21

For Windows GitBash users, use Powershell and NOT GitBash

Ryan Augustine
  • 1,237
  • 15
  • 13
  • 4
    Is there any possibility to configure GitBash to act like Powershell does? Thank you. – Marco Aug 07 '20 at 15:58
  • See answer below for doing this with gitbash https://stackoverflow.com/a/68163722/131391 – aland Apr 07 '22 at 20:40
18

When the flags -it are used with kubectl exec, it enables the TTY interactive mode. Given the error that you mentioned, it seems that Jenkins doesn't allocate a TTY.

Since you are running the command in a Jenkins job, I would assume that your command is not necessarily interactive. A possible solution for the problem would be to simply remove the -t flag and try to execute the following instead:

kubectl exec -i kafkacat-5f8fcfcc57-2txhc -- kafkacat -b cord-kafka -C -t BBSim-OLT-0-Events -o s@1585031458
foo0x29a
  • 586
  • 4
  • 6
11

For windows git bash:

alias kubectl='winpty kubectl'
$ kubectl exec -it <container>

Or just use winpty before the desired command.

4F2E4A2E
  • 1,526
  • 21
  • 28
5

Remove the -t option. That requests a TTY, which as you noted does not exist in Jenkins.

coderanger
  • 49,695
  • 4
  • 45
  • 66
  • 1
    -i still fails, see here: kubectl exec --namespace default -i svc/jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password && echo OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "C:/Program Files/Git/usr/bin/cat": stat C:/Program Files/Git/usr/bin/cat: no such file or directory: unknown command terminated with exit code 126 – joe hoeller Dec 29 '20 at 18:15
1

Just a hint for anyone that gets stuck like I did with kafkacat suddenly returning no data after removing the -t.

Turns out if there's no tty then kafkacat defaults to Producer mode, I never used the -C flag because it's the default to be a Consumer, but in this case it's required.

Clarence Liu
  • 3,806
  • 2
  • 24
  • 29