CONTROLLED DATA
Leidos Proprietary - US Citizens ONLY
The information contained herein is proprietary to Leidos, Inc. It may not be used, reproduced, disclosed, or exported without the written approval of Leidos.
Using pip to install Python packages through Artifactory requires basic authentication. See the following Jenkins pipeline examples.
Step-by-step guide
This example shows how to construct a URL in the format https://<USERNAME>:<PASSWORD>@host:port/artifactory/api/pypi/<PYPI_REPO>/simple and using it with pip to install 'setuptools'.
pipeline { agent none stages { stage('Do some Python3 stuff') { agent { node { // The node must be 'jenkins-tools-python3'. label 'jenkins-tools-python3' } } steps { // The name of the container must be 'python3'. container('python3') { withCredentials([usernamePassword(credentialsId: "srvc-sdop-docker", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { script { artifactoryHost = "artifactory.sdo.leidos.com" urlTemplate = "https://%1s:%2s@%3s/artifactory/api/pypi/sdo-pypi/simple" pipIndexUrl = java.lang.String.format(urlTemplate, "${USERNAME}", "${PASSWORD}", artifactoryHost) sh "pip3 -vvv --trusted-host $artifactoryHost install setuptools -i $pipIndexUrl" } } sh 'python3 --version' } } } } }
This example shows how to construct a URL in the format https://<USERNAME>:<PASSWORD>@host:port/artifactory/api/pypi/<PYPI_REPO>/simple and using it with pip to install 'setuptools'. Note in this example the URL encoding of the username and password. This is necessary when usernames or passwords contain special characters. However, this may not always work reliably. In this case, it is recommended to use the encrypted password that is provided by Artifactory and to then use the above example.
pipeline { agent none stages { stage('Do some Python3 stuff') { agent { node { // The name of the node must be 'jenkins-tools-python3'. label 'jenkins-tools-python3' } } steps { // The name of the container must be 'python3'. container('python3') { withCredentials([usernamePassword(credentialsId: "srvc-sdod-docker", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { script { artifactoryHost = "artifactory.sdodev.leidos.com" urlTemplate = "https://%1s:%2s@%3s/artifactory/api/pypi/sdo-pypi/simple" username = java.net.URLEncoder.encode("${USERNAME}", "UTF-8") password = java.net.URLEncoder.encode("${PASSWORD}", "UTF-8") pipIndexUrl = java.lang.String.format(urlTemplate, username, password, artifactoryHost) sh "pip3 -vvv --trusted-host $artifactoryHost install setuptools -i $pipIndexUrl" } } } } } } }