I have a pipeline, such as:
env_file='/tmp/.test_envs' def test_fun(){ return env_file } pipeline { agent any environment { //test env_file test_env="${env_file}" main_script="/scripts/release/release_dynamic_v2.sh" } parameters { extendedChoice bindings: '',description:'test_param', groovyClasspath: '', groovyScript: ''' def test_env="${env_file}" // def test_env = test_fun() // Here is error println test_env def ns_file = new File(file_path) def value_list = [] def line_list = ns_file.readLines() line_list.each{ value_list.push(it.tokenize(" ")[0]) } return value_list''', multiSelectDelimiter: ',', name: 'project_name', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_SINGLE_SELECT', visibleItemCount: 10, descriptionBindings: '', descriptionGroovyClasspath: '', descriptionGroovyScript: '' } stages { stage("check_params"){ steps { buildName "#${BUILD_NUMBER}" buildDescription "Checking parameters is incorrect." error 'The project_env_name mustn\'t be none or the project_name is empty.' } } stage('show_info'){ steps { sh ''' env ''' } } } post { success { sh ''' echo post_success ''' } failure { sh ''' echo post_failure ''' } } }
I want to use the function test_fun or the variable env_file in parameters block.
But it dons't work.
What should I do? Thanks.
We have a large function which is messy to insert inline. We have tried moving it to a function at the top of the Jenkinsfile, but this doesn't work. We are currently making use of the "groovyScriptFile" property, however this has a problem because the file needs to be available on the Jenkins master, and the file is not checked out by default, so we have to manually checkout the file on the master for this to work.
It would be great if we could just move this code to a function at the top of the Jenkinsfile.