Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    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!

    Update either Server or Role Variables

    Scheduled Pinned Locked Moved Support
    otter
    11 Posts 3 Posters 16 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      thoven
      last edited by

      You could use the Variables Management API for this:

      https://inedo.com/support/documentation/otter/reference/api/variables

      1 Reply Last reply Reply Quote 0
      • Jonathan.EngstromJ Offline
        Jonathan.Engstrom
        last edited by

        So I have been working on different ways to update a server, and I am having some issues. I can create a new server, or add a new server to a role no problem with the code below. But Updating variables, I am getting this:

        Invoke-RestMethod : 547160Variables_CreateOrUpdateVariable57`The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Variables__Servers".

        $Key= 'blahblah'
        $Server = 'hdarsintsv1'

        $Body =
        '{
        "variables": {
        "Viking": "True",
        },
        }'

        Invoke-RestMethod $URI -Method Post -Body $Body -Verbose

        Any ideas? Thanks!

        1 Reply Last reply Reply Quote 0
        • Jonathan.EngstromJ Offline
          Jonathan.Engstrom
          last edited by

          Forgot to add this too:

          $URI = "https://azlmidrange.azlifem.azl.pvt:8626/api/infrastructure/servers/update?key=$key"

          My bad!

          1 Reply Last reply Reply Quote 0
          • Jonathan.EngstromJ Offline
            Jonathan.Engstrom
            last edited by

            So I am able to update all of the attributes of a server, with the exception of variables. I am able to edit roles, environments, temppath, drift, all without issue. I am not able to change server variables, though. Can anyone test this to confirm it may be a bug, or perhaps I am doing something wrong? Being I can update everything else, I am going to side with the former, but anything's possible.

            $Key= 'blahblah'

            $Server = 'hdarsintsv1'

            $URI = "https://otterserver.test:8626/api/infrastructure/servers/update/$Server`?key=$key"

            $Body =

            '{

             "variables": 
             
             {
                 "Viking": "True",
                 
             },
            

            }'

            Invoke-RestMethod $URI -Method Post -Body $Body -Verbose

            1 Reply Last reply Reply Quote 0
            • jraschJ Offline
              jrasch inedo-engineer
              last edited by

              That is indeed a bug in that particular API, but in the meantime the variables API can be used as follows:

              $VariableObj = @{
                  name = "Viking"
                  value = "True"
                  server = "hdarsintsv1"	
              }
              
              $Headers = @{
                  "X-ApiKey" = "blahblah"
              }
              
              Invoke-RestMethod "http://otterint/api/variables/scoped/single" -Method Post `
                  -Body ($VariableObj | ConvertTo-Json) `
                  -Headers $Headers -Verbose
              
              1 Reply Last reply Reply Quote 0
              • Jonathan.EngstromJ Offline
                Jonathan.Engstrom
                last edited by

                I am not familiar with this way to do it, and it does not appear to work for me:

                Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive.

                This appears to be an issue when using headers, but I have not found a reliable way to fix this.

                1 Reply Last reply Reply Quote 0
                • jraschJ Offline
                  jrasch inedo-engineer
                  last edited by

                  You can adapt it to your method (i.e. just use JSON directly as you did in your previous example), I just already had this script handy and don't like putting the API key in the query string if I can avoid it.

                  1 Reply Last reply Reply Quote 0
                  • Jonathan.EngstromJ Offline
                    Jonathan.Engstrom
                    last edited by

                    Thanks John. I did try a few variations, and after I ended up renaming a server trying to get your method to work, I decided to stop trying. I am not very familiar with the format you are using, and it is different from the documentation. However, I agree that not adding the key to the URL string is probably a safer way to do it, and that process and examples should be added to the documentation.

                    I still am not able to update a variable, but if one creates a new server, then you can add variables as long as it's a create. Maybe that will help whoever is going to fix it.

                    1 Reply Last reply Reply Quote 0
                    • jraschJ Offline
                      jrasch inedo-engineer
                      last edited by

                      Ahh I see the confusion now. The important bit is that I am using a completely different API (i.e. the Variables Management API that Tod originally mentioned at /api/variables, not the Infrastructure API at /api/infrastructure) to accomplish the same task as a workaround. These endpoints are also far more powerful for variables specifically (i.e. you can edit multiple at once, handle multi-scoping, etc.)

                      As I mentioned, what you did originally is supposed to work, and there is a bug filed to fix for the next release: https://inedo.myjetbrains.com/youtrack/issue/OT-257

                      1 Reply Last reply Reply Quote 0
                      • Jonathan.EngstromJ Offline
                        Jonathan.Engstrom
                        last edited by

                        Alright, after messing around with that information, I was able to get it to work. I am able to update the variables. Interesting thing is that it doesn't appear I can change just one variable, I have to change all of them, or at least enter all of them as they are?

                        Thanks for your help!

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post
                        Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation