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

Extra characters in environment variables when using a multi-OS master/slave setup

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

      Hi,
      If I understood it correctly, with the Kubernetes Plugin the "jnp" container is where the Jenkins agent is running. The plugin offers the possibility to execute commands in different containers that are started as part of the pipeline.

      In order to launch commands in those additional containers, the plugin runs "kubectl exec". Before launching the actual command, the plugin executes a block of instructions to set the execution environment correctly. This block contains for example the environment variables available at that stage of the build.

      When preparing the block, the plugin using "println()" to write export instructions:

      out.println(
          String.format(
              windows ? "set %s=%s" : "export %s='%s'",
              entry.getKey(),
              windows ? entry.getValue() : entry.getValue().replace("'", "'\\''")
           )
      );
      

      I believe this causes the block to contain the new line character as configured on the Jenkins Master. In a setup with a Windows Master and Linux Agents, this leads (I think) to additional "\r" characters in the environment variables configured in the additional containers.

      See also my last comment on the issue.

      Regards

          [JENKINS-63847] Extra characters in environment variables when using a multi-OS master/slave setup

          In our case, heterogeneous environment - mix of windows master and windows and linux nodes, this issue prevents us from using Kubernetes agents in Jenkins

          Alexey Trenikhin added a comment - In our case, heterogeneous environment - mix of windows master and windows and linux nodes, this issue prevents us from using Kubernetes agents in Jenkins

          I don't have a windows environment to test it, but could you try https://repo.jenkins-ci.org/incrementals/org/csanchez/jenkins/plugins/kubernetes/1.28.6-rc3092.285ee36f6833/ and see whether it fixes it?

          Vincent Latombe added a comment - I don't have a windows environment to test it, but could you try https://repo.jenkins-ci.org/incrementals/org/csanchez/jenkins/plugins/kubernetes/1.28.6-rc3092.285ee36f6833/ and see whether it fixes it?

          max_laverse alexeyt I believe the linked PR addresses it however I don't have the environment to test it. Can one of you try it and tell me?

          Vincent Latombe added a comment - max_laverse alexeyt I believe the linked PR addresses it however I don't have the environment to test it. Can one of you try it and tell me?

          Max Laverse added a comment - - edited

          Hi vlatombe! I just helped debugging. I actually don't have any Windows environment to test this either.

          Max Laverse added a comment - - edited Hi vlatombe ! I just helped debugging. I actually don't have any Windows environment to test this either.

          Allan Kristensen added a comment - - edited

          I ran into this issue because of a windows master.

          Uploaded the plugin from the above url. Downgraded Kubernetes Client API Plugin to 4.13.3-1.

          I can confirm it fixes the new line issue. Thumbs-up merging to master.

           

           

          Allan Kristensen added a comment - - edited I ran into this issue because of a windows master. Uploaded the plugin from the above url. Downgraded Kubernetes Client API Plugin to 4.13.3-1. I can confirm it fixes the new line issue. Thumbs-up merging to master.    

            vlatombe Vincent Latombe
            max_laverse Max Laverse
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: