pelos
pelos

Reputation: 1876

cant docker build with pip install from jenkins pipeline

i am building a docker image, that will run a flask application. when i do it locally with no problem i can build the image

my dockerfile:

FROM python:3.7
#RUN apt-get update -y

WORKDIR /app
RUN curl www.google.com

COPY requirements.txt requirements.txt
RUN pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt

my jenkinspipeline

pipeline {
    agent {
        label "linux_machine"
    }
    stages {
        stage('Stage1') {
            steps {
                //sh 'docker --version'
                //sh 'python3 --version'
                //sh 'pip3 --version'
                checkout([$class: 'GitSCM', branches: [[name: '*/my_branch']], extensions: [], userRemoteConfigs: [[credentialsId: 'credentials_', url: 'https://myrepo.git']]])                    
            }
        }
        
        stage('Stage2'){
            steps{
                sh "docker build --tag tag1 --file path/to/docker_file_in_repo docker_folder_path"
            }
        }               
    }
}

i was able to install docker and jenkins locally in my machine and all works fine, but when i put it on the jenkins server with real agents i get:

  File "/usr/local/lib/python3.7/site-packages/pip/_internal/network/auth.py", line 256, in handle_401
    username, password, save = self._prompt_for_password(parsed.netloc)
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/network/auth.py", line 226, in _prompt_for_password
    username = ask_input(f"User for {netloc}: ")
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 237, in ask_input
    return input(message)
EOFError: EOF when reading a line
Removed build tracker: '/tmp/pip-req-tracker-i4mhh7vg'
The command '/bin/sh -c pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt' returned a non-zero code: 2

i try using --no-input but same error,

thanks guys.

Upvotes: 1

Views: 850

Answers (1)

sba
sba

Reputation: 2117

Unfortunately, the problem is not clear at all from the message. What happens is that pip gets a 401 Unauthorized from the package index. You have to provide credentials so it can log-in.

You can add --no-input so it doesn't try to ask for a password (where it then fails due to STDIN being unavailable). That doesn't solve the underlying problem of it being unable to connect.

Upvotes: 1

Related Questions