1
 environment {
      :
    PROXY_HOST = "Nothing"
      :
  }

stage('deploy') {

        steps {

         script {

            if (env.GIT_BRANCH == 'master') {
                env.PROXY_HOST = env.PROXY_HOST_PRODUCTIVE
            }
            else if(env.GIT_BRANCH == 'develop')
            {
                env.PROXY_HOST = env.PROXY_HOST_ACCEPTANCE
            }
            else
            {
                env.PROXY_HOST = env.PROXY_HOST_DEV
            }
         }

        echo env.PROXY_HOST   // here it will still print Nothing
        sh 'curl "$PROXY_HOST"'   // here I need the variable again

I defined a variable in environment section of jenkinsfile (declarative) just to use it in an if...else construct. But it will never be reassigned . What can I do ?

Toni26
  • 489
  • 4
  • 11
  • You could define `PROXY_HOST` outside the pipeline code `def PROXY_HOST = "Nothing"`. Or have a look at https://stackoverflow.com/questions/53541489/updating-environment-global-variable-in-jenkins-pipeline-from-the-stage-level/53541813 – Melkjot Sep 22 '21 at 12:55
  • This sounds like it should either be a global variable (as recommended above), or a parameter, but probably a global variable. – Matthew Schuchard Sep 22 '21 at 15:01

0 Answers0