Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-42753

Generate runtime model directly from AST model

    • Declarative - 1.2

      My apologies if this isn't a bug, but I've searched high and low and tried a number of things, but I can't seem to find the syntax ex. to solve what's broken.  After upgrading pipeline plugins to the latest releases (as of today), my declarative pipelines broke because it seems there might no longer be ability to use a property in the agent label.  This was working:

      pipeline{
      
          parameters {
              choice(choices: 'server-cd\server-demo', description: DeployEnvironmentHelp, name: 'Environment')
          } 
      
          environment {
              DEPLOYENVIRONMENT = "${params.Environment}"
          }
      
          agent none
      
          stages {
              stage ("Stage 1") {
                  agent {label DEPLOYENVIRONMENT}
                  echo 'Get Deployment Helper Files from SCM repo(s)...'
              }
          } 
      }

      But the pipeline fails saying that the DEPLOYENVIRONMENT is not a proper value (I no longer have the exact message )  

      As of model def. 1.1.1, is it no longer possible to use an environment variable or property in the agent label?   btw - I'm setting DEPLOYENVIRONMENT so I can do other tests and not have to keep using params.Environment, but in other pipelines I set properties so that I can define which agent based on properties that change in the pipeline.

       

       

          [JENKINS-42753] Generate runtime model directly from AST model

          Jason Davis created issue -

          Andrew Bayer added a comment -

          So what was working before? label DEPLOYMENTENVIRONMENT? I think I can see how that may have happened (we don't actually resolve the environment values until a bit later) but I'll play with this and see what I can figure out. Sorry for the inconvenience!

          Andrew Bayer added a comment - So what was working before? label DEPLOYMENTENVIRONMENT ? I think I can see how that may have happened (we don't actually resolve the environment values until a bit later) but I'll play with this and see what I can figure out. Sorry for the inconvenience!
          Jason Davis made changes -
          Description Original: My apologies if this isn't a bug, but I've searched high and low and tried a number of things, but I can't seem to find the syntax ex. to solve what's broken.  After upgrading pipeline plugins to the latest releases (as of today), my declarative pipelines broke because it seems there might no longer be ability to use a property in the agent label.  I had something like this:
          {noformat}
          pipeline{

              parameters {
                  choice(choices: 'server-cd\server-demo', description: DeployEnvironmentHelp, name: 'Environment')
              }

              environment {
                  DEPLOYENVIRONMENT = "${params.Environment}"
              }

              agent none

              stages {
                  stage ("Stage 1") {
                      agent {label DEPLOYENVIRONMENT}
                      echo 'Get Deployment Helper Files from SCM repo(s)...'
                  }
              }
          }{noformat}
          But the pipeline fails saying that the DEPLOYENVIRONMENT is not a proper value (I no longer have the exact message :()  

          As of model def. 1.1.1, is it no longer possible to use an environment variable or property in the agent label?   btw - I'm setting DEPLOYENVIRONMENT so I can do other tests and not have to keep using params.Environment, but in other pipelines I set properties so that I can define which agent based on properties that change in the pipeline.

           

           
          New: My apologies if this isn't a bug, but I've searched high and low and tried a number of things, but I can't seem to find the syntax ex. to solve what's broken.  After upgrading pipeline plugins to the latest releases (as of today), my declarative pipelines broke because it seems there might no longer be ability to use a property in the agent label.  This was working:
          {noformat}
          pipeline{

              parameters {
                  choice(choices: 'server-cd\server-demo', description: DeployEnvironmentHelp, name: 'Environment')
              }

              environment {
                  DEPLOYENVIRONMENT = "${params.Environment}"
              }

              agent none

              stages {
                  stage ("Stage 1") {
                      agent {label DEPLOYENVIRONMENT}
                      echo 'Get Deployment Helper Files from SCM repo(s)...'
                  }
              }
          }{noformat}
          But the pipeline fails saying that the DEPLOYENVIRONMENT is not a proper value (I no longer have the exact message :()  

          As of model def. 1.1.1, is it no longer possible to use an environment variable or property in the agent label?   btw - I'm setting DEPLOYENVIRONMENT so I can do other tests and not have to keep using params.Environment, but in other pipelines I set properties so that I can define which agent based on properties that change in the pipeline.

           

           

          Jason Davis added a comment -

          Whoops sorry for not making that more clear!  Yes,

          agent {label DEPLOYENVIRONMENT} was working and is no longer.  

           

           

          Jason Davis added a comment - Whoops sorry for not making that more clear!  Yes, agent {label DEPLOYENVIRONMENT} was working and is no longer.      
          Jason Davis made changes -
          Summary Original: Using a Pipeline Property an Agent Label? New: Using a Pipeline Property with an Agent Label?

          Andrew Bayer added a comment -

          So 

          agent {
            label DEPLOYENVIRONMENT
          }

          Won't work anytime soon. I'm going to try to deal with the backend parsing/resolving such that it might be able to work in the future, but even then, I'd probably say go with

          "${DEPLOYENVIRONMENT}"

          But for now, in this specific case, you can do 

          agent {
            label "${params.Environment}"
          }

          And it should work. But yeah, you can't count on environment variables to be available as parameters to agent for the time being.

          Andrew Bayer added a comment - So  agent {   label DEPLOYENVIRONMENT } Won't work anytime soon. I'm going to try to deal with the backend parsing/resolving such that it might be able to work in the future, but even then, I'd probably say go with "${DEPLOYENVIRONMENT}" But for now, in this specific case, you can do  agent { label "${params.Environment}" } And it should work. But yeah, you can't count on environment variables to be available as parameters to agent for the time being.

          Andrew Bayer added a comment -

          Grr, actually, I'm having trouble with that last example in my local tests, but I think that may just be that Declarative's dependencies aren't new enough - not a problem in the real world, just in my tests.

          Andrew Bayer added a comment - Grr, actually, I'm having trouble with that last example in my local tests, but I think that may just be that Declarative's dependencies aren't new enough - not a problem in the real world, just in my tests.

          Jason Davis added a comment -

          Bummer... OK - before reaching out with this issue, I did try both those recommendations but ran into troubles before I had to roll back the plugin updates.  I'm not at a place yet where I can re-set up some tests and report the results, but will asap.  Hopefully you hit on solution. 

          Jason Davis added a comment - Bummer... OK - before reaching out with this issue, I did try both those recommendations but ran into troubles before I had to roll back the plugin updates.  I'm not at a place yet where I can re-set up some tests and report the results, but will asap.  Hopefully you hit on solution. 

          Andrew Bayer added a comment -

          Repurposing this ticket to solve this whole category of problems, not just this one particular one.

          Andrew Bayer added a comment - Repurposing this ticket to solve this whole category of problems, not just this one particular one.
          Andrew Bayer made changes -
          Issue Type Original: Bug [ 1 ] New: Improvement [ 4 ]
          Priority Original: Minor [ 4 ] New: Critical [ 2 ]
          Summary Original: Using a Pipeline Property with an Agent Label? New: Generate runtime model directly from AST model

            abayer Andrew Bayer
            jedavis Jason Davis
            Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: