Skip to content

Instantly share code, notes, and snippets.

@XuefengWu
Created January 23, 2017 03:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save XuefengWu/843eb516f0395f8e8e419c134b7058d5 to your computer and use it in GitHub Desktop.
Save XuefengWu/843eb516f0395f8e8e419c134b7058d5 to your computer and use it in GitHub Desktop.
download jenkins plugin and dependencies offline for the internal jenkins server cannot access internet.
#!/usr/bin/python
import sys
import zipfile
import urllib
def download_plugin(name,version):
pluginUrl = "http://updates.jenkins-ci.org/download/plugins/%s/%s/%s.hpi" % (name,version,name)
print "downloading: %s" % pluginUrl
file = "%s.hpi" % name
urllib.urlretrieve (pluginUrl, file)
download_dependencies(file)
def download_dependencies(file):
z = zipfile.ZipFile(file, "r")
manifestPath = "META-INF/MANIFEST.MF"
bytes = z.read(manifestPath)
dependencies = [x for x in bytes.decode("utf-8").split("\n") if "Dependencies" in x]
for dep in dependencies:
_dep = dep.strip()
_deps = _dep.split(":")
print _deps
name = _deps[1].strip()
version = _deps[2].strip()
download_plugin(name,version)
#download_plugin("junit","1.19")
if __name__ == "__main__":
if len(sys.argv) < 3:
print "usage sample: python download_jenkins_plugins.py junit 1.19"
sys.exit(1)
name = sys.argv[1]
version = sys.argv[2]
print "download %s %s" % (name,version)
download_plugin(name,version)
@Lyr
Copy link

Lyr commented Nov 8, 2018

Line 18 create some issue sometimes caused by the fact that some line are too long to be totally catch by this mechanism

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment