Thank you for you help Craig! I meant to get back earlier today but was busy refactoring code to get that all working. Good news is, that @Field annotation worked really well. I also realized that I hadn't been committing code back to the Jenkins managed repository and it was loading from that managed repository in Jenkins.
I've been maintaining a separate repo in version control and updating it when I want to test it it. I'll have to write some hooks (which I haven't really done before but think it should work) to get that working in an orchestrated manner. On Thursday, February 4, 2016 at 12:48:30 AM UTC-5, Craig Rodrigues wrote: > > I only looked at the pipeline cps-global-lib feature after reading your > e-mail. It is some pretty advanced stuff. :) > > I am not a groovy expert, but I will try to explain to the best of my > understanding and hopefully it will lead you on the right path. > > When you have a Jenkinsfile or some arbitrary myscript.groovy which is > evaluated by the pipeline plugin, at runtime a class is dynamically > generated called *WorkflowScript*. If your script throws an exception > which is not caught, you will see a stacktrace line like: > > at WorkflowScript.run(WorkflowScript:4) > > that gives you a hint that the error occurred on line 4 of your script. > > > WorkflowScript is a derived class of CpsScript ( > https://github.com/jenkinsci/workflow-plugin/blob/master/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java > > ). If you keep looking through the inheritance hierarchy, > you will see that you are dealing with > http://docs.groovy-lang.org/next/html/gapi/groovy/lang/Script.html. > > At this point it is worth reading about Groovy Shell: > > http://www.groovy-lang.org/groovysh.html > > I believe the problem you are hitting with respect to global variables > is the same as this: > > > http://stackoverflow.com/questions/6305910/how-do-i-create-and-access-the-global-variables-in-groovy > > Under the covers, your pipeline script is being converted into > a Java class. As per the stackoverflow recommendation, > you should prefix your "global variables" with @Field. > > So you would do something like this in your globals.groovy file: > > // vars/globals.groovy > > import groovy.transform.Field > > @FieldString beginJobEmailBody = "The ${env.JOB_NAME} has begun" > > @FieldString emailDevOpsTeam = "[email protected]" > > /*** Sends an email to the team to notify of a build has begun*/ > def beginBuildNotificationTestEmail() { //mail body: > "${this.beginJobEmailBody} " + paramMap.STAGE + " " + paramMap.ENVIRONMENT, > //subject: "${this.beginJobEmailSubject}" , //to: "${this.emailDevOpsTeam}" > > echo "beginJobEmailBody: ${beginJobEmailBody}" > echo "emailDevOpsTeam: ${emailDevOpsTeam}" > } > > > and this in your Jenkinsfile > > node { > globals.beginBuildNotificationTestEmail()} > > I'm new to groovy, so if there is a better way to do it, let me know. > However, this example does work. > > -- > Craig > > > > > On Wed, Feb 3, 2016 at 3:45 PM, Tom Kierzkowski <[email protected] > <javascript:>> wrote: > > I'm wondering how to declare these properly within the globals.groovy >> script. Here are some examples of what I've tried: >> >> beginJobEmailBody = "The ${env.JOB_NAME} job has begin on" >> def beginJobEmailBody = "The ${env.JOB_NAME} job has begin on" >> GString this.beginJobEmailBody = "The ${env.JOB_NAME} job has begin on"; >> >> >> -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0c0f1053-aa0c-494a-97f0-7f0b7a633c29%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
