0

I am trying to set a Jenkins environment variable where I can get html values and pass it downstream for filtering in parameters stage. I am unable to do so, here we have minimal example

pipeline { agent any environment { get = new URL("http://company_server:port/packages/").openConnection(); getRC = get.getInputStream().getText() // set getRC and access this value for result (highlited with ***********) } stages { stage('Parameters'){ steps { script { properties([ parameters([ [$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: '', name: 'foo', filterLength: 1, filterable: true, script: [$class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: "return['']" ], script: [ classpath: [], sandbox: false, script: ''' def result = (getRC =~ /(">)pip_pkgs[^<]*/).findAll() def sublist = [] result.each { sublist.add(it[0].split(",")[0].replace('">', '')) } return sublist ''' ] ] ], ]) ]) } } } } } 
1
  • The environment block is for setting shell environment variables. You appear to want to set global Groovy Pipeline variables instead. If you migrate the variables, then it should start functioning correctly. Commented Dec 11, 2020 at 18:52

2 Answers 2

1

check here : jenkins environment variables

stages { stage('Build') { steps { echo "Database engine is ${DB_ENGINE}" echo "DISABLE_AUTH is ${DISABLE_AUTH}" sh 'printenv' } } 
Sign up to request clarification or add additional context in comments.

Comments

0

When you are using a variable that was set as an environment variable, you have to use like this: ${your_variable} (See Using environment variables)

In your case:

pipeline { agent any environment { get = new URL("http://company_server:port/packages/").openConnection(); getRC = get.getInputStream().getText() // set getRC and access this value for result (highlited with ***********) } stages { stage('Parameters'){ steps { script { properties([ parameters([ [$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT', description: '', name: 'foo', filterLength: 1, filterable: true, script: [$class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: "return['']" ], script: [ classpath: [], sandbox: false, script: ''' def result = (${getRC} =~ /(">)pip_pkgs[^<]*/).findAll() def sublist = [] result.each { sublist.add(it[0].split(",")[0].replace('">', '')) } return sublist ''' ] ] ], ]) ]) } } } } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.