Skip to content

Commit

Permalink
Download Jenkins silently and improve plugin downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
lechat committed Jan 25, 2023
1 parent 11954c7 commit 636d2b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion jenkinsapi_tests/systests/get-jenkins-war.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ readonly JENKINS_WAR_URL=$1
readonly JENKINS_PATH=$2
readonly WAR_FILENAME=$3

if [[ $(type -t wget) ]]; then wget -O ${JENKINS_PATH}/${WAR_FILENAME} $JENKINS_WAR_URL
echo "Downloading $JENKINS_WAR_URL to ${JENKINS_PATH}"
if [[ $(type -t wget) ]]; then wget -O ${JENKINS_PATH}/${WAR_FILENAME} -q $JENKINS_WAR_URL
elif [[ $(type -t curl) ]]; then curl -sSL -o ${JENKINS_PATH}/${WAR_FILENAME} $JENKINS_WAR_URL
else
echo "Could not find wget or curl"
exit 1
fi

echo "Jenkins downloaded"
21 changes: 18 additions & 3 deletions jenkinsapi_utils/jenkins_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import tempfile
import posixpath
import requests
from requests.adapters import HTTPAdapter
from urllib3 import Retry
import threading
import subprocess
from pkg_resources import resource_stream
Expand Down Expand Up @@ -151,6 +153,17 @@ def install_plugins(self):
self.install_plugin(url, plugin_dest_dir)

def install_plugin(self, hpi_url, plugin_dest_dir):
sess = requests.Session()
adapter = HTTPAdapter(
max_retries=Retry(
total=5,
backoff_factor=1,
allowed_methods=None
)
)
sess.mount("http://", adapter)
sess.mount("https://", adapter)

path = urlparse(hpi_url).path
filename = posixpath.basename(path)
plugin_orig_dir = os.path.join(self.local_orig_dir, "plugins")
Expand All @@ -166,9 +179,11 @@ def install_plugin(self, hpi_url, plugin_dest_dir):
)
else:
log.info("Downloading %s from %s", filename, hpi_url)
with open(plugin_orig_path, "wb") as hpi:
request = requests.get(hpi_url)
hpi.write(request.content)
with sess.get(hpi_url, stream=True) as hget:
hget.raise_for_status()
with open(plugin_orig_path, "wb") as hpi:
for chunk in hget.iter_content(chunk_size=8192):
hpi.write(chunk)
log.info("Installing %s", filename)
if not shutil.copy(plugin_orig_path, plugin_dest_path):
raise Exception("Cannot copy plugin to %" % plugin_dest_path)
Expand Down

0 comments on commit 636d2b1

Please sign in to comment.