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

Pipeline variables not updated in agent delcaration

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • None
    • Jenkins 2.147 (from the pkg.jenkins.io/redhat repo), running on Fedora

      We currently have a multi stage pipeline, where the first stage can calculate some parameters to be used when setting up the agent for the next stage (in this case, installing the build dependencies into the container). Using a variable in the pipeline doesn't work correctly - only the initial value of the variable is picked up when building the docker container.

      e.g.

      def builddeps="test"
      pipeline {    
        agent none   
        stages {
              stage('Configure') {
                  agent {
                      dockerfile { 
                         filename 'Dockerfile.configure'
                         dir 'dist'
                      }
                  } 
                 steps {
                      echo 'Configure..'
                      checkout scm
                      script {
                          builddeps="test2"
                      }
                  }
              }
              stage('Build') {
                agent {
                      dockerfile {
                          filename 'Dockerfile.build'
                          additionalBuildArgs "--build-arg BUILD_DEPS=$builddeps"
                          dir 'dist'
                      } 
                 }
                 steps {
                    echo "Build $buildargs"
                 }
             }
          }
      }
      

      I would expect the Build agent to be created with "--build-arg BUILD_DEPS=test2", but it is created with BUILD_DEPS=test"

       

      I can work around this by writing the variable to a file, then reading the file back when creating the agent, but it doesn't feel like the correct way to do things.

       

            Unassigned Unassigned
            tomhirst Tom Hirst
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: