I'm encountering an issue with my pipeline script when running it from SCM. The @Field annotation isn't being recognized, even though I'm using the correct import statement (import groovy.transform.Field). This only happens when running the pipeline from SCM; it works fine when the script is executed directly in Jenkins (version 2.203.3). Does anyone have any suggestions on how to resolve this?
This is an example of a segment of my code :
import groovy.transform.Field @Field def FINAL_SELECTED_RULES = [] @Field def FULL_VERSION = "1.0.0.0" @Field def SERVICE_PARAMS = [ 'TestService1', 'TestService2', ..... ] pipeline { agent { label '' } environment { GIT_URL = "" SERVICE_NAME = "" ARTIFACTORY_SOURCE = '' DEPLOY_DIR = "${env.WORKSPACE}\\Deploy" ZIP_FILE = "${DEPLOY_DIR}\\${SERVICE_NAME}.zip" DEV_SERVER_DIR = "" } options { timeout(time: 1, unit: 'HOURS') buildDiscarder(logRotator(numToKeepStr: '10')) disableConcurrentBuilds() skipStagesAfterUnstable() } parameters { string(name: 'JENKINS_SLAVE', defaultValue: '', description: 'Slave build server') booleanParam(name: 'TestService', defaultValue: false, description: '') } stages { stage('Prepare') { steps { cleanWs() git url: "${GIT_URL}", credentialsId: 'test' } } stage('Retrieve Version Info from Artifactory') { steps { script { echo "Retrieving version info from Artifactory" FINAL_SELECTED_RULES = getSelectedRules() FINAL_SELECTED_RULES.each { rule -> echo "Processing rule: ${rule.name}" def currentVersion = getVersionFromArtifactory(rule.name+"Rules") rule.version = incrementVersion(currentVersion) echo "Rule: ${rule.name}, Current Version: ${currentVersion}, New Version: ${rule.version}" } echo "Final selected rules with versions: ${FINAL_SELECTED_RULES}" } } } } } def getSelectedRules() { SERVICE_PARAMS.findAll { paramName -> params[paramName] } .collect { paramName -> [name: paramName, version: null] } } def getSelectedRulesEnv() { SERVICE_PARAMS.collect { paramName -> [ param: paramName, dir : paramName, envId: "${paramName}" ] } } def incrementVersion(version) { def parts = version.split('\\.') parts[-1] = (parts[-1].toInteger() + 1).toString() return parts.join('.') }