Error “The input device is not a TTY”

后端 未结 11 1204
野的像风
野的像风 2020-11-27 09:20

I am running the following command from my Jenkinsfile. However, I get the error \"The input device is not a TTY\".

docker run -v $PWD:         


        
11条回答
  •  时光取名叫无心
    2020-11-27 09:41

    My Jenkins pipeline step shown below failed with the same error.

           steps {
                echo 'Building ...' 
                sh 'sh ./Tools/build.sh'
            }
    

    In my "build.sh" script file "docker run" command output this error when it was executed by Jenkins job. However it was working OK when the script ran in the shell terminal.The error happened because of -t option passed to docker run command that as I know tries to allocate terminal and fails if there is no terminal to allocate.

    In my case I have changed the script to pass -t option only if a terminal could be detected. Here is the code after changes :

    DOCKER_RUN_OPTIONS="-i --rm"
    
    # Only allocate tty if we detect one
    if [ -t 0 ] && [ -t 1 ]; then
        DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t"
    fi
    
    docker run $DOCKER_RUN_OPTIONS --name my-container-name  my-image-tag
    

提交回复
热议问题