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

Build parameters are not passed to declarative pipelines

      We're using List maven artifact version in a parameterized build to pass the application artifact version as a parameter to a declarative pipeline script. Unfortunately this does not work (using ${params.ESB_VERSION} as well as ${env.ESB_VERSION}) and the parameter name is always resolved to 'null'.

      Declarative pipeline script:

       

      pipeline {
          agent {
              label "docker"
          }
      
          stages {
              […]
      
              stage('Build image') {
                  agent {
                      dockerfile {
                          reuseNode true
                          registryUrl "https://registry.comapny.com"
                          registryCredentialsId "dcr-jenkins"
                          additionalBuildArgs "--pull --build-arg ESB_VERSION=${params.ESB_VERSION}"
                          dir "installation/app"
                      }
                  }
      
                  steps {
                      script {
                          docker {
                              app = docker.build "company/app"
                          }
                      }
                  }
              }
      
              […]
      
          }
      }
      
      

      Job execution:

       

       

      [Job_Name] Running shell script
      + docker build -t 0ed28f6bfba3f17d99c8f8689058b9f5c00e8bf3 --pull --build-arg ESB_VERSION=null -f installation/app/Dockerfile installation/app
      

      Note the ESB_VERSION=null string.

       

       

          [JENKINS-45566] Build parameters are not passed to declarative pipelines

          Andrew Bayer added a comment -

          This is an issue in maven-metadata-plugin. MavenMetadataParameterValue doesn't work with Run, just AbstractBuild. It also doesn't actually set a value directly - it instead sets up a bunch of environment variables. At a minimum, the plugin needs to move to a newer version of core than its current 1.481 (at least 1.556, preferably higher still) and implement ParameterValue#buildEnvironment(Run,EnvVars) in MavenMetadataParameterValue. More may be needed as well, but that's definitely needed. I think that'd add the environment variable ESB_VERSION, though it still wouldn't be available on params.ESB_VERSION, since the params variable pulls from ParameterValue.getValue(), which defaults to returning null and isn't overridden here.

          Andrew Bayer added a comment - This is an issue in maven-metadata-plugin . MavenMetadataParameterValue doesn't work with Run , just AbstractBuild . It also doesn't actually set a value directly - it instead sets up a bunch of environment variables. At a minimum, the plugin needs to move to a newer version of core than its current 1.481 (at least 1.556, preferably higher still) and implement ParameterValue#buildEnvironment(Run,EnvVars) in MavenMetadataParameterValue . More may be needed as well, but that's definitely needed. I think that'd add the environment variable ESB_VERSION , though it still wouldn't be available on params.ESB_VERSION , since the params variable pulls from ParameterValue.getValue() , which defaults to returning null and isn't overridden here.

          see JENKINS-38619 as well.

          Torsten Reinhard added a comment - see JENKINS-38619 as well.

            gesh Gesh Markov
            stephan Stephan Austermühle
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: