Mastering Parameter Injection in NUKE 🔥

TL;DR: Fine-tuning a build from outside using parameters is an essential feature in build execution. NUKE enables to use a declarative approach to achieve just that. Fast-failing a build in case of missing parameters and typo detection are completing this gem to provide the best experience while building. 👷🏻

Once in a while, we might need to pass additional information to our build chain. For instance, a Configuration parameter is often used to indicate whether we want to build our solution in Release or Debug mode; or we need to pass the ApiKey required to publish our NuGet packages. 📦

NUKE provides a declarative approach using auto-injection, which allows to easily access command-line arguments and environment variables from our build. Let’s look at an example:

Having our field MyParam decorated with the Parameter attribute, we can pass values to the build either by calling build -myparam value or setting an environment variable MyParam . Passing the value via argument also allows us to use double-dashes --myparam or lisp-casing -my-param 🐧. If nothing is supplied, the field will keep its default value. 🔌

Declaring parameters, will also automatically extend the help text, which is shown when calling build -help 📋

But the best news is, NUKE will also safe us from unnoticed typos! 😍

Corresponding warnings are issued before and after build execution. ⚠️

Supported types 🎲

Of course, our parameter injection supports a variety of types, including primitive literals like strings, numbers, booleans and enumeration values as well as nullable types and arrays of them (separated by spaces or a custom character). Here are some examples:

Fast-fail ⚡️

Let’s get back to our scenario about publishing NuGet packages. In order to make this work, we need an API key available in our build. However, before we can publish, we need to compile our solution. Now what if we forgot to pass the API key? We certainly don’t want to wait until the publish target is executing to find out. We want our build to fail-fast. In NUKE, this works very nicely using Requires inside our fluent syntax:

If we call the publish target without providing a proper API key, we will get an error message like this:

We hope that parameter injection along with other fancy additions can help to improve, maintain and use build implementations more easily.

Check out NUKE! Feedback is always welcome! 🤗

So long, keep on building! 🤘🏻🏗