Unable to pip install Docker image as proxy via Jenkins declarative pipeline


Casper Press:

I again had a docker permissions issue running through the Jenkins declaration pipeline. I want to build and publish a Python package via a Jenkins job in a Docker container:

pipeline {

  agent {
    docker {
      image 'python:3.7'
      label 'docker && linux'
    }
  }

  environment {
    PACKAGE_VERSION = readFile 'VERSION'
  }

  stages {

    stage('Package') {
      steps {
        sh 'python -V'
        sh 'python -m pip install -r requirements.txt --user --no-cache'
        sh 'python setup.py sdist'
      }
    }

    stage('Deploy') {
      steps {
        ...
      }
    }

  }

  post {
    always {
      cleanWs()
    }
  }

}

However, I am not allowed pip installdue to PermissionError:

+ python -m pip install -r requirements.txt --user --no-cache requirements already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from -r requirements.txt (page 1) line)) (40.0.0) collect pytest (from -r requirements.txt (line 2))
download https://files.pythonhosted.org/packages/9e/a1/8166a56ce9d89fdd9efcae5601e71758029d90e5644e0b7b6eda07e67c35/pytest-3.7.0-py2. py3-none -any.whl (202kB) collect py >= 1.5.0 (from pytest->-r requirements.txt (line 2)) download https://files.pythonhosted.org/packages/f3/bd/ 83369ff2dee18f22f27d16b78dd651e8939825af5f8b0b83c38729029069962/py-1.5.4-py2.py3-none-any.whl (83kB) collect more-itertools >= 4.0.0 (from pytest->-r requirements.txt (line 2)) download https:// files.pythonhosted.org/packages/79/b1/eace304ef66bd7d3d8b2f78cc374b73ca03bc53664d78151e9df3b3996cc/more_itertools-4.3.0-py3-none-any.whl (48kB) collection issue >= 0.7 (from pytest->-r line 2)) download https://files.pythonhosted.org/packages/f5/f1/5a93c118663896d83f7bcbfb7f657ce1d0c0d617e6b4a443a53abcc658ca/pluggy-0.7.1-py2.py3-none-any .whl gather six >= 1.10.0 (from pytest--r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0 -py2.py3-none-any.whl collect atomic writes >= 1.0 (from pytest->-r requirements.txt (line 2)) download https://files.pythonhosted.org/packages/0a/e8/ cd6375e7a59664eeea9e1c77a766eeac0fc3083bb958c2b41ec46b95f29c/atomicwrites-1.1.5-py2.py3-none-any.whl collection properties >= 17.4.0 (from pytest->-r. (line 2)
download )https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl install collected packages: py, six, more itertools, pluggy, atomicwrites, attrs, pytest

Unable to install package due to environment error: [Errno 13] Permission denied: Check permissions for '/.local'.

How to resolve these permissions?

Casper Press:

I found myself what I think is a prettier solution:

stage("Python Test") {
  agent { 
    docker {
      label "docker && linux" 
      image "python:3.7"
    }
  }
  steps {
    withEnv(["HOME=${env.WORKSPACE}"]) {
      sh "pip install -r requirements.txt --user"
      # python stuff
    }
  }
  post {
    cleanup {
      cleanWs()
    }
  }
}

This workaround completely solves the problem itself and installs the package at the user level. The problem here is that the HOME directory is also not writable initially, so the HOME directory is overwritten.

Related


Jenkins Declarative Pipeline Docker Registry

Beriato How do I setup the pipeline so that Docker pulls images from the local registry? Beriato Found in a user mailing list post , but I don't see it in the official documentation. For posterity, here is the linked answer agent { docker { image "image

Jenkins Declarative Pipeline Docker Registry

Beriato How do I setup the pipeline so that Docker pulls images from the local registry? Beriato Found in a user mailing list post , but I don't see it in the official documentation. For posterity, here is the linked answer agent { docker { image "image

Jenkins Declarative Pipeline Docker Registry

Beriato How do I setup the pipeline so that Docker pulls images from the local registry? Beriato Found in a user mailing list post , but I don't see it in the official documentation. For posterity, here is the linked answer agent { docker { image "image

Delete docker container with image name via jenkins pipeline

Mohan Cons I redeploy the docker container whenever gitlab is triggered via the jenkins pipeline. So I can't delete the docker container with the image name. I follow the following commands: sh 'docker ps -f name=imagename -q | xargs --no-run-if-empty docker c

Increment Maven version via jenkins declarative pipeline

dane_griffiths I'm trying to increase my pom version via Jenkins, but I'm facing a number of issues with the script element of the Jenkins declarative pipeline. my goal is: Jenkins pulls code from SCM Run the Maven plugin Incremental version of the app in the

Jenkins Declarative Pipeline Docker Registry

Beriato How do I setup the pipeline so that Docker pulls images from the local registry? Beriato Found in a user mailing list post , but I don't see it in the official documentation. For posterity, here is the linked answer agent { docker { image "image

Jenkins Declarative Pipeline Docker Registry

Beriato How do I setup the pipeline so that Docker pulls images from the local registry? Beriato Found in a user mailing list post , but I don't see it in the official documentation. For posterity, here is the linked answer agent { docker { image "image

Delete docker container with image name via jenkins pipeline

Mohan Cons I redeploy the docker container whenever gitlab is triggered via the jenkins pipeline. So I can't delete the docker container with the image name. I follow the following commands: sh 'docker ps -f name=imagename -q | xargs --no-run-if-empty docker c