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!

    Check if variable exists

    Scheduled Pinned Locked Moved Support
    variablesbuildmaster
    2 Posts 2 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.
    • N Offline
      nsitnikov_5096
      last edited by

      What is the best way to verify that the variable exists? I.e. if variable can't be resolved the execution fails, but most of the time we don't want to fail it, we just need to continue with some default value provided in that plan.
      So far the only workaround I found is to run the check in try-catch block and assign the default this way, but it still produces a warning in the plan execution. Ideally we just need to assign the default value if the variable can't be resolved, without any errors or warnings.

      set $BuildTestsFlag = "";
          try
          {
              set $BuildTestsFlag = $BuildTests;
              Log-Information BuildTests variable is set to $BuildTestsFlag;
          }
          catch
          {
              Log-Information BuildTests variable is not defined so we will not build tests;
          }
      

      Product: BuildMaster
      Version: 5.8.2

      1 Reply Last reply Reply Quote 0
      • ? This user is from outside of this forum
        Guest
        last edited by

        There are 2 ways to handle this:

        • set a higher-scoped variable to the default value, e.g. set $BuildTestsFlag to false at the application group or system level; this removes the need to check at all, or:
        • use if !$IsVariableDefined(BuildTestsFlag) function to determine if it doesn't exist
        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