Setting Groovy version on global level for all pipeline jobs

Issue: We noticed a bug in Groovy 2.4.21 and require an upgrade to version 2.5, the university has about 80 to 90 pipeline jobs running as “Pipeline script from SCM”. I don’t want to go through each job and set the groovy version within the script.

I have read and watched the following links

https://issues.jenkins.io/browse/JENKINS-53372

I have a couple of questions just to confirm my understanding

  1. From the links above i’m gathering Im unable to set the Groovy Version on a global level to override Jenkins Core Groovy ?

  2. I will need to update each pipeline script and set the Groovy version correctly (this setting is based on Manage Jenkins / Global Tool Configuration / Groovy) ?

  3. Our agents are deployed via pre-built images, if I install / Configure GROOVY_HOME within the image I still need to configure the pipeline script to call the version set within “Global Tool Configuration”

Any thoughts or tips/tricks to manage this number of pipe jobs that require the Groovy version update?

Hello @ReidWat :wave:

I’m not an expert on that, I just have read a few things.
Hopefully someone more knowledgeable will chime in.
As far as I can tell, you can’t set the Groovy version on a global level to override Jenkins Core’s Groovy.
You would need to update each pipeline script and set the Groovy version correctly.
As for managing a large number of pipeline jobs that require the Groovy version update, you could try the following:

  1. Use the Jenkins command line client (CLI) to update the pipeline scripts in bulk. This may be a more efficient way to update a large number of jobs instead of manually editing each one.
  2. You could maybe switch to using a Jenkinsfile instead of a Pipeline script from SCM. This could maybe allow you to manage the Groovy version in the Jenkinsfile and make updates more easily.
pipeline {
    agent any
    tools {
        groovy 'Groovy-2.5.14'
    }
    stages {
        stage('Build') {
            steps {
                sh 'groovy -version'
            }
        }
    }
}

  1. I know this won’t help for existing pipelines, but you could maybe create a template pipeline script for new pipelines that includes the Groovy version and use it as a basis for creating new pipeline jobs. :person_shrugging:
  2. Use a sledgehammer to crack a nut: why not use a configuration management tool like Ansible or Puppet to manage the Jenkins configuration, including the Groovy version?

Sorry just have one more question, the devs wrote the following templates and I’m trying to estimate how work/time is required to manually update them

#!groovy
package pipelines.templates

pipeline {
    agent { label("maven-test-agent") }
    stages {
        stage("Setup workspace") {
            steps {
                script {
                    def workspace = load "src/modules/Workspace.groovy"
                    workspace.setup("resources/definitions/ecsDeployTemplate.yaml", false)
                }
            }
        }
       stage("Create ECS Build Deploy job") {
            steps {
                script {
                    log.heading("Create ECS Build Deploy job")
                    def jenkins = load "src/modules/Jenkins.groovy"
                    jenkins.createPipeline()
                }
            }
        }
    }
    post {
        always {
            script {
                def postAction = load "src/modules/PostAction.groovy"
                postAction.perform(false, true)
            }
        }
    }
}

Please correct me if im wrong but I need to rewrite these templates and move away from using script steps because if I set the following “withGroovy” this seems to be ignored and still triggers jenkins core groovy version 2.4.21

pipeline {
    agent { label("maven-test-image") }
    tools {
           groovy 'Groovy-2.5.1'
    }

or

 post {
        always {
            script {
                withGroovy(tool:'Groovy-2.5.1'){
                    def postAction = load "src/modules/PostAction.groovy"
                    data.athena.metadata["updated"] = false
                     postAction.perform(false)
                 }
            }
        }
    }

so for example I should be using the following

 stage ('Example') {
            steps {
                withGroovy(tool:'Groovy-2.5.1') {
                    sh 'groovy deploy.groovy'
                }
            }