Skip to content

Instantly share code, notes, and snippets.

View doctor500's full-sized avatar
πŸ”¬
Continuous Learning and Researching

David Layardi doctor500

πŸ”¬
Continuous Learning and Researching
View GitHub Profile
@doctor500
doctor500 / insert-data-to-sheets.gs
Last active July 30, 2021 14:20
Insert data to Google Sheets using Google Apps Script
function insertJenkinsJobList( data_source, sheet_name){
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(sheet_name);
let cell = sheet.getRange('A2');
let rows = [];
ss.setFrozenRows(1);
sheet.getRange('A1:D1').setValues([[
"Name", "View Name", "Url", "Last Run"
]]).setFontStyle('bold')
@doctor500
doctor500 / create-ui-menu.gs
Created July 30, 2021 13:56
Create simple menu in google sheets using google apps script
function addJenkinsMenu() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Jenkins')
.addItem('Get Job list fron Jenkins API', 'myFirstFunction')
.addItem('Get Job that was run last this week', 'mySecondFunction')
.addToUi();
}
@doctor500
doctor500 / jenkins-api-result.json
Created July 20, 2021 15:37
Structure Reference of Jenkins API when retrieve Job list with their all attributes ([*[*]]) - Jenkins Version 2.289.1
{
"_class" : "hudson.model.Hudson",
"jobs" : [
{
"_class" : "org.jenkinsci.plugins.workflow.job.WorkflowJob",
"actions" : [],
"description" : "",
"displayName" : "My Fancy Jenkins Job Here",
"displayNameOrNull" : "My Fancy Jenkins Job Here",
"fullDisplayName" : "My Fancy Jenkins Job Here",
@doctor500
doctor500 / input-box.gs
Created July 20, 2021 09:30
Example of inputBox action in google apps script
var sheet_name = Browser.inputBox('Enter Sheet Destination Name','Leave blank to use default name (JenkinsCI)', Browser.Buttons.OK_CANCEL);
if (sheet_name.match('cancel')){
return SpreadsheetApp.getUi().alert("Operation abort!");
}
sheet_name = sheet_name == '' ? 'JenkinsCI' : sheet_name
@doctor500
doctor500 / jenkins-api.gs
Last active July 31, 2021 06:00
Fetch Job list from Jenkins API in Google Apps Script
function insertJobListToSheet(){
let user_name = "yes_man";
let user_token = "0293kdj2039dk20e9fj203923k90235ck234mlfg";
let url_endpoint = "https://your-lovely-jenkins-url.com/api/json?tree=jobs[fullDisplayName,fullName,url,lastBuild[id,timestamp]]&pretty=true";
let data_source = fetchJenkinsAPI(user_name,user_token, url_endpoint);
insertJenkinsJobList(data_source,"Result")
}
function fetchJenkinsAPI(user_name, user_token, url_endpoint){