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!

    Script Repository System Variables

    Scheduled Pinned Locked Moved Support
    script-repositorypowershellbuildmaster
    9 Posts 1 Posters 31 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.
    • ? This user is from outside of this forum
      Guest
      last edited by

      Hi,

      When creating an execute powershell script action, you can pass through system/application variables by doing:

      BuildNumber=BuildNumber

      and then accessing via $BuildNumber in the script.

      When I move this script into the script repository, there is a parameters section but no variables. Trying to pass variables into a parameter doesn't seem to work, so how would I go about accessing a variable from within my script?
      I've also tried using a Param() definition for the script.

      Thanks.

      Product: BuildMaster
      Version: 4.7.3

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

        Script repository scripts only support passing parameters, and for PowerShell you just do this by starting the script with a Param() block.

        We will probably add standard BuildMaster variable replacement to script repository scripts at some point, but we don't want to break anyone's scripts by just doing it transparently.

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

          I don't have a problem with using Params. When I configure the params though is it possible to have a default value of $ReleaseNumber for example?
          That way it is passed via params, won't break existing scripts but provides a way to access system variables. Alternatively is there another approach with direct access to system / application variables from within a powershell script?

          My only other solution to this is to have different step write the system variable values i need to a file, then read the file in the powershell script.

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

            PowerShell scripts have two modes for default parameter values. The default mode effectively just passes in null to the script and relies on defaults being defined in the [param] block of the script to be used by PowerShell. You can also override this behavior and use the BuildMaster-supplied values as defaults instead - in this mode you can use BuildMaster variables as defaults.

            To enable this behavior, go to the Windows extension on the Admin->Manage Extensions page, and select Create Configuraiton Profile. Name the profile (and set it as default if you want it to affect every Execute PowerShell action), and check the "Override PowerShell script defaults" box. Now you should be able to use variables in defaults.

            Does this help?

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

              Thanks Dean.

              After a bit more playing and following your instructions I now have this working.

              Perhaps this could be included in the Support documentation around executing powershell scripts?

              For the benefit of others I now have a powershell script in the script repository:

              param(
                  [string]$ReleaseNumber
              )
              Write-Output $ReleaseNumber
              

              There is a parameter for the script defined as:

              Parameter: ReleaseNumber

              Default Value: $ReleaseNumber

              I also created the powershell config as suggested by Dean. Call the repository powershell script from an action group choosing the new powershell config. Leave the parameter value blank (it should show the $ReleaseNumber in light grey).

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

                I'll make a note to get the documentation updated at least; that's a good suggestion. I know the script repository has some room for improvement, particularly with how it handles parameters; I'll see if we can get any enhancements scoped in for the BuildMaster 4.8 release. Any general suggestions for how we can improve?

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

                  Hi,

                  I think using built-in parameters is a pretty common use case. Maybe rather than specifying a default value of a system variable, you could just select parameters to inject. Then the powershell script is the same but when using the script elsewhere you aren't presented with the option to set the parameter. If my script has 5 system variable and one true parameter I don't want to see all 6 parameters from the action. It would be useful to also retain the existing ability to override, but only if the script definition allows it.

                  I think a few more tutorials would go a long way. I know a lot of effort has been put into kramerica industries but the places where I have struggled to move forward is in the details rather than the high level of how to put together build pipelines.

                  So far I'm really liking the product though :)

                  Also, maybe add a script-repository tag for posts.

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

                    Thanks for the feedback! We're aware of the need for more tutorials, and hopefully will be updating and adding more in the coming months. Regarding the feature request - that all sounds pretty good to me; I've added an item for the v4.8 release to see if we can get those in.

                    Also retagged this question with [script-repository] :)

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

                      Just letting you know that we have added a feature to BuildMaster 4.8 that we're calling Ambient Script Variables that should solve this problem. Basically, it allows you do define script variables that BuildMaster will evaluate and assign before running a script. So, in your case you'd just add one called ReleaseNumber that contains the value $ReleaseNumber (the value can evaluate to anything though, and use any variables/functions that are in scope when the script runs).

                      4.8.0 should be released tomorrow.

                      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