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

agent docker parameters do not honor the current environment

      Currently I need to use multiple docker containers which need to be linked together.
      I tried using the --link option to set the linked image. In my use-case I don't want to set a fixed name but need to use a variable for the name.

      In this case the args parameter is evaluated to "--link null:linkedimage" and the job fails.

      Or is there another way to pass dynamic parameters (from variables) to the docker args?

      pipeline {
          agent any
          environment {
              LINK_DOCKER_IMAGE = "linkedimage"
          }
          stages {
              stage ('Compose') {
                  agent {
                     docker {
                          image 'alpine'
                          args  "--link ${env.LINK_DOCKER_IMAGE}:linkedimage"
                      }
                  }
                  steps {
                          sh 'printenv'
                  }
              }
          }
      }
      

          [JENKINS-42369] agent docker parameters do not honor the current environment

          Sven Carstens created issue -
          James Dumay made changes -
          Epic Link New: JENKINS-45381 [ 183541 ]
          James Dumay made changes -
          Rank New: Ranked higher
          James Dumay made changes -
          Rank New: Ranked lower

          I came across the same issue and was able to work around it by defining variable outside the pipeline.

          def LINK_DOCKER_IMAGE = "linkedimage"
          pipeline {
              ...
                  docker {
                      image 'alpine'
                      args  "--link ${LINK_DOCKER_IMAGE}:linkedimage"
                  }

          Jitender Singh added a comment - I came across the same issue and was able to work around it by defining variable outside the pipeline. def LINK_DOCKER_IMAGE = "linkedimage" pipeline { ... docker { image 'alpine' args "--link ${LINK_DOCKER_IMAGE}:linkedimage" }

          Linus Lotz added a comment -

          I want to mount a volume depending on a parameter, so the workaround does not work for me.

          Linus Lotz added a comment - I want to mount a volume depending on a parameter, so the workaround does not work for me.

          Karl added a comment - - edited

          you can use build parameters.

          pipeline {
              agent any
              parameters {
                  string(defaultValue: 'linkedimage', description: '', name: 'LINK_DOCKER_IMAGE')
              }
              stages {
                  stage ('Compose') {
                      agent {
                          docker {
                              image 'alpine'
                              args "--link ${params.LINK_DOCKER_IMAGE}:linkedimage" }
                      }
                      steps {
                          sh 'printenv'
                      }
                  }
              }
          }
          

          Karl added a comment - - edited you can use build parameters. pipeline { agent any parameters { string(defaultValue: 'linkedimage' , description: '', name: ' LINK_DOCKER_IMAGE') } stages { stage ( 'Compose' ) { agent { docker { image 'alpine' args "--link ${params.LINK_DOCKER_IMAGE}:linkedimage" } } steps { sh 'printenv' } } } }
          Guillaume Dupin made changes -
          Comment [ Hi !
          This bug is very troubelsome for us and the workarounds does not work in all cases... and are workarounds ;)
          Would it be possible to change the priority to accelerate the fix please ? ]

          Hi !
          This bug is very troubelsome for us and the workarounds does not work in all cases... and are workarounds
          Would it be possible to change the priority to accelerate the fix please ?

          Guillaume Dupin added a comment - Hi ! This bug is very troubelsome for us and the workarounds does not work in all cases... and are workarounds Would it be possible to change the priority to accelerate the fix please ?

          Same issue. I am using a dockerfile agent and there is no way (or I don't know one) to pass environment variables to the "docker build" command. Example:

          pipeline {
              environment {
                  SSH_KEY = credentials('ssh-key')
              }
              agent {
                  dockerfile {
                      additionalBuildArgs "--build-arg SSH_KEY=${SSH_KEY}"
                  }
              }
              stages {
                  stage('Test') {
                      steps {
                          sh 'go test'
                      }
                  }
              }
          }
          

          Anatoliy Vlassov added a comment - Same issue. I am using a dockerfile agent and there is no way (or I don't know one) to pass environment variables to the "docker build" command. Example: pipeline { environment { SSH_KEY = credentials( 'ssh-key' ) } agent { dockerfile { additionalBuildArgs "--build-arg SSH_KEY=${SSH_KEY}" } } stages { stage( 'Test' ) { steps { sh 'go test' } } } }

            Unassigned Unassigned
            sven_carstens_udg Sven Carstens
            Votes:
            29 Vote for this issue
            Watchers:
            31 Start watching this issue

              Created:
              Updated: