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 ''' ] ] ], ]) ]) } } } } }
environmentblock 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.