Skip to content

Instantly share code, notes, and snippets.

View mig82's full-sized avatar
🏠
Working from home

Miguelángel Fernández mig82

🏠
Working from home
View GitHub Profile
@mig82
mig82 / parseJson.groovy
Created August 17, 2017 13:45
How to parse json into a serializable HashMap in Jenkins Groovy
@NonCPS
def parseJson(txt){
def lazyMap = new groovy.json.JsonSlurper().parseText(txt)
def map = [:]
for ( prop in lazyMap ) {
map[prop.key] = prop.value
}
return map;
}
@mig82
mig82 / install_zipalign.sh
Last active October 20, 2018 00:01
A bash script to install Android's zipalign in Jenkins as a Global Tool
printf "\nInstalling Android SDK as a Jenkins Custom Tool\n"
printf "WARNING: Remember that to run Android SDK tools you must first add support for 32 bit binaries to your slave -e.g. For AWS Linux \n\t yum install glibc.i686 \n\t yum install libzip.i686 \n\n"
pwd
ls -la
if [ ! -d build-tools ];
then
printf "There's no dir by the name 'build-tools' on this agent yet. Will proceed to install the Android SDK.\n"
@mig82
mig82 / get-google-calendar-event-url
Created June 26, 2017 13:17
Get a shareable link of a Google calendar from its Edit Details screen.
(function() {
try {
window.prompt('Shareable link to this event:', 'https://www.google.com/calendar/event?eid=' + document.getElementsByClassName('ep')[0].getAttribute('data-eid'))
} catch (e) {
alert("Use this bookmarklet to get a shareable link to a Google Calendar event when editing its Details page.")
}
})()
@mig82
mig82 / write-properties-file.groovy
Created June 12, 2017 17:16
Creates a Visualiser headless build properties file.
dir(visualizerWorkspace){
bat("rm HeadlessBuild-Global.properties")
writeFile(
file: 'HeadlessBuild-Global.properties',
text: '''
workspace.location=c:/Jenkins/workspace/AFS-2.0/android-native-build/vis-workspaces/work-DigitalOperator
eclipse.equinox.path=C:/KonyVisualizerEnterprise7.3.0/Kony_Visualizer_Enterprise/plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
@mig82
mig82 / git-clone-into-subdir.groovy
Created June 2, 2017 13:28
Clone a git repo into a specific subdir.
checkout([
$class: 'GitSCM',
branches: [
[name: '*/branchname']
],
doGenerateSubmoduleConfigurations: false,
extensions: [
[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'MyDirectory'
@mig82
mig82 / jobA.groovy
Last active May 31, 2017 17:42
A Jenkins job that passes a user and password and a secret file to another job
properties([
parameters([
[
$class: 'CredentialsParameterDefinition',
name: 'GIT_CREDENTIALS',
credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: params.GIT_CREDENTIALS?params.GIT_CREDENTIALS:'',
description: 'Credentials for Github.',
required: true
],
@mig82
mig82 / ShellStepWithOutput.groovy
Last active September 1, 2017 13:00
A Groovy library that can be used in a Jenkinsfile to call a shell command and retrieve the output from it.
import java.util.UUID
def command(command) {
def uuid = UUID.randomUUID()
def filename = "cmd-${uuid}"
echo(filename)
def cmd = "${command} > ${filename}"
isUnix()?sh(cmd):bat(cmd)
def result = readFile(filename).trim()
isUnix()?sh("rm ${filename}"):bat("del ${filename}")