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

Build Environment Variables not available within Container Step

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • kubernetes-plugin
    • None

      Currently, inside the build container steps, shell executions cannot access build-level parameters, such as SCM properties or Build information like BUILD_NUMBER.

      A workaround to allow this is to redeclare it:

       

      environment{

      BUILD_NUMBER = "${BUILD_NUMBER}

      }

       

      But this should be fixed to allow smoother use of the Kubernetes Plugin

          [JENKINS-49465] Build Environment Variables not available within Container Step

          An example build would be this:

           

          pipeline {
              agent {
          
                  kubernetes{
                          label 'openjdk'
                          containerTemplate{
                                  name 'openjdk'
                                  image 'openjdk'
                                  workingDir '/home/jenkins'
                                  ttyEnabled true
                                  command 'cat'
                                  args ''
                          }
                  }
          }
          
          
              stages{
                  stage('Build') {
                      steps {
          
                          sh 'echo DEFAULT_BUILD_NUMBER: ${BUILD_NUMBER}'
                          container('jnlp')
                          {
                              sh 'echo JNLP_BUILD_NUMBER: ${BUILD_NUMBER}'
                          }
                          container('openjdk'){
                              sh 'echo OPENJDK_BUILD_NUMBER: ${BUILD_NUMBER}'
                          }
                      }
                  }
              }
          }
          

           Where the container steps do not show the BUILD NUMBER.

          Matthew Ludlum added a comment - An example build would be this:   pipeline {     agent {         kubernetes{                 label 'openjdk'                 containerTemplate{                         name 'openjdk'                         image 'openjdk'                         workingDir '/home/jenkins'                         ttyEnabled true                         command 'cat'                         args ''                 }         } }     stages{         stage( 'Build' ) {             steps {                 sh 'echo DEFAULT_BUILD_NUMBER: ${BUILD_NUMBER}'                 container( 'jnlp' )                 {                     sh 'echo JNLP_BUILD_NUMBER: ${BUILD_NUMBER}'                 }                 container( 'openjdk' ){                     sh 'echo OPENJDK_BUILD_NUMBER: ${BUILD_NUMBER}'                 }             }         }     } }  Where the container steps do not show the BUILD NUMBER.

          Carlos Sanchez added a comment - Fixed in https://github.com/jenkinsci/kubernetes-plugin/pull/283

            seakip18 Matthew Ludlum
            seakip18 Matthew Ludlum
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: