Skip to content

Instantly share code, notes, and snippets.

View pavelzag's full-sized avatar
💭
Eat Code Sleep

Pavel Zagalsky pavelzag

💭
Eat Code Sleep
View GitHub Profile
from configuration import get_config
from json import dumps
from flask import Flask, request, Response
import jenkins as jenkins_python_module
JENKINS_URL = get_config("jenkins_url")
JENKINS_JOB_NAME = get_config("jenkins_job_name")
JENKINS_USER = get_config("jenkins_user")
JENKINS_PASSWORD = get_config("jenkins_password")
import os
import yaml
def get_config(parameter_name):
home = os.getcwd()
config_file_path = os.path.join(home, 'app_config.yml')
with open(config_file_path, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
return cfg[parameter_name]
jenkins_url: http://<jenkins_ip>:<jenkins_port>
jenkins_user: <api_user>
jenkins_password: <app_password>
jenkins_job_name: chrome_extension_job
def get_language(city_name):
if city_name == 'New York City' or city_name == 'London':
return 'English'
elif city_name == 'Amsterdam':
return 'Dutch'
elif city_name == 'Berlin':
return 'German'
elif city_name == 'Tel Aviv':
return 'Hebrew'
else:
@app.route('/trigger_jenkins_job', methods=['POST'])
def trigger_jenkins_job():
content = request.get_json()
city_name = content['city_name']
country_language = get_language(city_name)
country_name = get_country(city_name)
result = server.build_job(name=JENKINS_JOB_NAME, parameters={'CITY_NAME': city_name,
'COUNTRY_NAME': country_name,
'COUNTRY_LANGUAGE': country_language})
if result:
certifi==2019.6.16
chardet==3.0.4
Click==7.0
Flask==1.1.1
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
multi-key-dict==2.0.3
pbr==5.4.3
<!doctype html>
<html>
<head>
</head>
<body>
<center>
<h4>Select a city</h4>
</center>
<center>
<select name="City Name" id="city">
{
"manifest_version": 2,
"name": "JenkinsTriggerExtension",
"description": "Just a Jenkins triggering extension",
"version": "1",
"author": "Pavel Zagalsky",
"browser_action": {
"default_icon": "chrome.png",
"default_title": "Select a city",
"default_popup": "popup.html"
$(document).ready(function() {
$("button").click(function() {
var xhr = new XMLHttpRequest();
var url = "http://localhost:8081/trigger_jenkins_job";
var selectedCity = $('#city').val();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);