Skip to content

Instantly share code, notes, and snippets.

View wmclifford's full-sized avatar

William M. Clifford wmclifford

View GitHub Profile
@wmclifford
wmclifford / attributeParser.cpp
Created November 27, 2021 06:35
HackerRank: attribute parser (c++)
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
#include <regex>
#include <map>
#include <vector>
#include <iterator>
@wmclifford
wmclifford / jenkinsSendSlackMessage.groovy
Created November 9, 2021 02:51
Send Slack message from Jenkins Groovy script (non-pipeline)
// Hopefully, this is useful to someone else. Using the Slack Notification plugin it is trivially
// easy to send a Slack message from within a build pipeline. What may not be so easy is to send
// one from within a Groovy script build step inside a freestyle build, or from within another
// plugin. Personally, I hate having to reinvent the wheel, especially where making HTTP requests
// is concerned. So how do we leverage the Slack plugin for this scenario? Read on ...
// This is the main thing we need - the `StandardSlackService` class, exposed by the Slack
// Notification plugin.
import jenkins.plugins.slack.StandardSlackService
@wmclifford
wmclifford / jenkinsGetCredential.groovy
Last active November 9, 2021 02:28
Lookup a Jenkins credential - simple case
// This is a simple usage case for retrieving a "secret text" or "token" credential
// from the global Jenkins credentials, and, if found, making it available as
// cleartext for use within a Groovy script or within a plugin. Obviously, this
// should NOT BE USED for mischevous purposes ...
import com.cloudbees.plugins.credentials.SystemCredentialsProvider
import hudson.util.Secret
def allCredentials = SystemCredentialsProvider.instance.credentials
@wmclifford
wmclifford / jenkinsFreestyleGetEnv.groovy
Created November 9, 2021 01:53
Get environment inside "System Groovy script" in Jenkins freestyle build
// Cannot use System.getenv(keyName) nor System.getenv(). These do not include all of the build
// parameters, nor do they include Jenkins-specific environment values. The following will give
// access to all of that data, plus the system environment variables:
// Get access to the script binding context
def binding = this.getProperty('binding')
// Get the executing build
def build = binding.getVariable('build')
@wmclifford
wmclifford / sample_array_processing_bash.sh
Last active December 16, 2015 15:09
Example of processing an array of items in a Bash script. Assumes that the array has no "holes", that is, no undefined elements - that it is contiguous.
#!/bin/sh
function do_something {
local my_arg=$1
# do something here ...
}
# Iterate over array of values, processing each in turn.
# Assumes that there are no holes in the array (no unassigned
# elements).