Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

OTTER / List variable not working correctly



  • Hello

    List variable seems to be buggy

    Create a test otter script : test-hello.otter

    Log-Debug Hello $ServerName;
    

    Create a job template :

    • script : test-hello.otter
    • template variables:
      7fce2638-53e7-4d68-b4b3-ea228fb9f09f-image.png

    Create the job with default value ==> Job failed
    e8808bea-15f3-4411-a671-883b4ae3238a-image.png

    5b7802ad-03c5-46ab-8ad5-4524f2971b0f-image.png

    Create the job and select item2 value ==> Job failed
    ac37834b-ba67-4d42-b7a4-5c56a595e4cc-image.png
    f38fd87b-7a0b-4fe6-80bc-a98074112c49-image.png

    Create the job and select the last item value ==> Job completed
    3b730ebf-0a62-4fcb-92f5-14cde5a2fd10-image.png

    6d646b1e-a1fa-476d-ac3f-9a7efbf5d90e-image.png

    Whatever the number of items in the list, only the last item is working 🤔

    Cordially
    Philippe


  • inedo-engineer

    Hi @philippe-camelio_3885 ,

    I didn't try to reproduce this or investigate, but there is clearly some kind of problem parsing that variable value because it's a map expression, and that's crashing the job processor (i.e. script isn't even being run).

    I don't think we considered this would be used for maps, but just user-friendly variables instead. Are you intending to use this as a user-selectable map??

    Just as an idea, does prefixing it with the grave apostrophe escape symbol work? Like

    `%(env:item1)
    `%(env:item2)
    `%(env:item3)
    

    With that we can explore/consider how to fix.

    Thanks,
    Alana



  • @atripp
    This was working in Otter 3. For me, this is a regression 😥

    I am using map expression because I have to pass a group of variable which are interdependant
    So I am sure the others sysadmin and dev people will use the right set of parameters.

    Example
    I have a script for creating VM and I need to pass 3 variables (Modele, OS and Template)

    %(Modele: Ubuntu 20.04,            OS:Linux,   Template:GI-DCS-UBUNTU-20.04.1-20210121)
    %(Modele: W2019 GUI FR 2010,       OS:Windows, Template:GI-DCS-W2019-FR-GUI-20201026)
    %(Modele: W2019 CORE FR 2010,      OS:Windows, Template:GI-DCS-W2019-FR-CORE-20201026)
    %(Modele: W2019 GUI FR 2006,       OS:Windows, Template:GI-DCS-W2019-FR-GUI-20200624)
    %(Modele: W2022 CORE FR 2202,      OS:Windows, Template:GI-W2022-FR-CORE-21H2)
    %(Modele: W2022 GUI FR 2202 21H2,  OS:Windows, Template:GI-W2022-FR-GUI-21H2)
    

    I made a test with the apostrophe escape symbol and I have this error

    Beginning execution run...
    **Indexer is only valid on list or map values.**
    Execution run succeeded.
    Cleaning up temporary files on Linux/SSH (10.100.4.70:2666)...
    

  • inedo-engineer

    Thanks for clarifying @philippe-camelio_3885

    There was a big change to Job Templates in 2022, so it's not surprising it's a regression.

    We'll get this via OT-496, hopefully in the same next maintenance release as well.



  • @atripp
    OK
    Thanks


  • inedo-engineer

    Hi @philippe-camelio_3885 ,

    We tried to reproduce this in the latest version of Otter, but are not having any luck :(

    Here is my Job Template; note that you can get the JSON for job template under Admin > Raft Repositories > Browse.

    {
      "Description": "",
      "JobConfiguration": {
        "ScriptId": "Default::Script::z-z-test/test-hello.otter",
        "ServerTargeting": 1,
        "ServerNames": [
          "LOCALHOST"
        ],
        "ServerRoleNames": [],
        "EnvironmentNames": [],
        "Variables": {},
        "Arguments": ""
      },
      "TemplateUsage": 1,
      "JobVariables": [
        {
          "Name": "params",
          "Description": "",
          "InitialValue": "%(env:item1)",
          "Type": "List",
          "Usage": "Input",
          "ListValues": [
            "%(env:item1)",
            "%(env:item2)",
            "%(env:item3)"
          ],
          "ListRestrict": true
        }
      ]
    }
    

    Here is my OtterScript. I wanted to verfify that env would be written, which it was.

    foreach $i in @MapKeys(%params)
    {
        Log-Debug Hello $i;
    }
    

    It's possible it was fixed by something else since the version you used, but I don't know.

    Might be worth upgrading; if you still have the issue, can you send your JSON of the Job TEmplate?

    Thanks,
    Alana



  • Hi @atripp

    I may have found the pb:

    The list contains an extra character \r

     "ListValues": [
        "%(env:INT,site:www1,serveur:VMXXXXXX)\r",
        "%(env:DEV,site:www2,serveur:VMXXXXXX)\r",
        "%(env:PRD,site:www3r,serveur:VMXXXXXX)\r",
        "%(env:CLO,site:www4,serveur:VMXXXXXX)\r",
        "%(env:SEC,site:www5,serveur:VMXXXXXX)"
      ],
    

    I removed it, and now it is working fine.

          "ListValues": [
             "%(env:INT,site:www1,serveur:VMXXXXXX)",
             "%(env:DEV,site:www2,serveur:VMXXXXXX)",
             "%(env:PRD,site:www3r,serveur:VMXXXXXX)",
             "%(env:CLO,site:www4,serveur:VMXXXXXX)",
             "%(env:SEC,site:www5,serveur:VMXXXXXX)"
           ],
    

    Problem comes from the editor of the job.
    I made few tests, add a new value, remove one and the extra character is always added when I save the job 😠

    At least, the pb can be overcome.
    Having access to the raw content of the Raft is very usefull,

    Thanks for your time

    Best regards


  • inedo-engineer

    @philippe-camelio_3885 oh wow, great find.

    Hmmm..... so I guess that must be some kind of UI bug with not trimming the newlines 🤔

    variable.ListValues = variable.Type == VariableTemplateType.List ? txtListValues.Value?.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) : null;
    

    I'm sure this should be fixed eleswhere too, but for now I'll just add | StringSplitOptions.TrimEntries and I guess that will at least fix the UI bug


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation