BuildMaster Documentation

PowerShell & Shell Scripting

  • Last Modified: 2019-02-14

PowerShell is the standard for automating configuration on Windows servers, Bash/Sh is the standard for automating configuration on Linux servers, and BuildMaster was designed to seamlessly integrate with both -- whether that means running your existing scripts across dozens of servers, leveraging scripts built by the community, or any customized way needed.

While you definitely don't need to be a scripting guru to use BuildMaster, learning how to incorporate scripts into your BuildMaster deployment plans will enable you to automate virtually any aspect of Windows or Linux.

Script Assets in BuildMaster

BuildMaster makes it incredibly easy to use your current scripts to automate your application deployments. Once you've added a script as an asset (either in the Admin/global section, or as an Application asset), you can call it as an operation in a deployment plan, and BuildMaster will execute those scripts and present rich logs about their execution.

Inline Script Execution

Through PSExec, SHExec, and swim strings, you can incorporate scripts directly into your plans.

  • PowerShell
  • Shell
psexec >>
  # delete all but the latest 3 logs in the log directory
  Get-ChildItem "E:\Site\Logs\$ApplicationName" |
     Sort-Object $.CreatedDate -descending |
     Select-Object -skip 3 |
shexec >>
  echo "Hello $ApplicationName";

BuildMaster will seamlessly replace variables within your scripts, so in the example above $ApplicationName might be defined as a configuration variable.

Calling Scripts

After writing or uploading scripts as a script asset, you can invoke them with PSCall or SHCall as if they were an Operation.

  • PowerShell
  • Shell
pscall CreateUserInDirectory(
  domain: hdars.local,
  user: $UserName

If you use PowerShell's header documentation standards, you'll even get rich descriptions for script arguments when editing in visual mode.

shcall ConfigDirectory(
  arguments: -domain=hdars.local -user=$UserName

Evaluating PowerShell Literals

The BuildMaster Execution Engine is not a general-purpose programming runtime, and thus doesn't have built-in support for things like arithmetic. You could, of course, write a custom variable function to support this, but PSEval is much easier:

For example, say that you wanted to convert the value stored in one variable ($minutes) to milliseconds. You could PSEval the simple expression $minutes * 60 * 1000:

set $milliseconds = $PSEval($minutes * 60 * 1000);

$PSEval actually runs the expression on the server currently in context, so use it inside of an If/Else Block to perform different operations depending on the results of the expression on that server.

Built-in Operations vs Scripts

Because a script can do anything, there's an obvious overlap between BuildMaster's built-in operations and a PowerShell CmdLet or script that you might write.

In general, you should use a built-in Operation when possible: Operations are designed to be massively parallel, cancellation-aware, and highly performant, and they also provide rich descriptions when viewed outside of code.

Many scripts, on the other hand, are often written to run interactively (i.e. in a commandline), and may prompt for user input if an argument is missing, or do other things not suitable in for non-interactive, scalable environments.

Have a question? Try the Q&A Forum

Our documentation is now Open Source and on GitHub. We highly encourage our users to contribute and get involved! .