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.
[JENKINS-68609] How to use jenkins pipeline function in parameter plugin groovy script
Description |
Original:
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. |
New:
I have a pipeline, such as:
{code:groovy} 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 ''' } } } {code:groovy} 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. |
Description |
Original:
I have a pipeline, such as:
{code:groovy} 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 ''' } } } {code:groovy} 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. |
New:
I have a pipeline, such as:
{code:java} 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 ''' } } } {code} {code:groovy} 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 ''' } } } {code} 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. |
Description |
Original:
I have a pipeline, such as:
{code:java} 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 ''' } } } {code} {code:groovy} 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 ''' } } } {code} 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. |
New:
I have a pipeline, such as:
{code:groovy} 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 ''' } } } {code} 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. |
Assignee | Original: vimil [ vimil ] | New: Martin Wang [ martin_wang ] |
Resolution | New: Fixed [ 1 ] | |
Status | Original: Open [ 1 ] | New: Resolved [ 5 ] |