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

Kubernetes agent environment not working with Git Parameter branch variable in SCM

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • kubernetes-plugin
    • None

      When using Git Parameter variable (ex ${BRANCH}) git checkout can be made in any "phisical node" but branch variable is not recognize by  any kubernetes agent, but if a string is used instead checkout is meade in kubernetes properly.

      JOB CONFIG

      1) Git Parameter configuration in job

      2) SCM configuration

      FAILED PIPELINE LOGS

      1) Correct SCM in 'master' label \\{_}Stage => Prepare\\{_}, ${BRANCH} variable is highlighted

      (pipeline code block)

      Branch was clone fine

      2) When trying to clone inside kubernetes environment ${BRANCH} is not recognized \\{_}Stage =>\\{_} \\{_}Build PHP test image\\{_}. Variable is highlighted, values is not recognized (seems treated as string).

      (pipeline code block)

      SUCCESS PIPELINE LOGS

      If the needed branch is hardcoded instead of the Git Parameter variable, checkouts work fine even in kubernetes environment

      1) SCM configuration

      2) Kubernetes agent/pod is created and checkout is performed inside, branch name is now correct (highlighted) \\{_}Stage =>\\{_} \\{_}Build PHP test image\\{_}

      • Why is the Git Parameter variable not recognized by kubernetes?
      • How can we pass that variable to kubernete-pligin?

      Could you help on this? Thanks in advance

      Regards!

      PS: This is the kubernetes agent definition

      kaniko-pod-definition.yaml

      (Also attahced)

       

          [JENKINS-71816] Kubernetes agent environment not working with Git Parameter branch variable in SCM

          David added a comment - - edited

          I've found a workaround, as ${BRANCH} is not recognized inside kubernetes, the (kaniko) agent's yaml file was changed as follows:

          apiVersion: v1
          kind: Pod
          spec:  
            containers:    
              - name: kaniko      
                image: gcr.io/kaniko-project/executor:debug      
                command: ["/bin/sh"]      
                args: ["-c", "while true; do export BRANCH='BRANCH_KANIKO'; sleep 99999; done"]      
                volumeMounts:
                  - name: registry-secret
                    mountPath: /kaniko/.docker
            volumes:
              - name: registry-secret
                secret:
                  secretName: registry-secret
           

          Exporting the environment variable as command in the yaml file did the trick, then, in te pipeline code, the param variable is saved as env variable and then used in the kubernetes agent section:

          Anyway, this is a critical bug/feature to be fixed in this plugin, hope this help anyone having the same issue.

          Regards!

          David added a comment - - edited I've found a workaround, as ${BRANCH} is not recognized inside kubernetes, the (kaniko) agent's yaml file was changed as follows: apiVersion: v1 kind: Pod spec: containers: - name: kaniko image: gcr.io/kaniko-project/executor:debug command: [ "/bin/sh" ] args: [ "-c" , " while true ; do export BRANCH= 'BRANCH_KANIKO' ; sleep 99999; done" ] volumeMounts: - name: registry-secret mountPath: /kaniko/.docker volumes: - name: registry-secret secret: secretName: registry-secret Exporting the environment variable as command in the yaml file did the trick, then, in te pipeline code, the param variable is saved as env variable and then used in the kubernetes agent section: Anyway, this is a critical bug/feature to be fixed in this plugin , hope this help anyone having the same issue. Regards!

            Unassigned Unassigned
            tang81 David
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: