Skip to content

Instantly share code, notes, and snippets.

@Alxkkor
Created May 17, 2017 11:54
Show Gist options
  • Save Alxkkor/0882542c79d4ea5b373d5ebbe9eeea04 to your computer and use it in GitHub Desktop.
Save Alxkkor/0882542c79d4ea5b373d5ebbe9eeea04 to your computer and use it in GitHub Desktop.
except ImportError:
sys.stderr.write("\nError: please install python requests module first: http://www.python-requests.org/\n")
from requests.auth import HTTPBasicAuth
from string import Template
import getpass
import json
currenttime = time.asctime(time.localtime())
urllib3.disable_warnings()
LARRY_TOKEN = "a2310b1f6b7d584495ebbf9b347244e9fee"
TEMPLATE_FILE = "plugin_usage_template.html"
DETAIL_TEMPLATE_FILE = "detail_plugin_jobs_template.html"
INDEX_HTML = "index.html"
DETAIL_DIR = "detail"
SHALL_DETAIL = True
LIMIT_JOBS = 20
SYSTEM_VIEW_CFG = "views.config_xml"
prop = {
"user" : "larry", # will set to current user as default
"token" : LARRY_TOKEN,
"dir" : "jenkinsBackup",
"config" : "jenkins.cfg",
"passwd" : False,
"url" : "https://jenkins-server/",
}
def withoutPort(url):
return re.sub(r'\:\d+([^\d]|$)', r'\1', url, count=1)
def get_job_config(url,name):
config_url = "%s/job/%s/config.xml" % (url,name)
#with vcr.use_cassette('fixtures/debug3.yaml'):
# j = jenkins.Jenkins(url, 'rdccaiy', 'a231094d044ca829d367f35829085036')
r = requests.get(config_url,verify=False,auth=HTTPBasicAuth(prop["user"], prop["token"]))
if r.ok:
return r.text
else:
raise Exception("can't fetch data from %s using user: %s, token: %s" % (config_url,prop["user"], prop["token"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment