Created
February 9, 2017 17:44
-
-
Save BoboTiG/7f60aba441b715413a495f204bffff92 to your computer and use it in GitHub Desktop.
Install a custom version of Python within the Jenkins current WORKSPACE.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: powershell ".\deploy_jenkins_slave_python.ps1" | |
# Stop the execution on the first error | |
$ErrorActionPreference = "Stop" | |
# Ensure we have a working WORKSPACE and a defined Python version | |
if (-Not ($Env:PYTHON_VERSION)) { | |
echo "PYTHON_VERSION not defined. Aborting." | |
exit 1 | |
} elseif (-Not ($Env:WORKSPACE)) { | |
echo "WORKSPACE not defined. Aborting." | |
exit 1 | |
} | |
function download($url, $output) { | |
# Download one file and save its content to a given file name | |
echo ">>> Downloading $url" | |
echo " to $output" | |
$curl = New-Object System.Net.WebClient | |
$curl.DownloadFile($url, $output) | |
} | |
function install_python { | |
$output = "$($Env:WORKSPACE)\python-$($Env:PYTHON_VERSION).msi" | |
$python_dir = "$($Env:WORKSPACE)\python-$($Env:PYTHON_VERSION)" | |
$url = "https://www.python.org/ftp/python/$($Env:PYTHON_VERSION)/python-$($Env:PYTHON_VERSION).msi" | |
echo " PYTHON_VERSION = $Env:PYTHON_VERSION" | |
echo " WORKSPACE = $Env:WORKSPACE" | |
echo " PYTHON_DIR = $PYTHON_DIR" | |
if (-Not (Test-Path $python_dir)) { | |
download $url $output | |
echo ">>> Installing Python" | |
# As the installation write some keys into regedit, we need to uninstall Python before installing a new one. | |
# If we do not do that, the next installation will be incomplete. | |
# BTW this issue will no occur with Python 3. | |
Start-Process msiexec -ArgumentList "/x `"$output`" /passive" -wait | |
Start-Process msiexec -ArgumentList "/i `"$output`" /passive ADDLOCAL=`"pip_feature`" TARGETDIR=`"$python_dir`"" -wait | |
} | |
} | |
install_python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment