Skip to content

Instantly share code, notes, and snippets.

@brianoflan
brianoflan / Jenkinsfile.get_keys
Last active June 19, 2017 17:37
Get a map's keys in a Jenkinsfile's Groovy sandbox
@NonCPS
def getKeys(map) {
def keylist = []
for (def entry in map) {
// For converting map into list:
// // keylist.add(new java.util.AbstractMap.SimpleImmutableEntry(entry.key, entry.value))
keylist.add(entry.key)
}
keylist
@brianoflan
brianoflan / lightsail_wordpress.sh
Last active March 15, 2017 04:56
For hastily installing WordPress on a LightSail instance
#!/bin/bash
fix() {
export lightsail_wordpress_fix=true ;
check ;
exit 0 ;
}
check() {
export checks_failed=0 ;
[[ $DEBUGN -lt 2 ]] || set -x ;
@brianoflan
brianoflan / say_and_do.sh
Created March 6, 2017 17:50
a verbose execute() kind of script
#!/bin/bash
say_and_do() {
echo "$@" 1>&2 ;
"$@" ;
local e=$? ;
echo "Exit code = $e" 1>&2 ;
echo ;
return $e ;
}
@brianoflan
brianoflan / some_functions.sh
Created March 2, 2017 19:58
Functions including debug_ruby()
#!/bin/bash
debug_linux() {
local this=debug_linux
local label=$1 ;
[[ $label ]] || label=0 ;
local outputfile=$2 ;
[[ $outputfile ]] || outputfile=$this.$label.txt ;
{
echo $this ;
@brianoflan
brianoflan / Jenkinsfile
Last active November 14, 2018 21:38
Exhaustive Jenkinsfile
#!/usr/bin/env groovy
CLEAN = true
DEBUG = 2
OVERALL_TIMEOUT = 1 // minutes
email_to = '[email protected], [email protected], '
git_creds = 'general-deploy-key-1'
git_url = '[email protected]:someNamespace/someProject.git'
branch = ''
default_branch = 'master' // Ignored if Jenkinsfile is pulled from SCM - in favor of that Jenkinsfile's SCM branch.
@brianoflan
brianoflan / Jenkinsfile.snippet1
Created February 10, 2017 21:06
Jenkinsfile / Pipeline DSL Groovy check if string is null or empty
def isStringBlankOrNull(s) {
if ( s == null ) {
return true
} else if ( 0 == s.compareTo("") ) {
return true
}
return false
}
#!/bin/bash
pre() {
local f=$1 ;
mkdir test_$f &> /dev/null ;
ln -s ../functions.sh test_$f/functions.sh ;
cat bash_script.sh.pre > test_$f/bash_script.sh
echo "$MAIN" >> test_$f/bash_script.sh ;
cat bash_script.sh.post >> test_$f/bash_script.sh
}
@brianoflan
brianoflan / BASH_script_alt3.sh
Last active January 23, 2017 23:58
basic BASH template (execute, vexecute, die)
#!/bin/bash
cat > functions.sh <<'EOF'
#!/bin/bash
die() {
local exit=$2 ;
echo "$exit" | egrep '^[0-9][0-9]*$' &> /dev/null || exit=1 ;
echo "$1" ;
exit $exit ;
@brianoflan
brianoflan / wget_curl_file.sh
Last active January 29, 2018 19:25
Get a file from an URL (wget, curl)
#!/bin/bash
wget_curl_file() { # Args: from_URL, to_file. Optional arg: Log.
local log='' ;
log=$3 ;
[[ $log ]] || log=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ;
{ wget -qO $2 $1 2>$log || curl -s $1 > $2 ; } &> $log ;
local e=$?
[[ $e -eq 0 ]] || {
echo "ERROR: $e from wget or curl:" 1>&2