Use the same (repeated) code in all my jenkins files

Okay - by the code below, I’m not a pro. :slight_smile: I’m using Jenkins as a “Command and Control” Application bounce, health check…etc.

all of my jobs have the exact same code before the actual pipeline runs. I have dicked around with shred libraries but not luck. Is there a way that I can use the code below in all my files without having to copy and paste…etc?

START of Jenkins.groovy

def loadEnvironmentVariables(path){
    def props = readProperties  file: path
    keys= props.keySet()
    for(key in keys) {
        value = props["${key}"]
        env."${key}" = "${value}"

node {
env.HOSTpr = Jenkins.getInstance().getComputer('').getHostName().substring(0,7)
HOSTpr = Jenkins.getInstance().getComputer('').getHostName().substring(0,7)
// Let's define some stuff specific to this job
fieldList = env.JOB_NAME.split('~')
fldcnt =  fieldList.length
println fldcnt
def push_env_params = ''
if (env.HOSTpr.startsWith('m4s')) {
push_env_params = choice(choices: ['Please Choose an Environment', 'm4s-a0-','m4s-a1-','m4s-a2-','m4s-ap1-','m4s-ci1-','m4s-ci2-','m4s-ci3-','m4s-ci4-','m4s-d0-','m4s-d1-','m4s-d101-','m4s-d16-','m4s-d171-','m4s-d18-','m4s-d19-','m4s-d2-','m4s-d23-','m4s-d24-','m4s-d27-','m4s-d3-','m4s-d35-','m4s-d4-','m4s-d45-','m4s-d5-','m4s-d507-','m4s-d510-','m4s-d530-','m4s-d6-','m4s-d7-','m4s-d73-','m4s-d74-','m4s-d9-','m4s-dm-','m4s-dm1-','m4s-dv-','m4s-dv5-','m4s-ft-','m4s-ft1-','m4s-i1-','m4s-i3-','m4s-lab1-','m4s-lab2-','m4s-lt-','m4s-lt1-','m4s-np-','m4s-np19-','m4s-np5-','m4s-np9-','m4s-p1-','m4s-p2-','m4s-p3-','m4s-pm1-','m4s-poc-','m4s-pr-','m4s-ps1-','m4s-pt-','m4s-pt1-','m4s-q1-','m4s-q2-','m4s-q26-','m4s-q3-','m4s-q30-','m4s-q4-','m4s-q41-','m4s-q5-','m4s-q6-','m4s-q8-','m4s-qa-','m4s-rt1-','m4s-rt2-','m4s-s1-','m4s-s2-','m4s-s3-','m4s-s4-','m4s-s9-','m4s-sb-','m4s-sb1-','m4s-sb2-','m4s-sb3-','m4s-sb4-','m4s-sp1-','m4s-t1-','m4s-tp1-','m4s-tp2-','m4s-u1-','m4s-u2-','m4s-u3-','m4s-u4-'], description: 'Please Choose the environment you wish to use.',name: 'ENVIRONMENT')
} else {
    push_env_params = [$class: 'WHideParameterDefinition', defaultValue: '', description: '"${HOSTpr}"', name: 'ENVIRONMENT']

if ("${PROCESS}" == "Please Choose a Process") {
    error("YOU DID NOT CHOOSE A PROCESS.  Failing this job.  Please rerun the job again but choose a PROCESS option from the drop down list.")
} else {
    HANDOVER = "baton"
if ("${HANDOVER}" == "baton") {
    println("We have the key. Safety override enabled.")
} else {
    if ("${PROCESS}" != "STATUS") {
        stage("ABORT or PROCEED..You are about to perform a ${PROCESS} command. Are you sure you want to Proceed?") { input "ABORT or PROCEED?" }
        push_status_fail_params = emailext body: '${JELLY_SCRIPT,template="groovy-html"}', to: '', subject: 'Build ${JOB_NAME}', mimeType: 'text/html'
    } else {
        push_status_fail_params = echo 'FAILED: This job failed.  Sending an email.'