Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-21898

Inject Bamboo Variable on Windows script task has a encoding issue

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • 8.1.8
    • Tasks
    • None

      Issue Summary

      This is reproducible on Data Center:

      Bamboo fails to load default encoded files when loaded from an "Inject variable task" on Windows. This is not reproducible on Linux hosts/agents.

      The default character encoding on Windows is UTF-16. UTF-16 encoded files result in a corrupted variable import. When forcing the file encoding as UTF-8 the variable is partially recognised and allows a workaround to be used.

      Steps to Reproduce

      It is assumed that Windows running the Bamboo Agent uses the default input/output encoding.

      1. Create a Script task
      2. Use the below script contents
        echo poWindowCloneDir=D:\bamboo-home\xml-data\build-dir\TP-TBP-JOB1 > a.txt
        type a.txt
        Get-Content a.txt
        
      3. Inject the a.txt file using an "Inject Variable task"
      4. Monitor the build logs for "Injected variable bamboo..."

      Expected Results

      Bamboo should understand the file encoding and load it correctly. The variables should be parsed from the created file without further hacks (check workaround)

      Injected variable bamboo.inject.poWindowCloneDir=D:\bamboo-home\xml-data\build-dir\TP-TBP-JOB1
      

      Actual Results

      We can observe in the build logs that a broken/corrupted variable is created with unrecognised content:

      simple	27-Sep-2022 00:36:19	Starting task 'Inject Bamboo variables' of type 'com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin:inject'
      simple	27-Sep-2022 00:36:19	Injected variable bamboo.inject.�= in LOCAL scope
      simple	27-Sep-2022 00:36:19	Injected variable bamboo.inject.??p�o�W�i�n�d�o�w�C�l�o�n�e�D�i�r�=�"�D�:��b�a�m�b�o�o�-�h�o�m�e��x�m�l�-�d�a�t�a��b�u�i�l�d�-�d�i�r��T�P�-�T�B�P�-�J�O�B�1�"� in LOCAL scope
      

      When using a file encoded with UTF-8, the "\" (backslash) character is missing from the variable value:

      simple	27-Sep-2022 02:12:48	Starting task 'Inject Bamboo variables' of type 'com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin:inject'
      simple	27-Sep-2022 02:12:48	Injected variable bamboo.inject.poWindowCloneDir=D:bamboo-homexml-databuild-dirTP-TBP-JOB1 in LOCAL scope
      

      Workaround

      1. Set the Script task interpreter as PowerShell
      2. Force the script to create UTF-8 encoded files. Add the $PSDefaultParameterValues variable at the beginning of the Script task:
        $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
        
      3. Modify the command and add double backslashes to the variable contents. This way Bamboo will recognise them as legitimate characters. This is the final script:
        $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
        echo poWindowCloneDir=D:\\bamboo-home\\xml-data\\build-dir\\TP-TBP-JOB1 > a.txt
        type a.txt
        Get-Content a.txt
        

        The workaround will generate a file that is recognised by Bamboo and can be correctly imported as a variable. This has been tested with the "\" (backslash) character. It may also manifest in other character sets.

        simple	27-Sep-2022 14:39:05	Starting task 'Inject Bamboo variables' of type 'com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin:inject'
        simple	27-Sep-2022 14:39:05	Injected variable bamboo.inject.poWindowCloneDir=D:\bamboo-home\xml-data\build-dir\TP-TBP-JOB1 in LOCAL scope
        

            [BAM-21898] Inject Bamboo Variable on Windows script task has a encoding issue

            SET Analytics Bot made changes -
            UIS Original: 6 New: 1
            Bugfix Automation Bot made changes -
            Priority Original: Low [ 4 ] New: Medium [ 3 ]
            SET Analytics Bot made changes -
            UIS Original: 1 New: 6
            SET Analytics Bot made changes -
            UIS Original: 6 New: 1
            SET Analytics Bot made changes -
            UIS New: 6
            Marcin Gardias made changes -
            Status Original: Needs Triage [ 10030 ] New: Long Term Backlog [ 12073 ]
            Eduardo Alvarenga (Inactive) made changes -
            Resolution Original: Answered [ 9 ]
            Status Original: Closed [ 6 ] New: Needs Triage [ 10030 ]
            Marcin Gardias made changes -
            Resolution New: Answered [ 9 ]
            Status Original: Long Term Backlog [ 12073 ] New: Closed [ 6 ]
            Mateusz Szmal made changes -
            Status Original: Needs Triage [ 10030 ] New: Long Term Backlog [ 12073 ]
            Shashank Kumar made changes -
            Remote Link New: This issue links to "Page (Confluence)" [ 688400 ]

              Unassigned Unassigned
              562af27be96e Santhosh Thokur Raghava
              Affected customers:
              2 This affects my team
              Watchers:
              7 Start watching this issue

                Created:
                Updated: