-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose current build job in Enter-BuildJob #185
Comments
It looks like an original and useful technique. I'll take a look indeed. Out of curiosity, how do you define such custom attributes, right in PowerShell or module or something else? |
We define them in Powershell directly, by writing classes that inherit from System.Attribute; Powershell makes them available via properties on the automation scriptblock object, eg. UsesTerraform.ps1
build.ps1
then Enter-BuildJob as above. |
This is really cool. I'd like to play with this and publish the topic in the IB collection https://github.com/nightroman/Invoke-Build/tree/master/Tasks#readme But at first, implement your request :) |
UPDATE: see v5.8.3 below v5.8.2 I'll add tests and the topic later but the change looks straightforward and reasonable, done. |
The topic and its test was added. |
v5.8.4 After some thinking, the public / automatic variable |
While would I use this over functions? Anything I miss here ? Semantics of invocation is a little bit different but that can be also done with functions and xxx-BuildJob hooks.
|
@majkinetor I think in most cases functions will do. But the example I provided here https://github.com/nightroman/Invoke-Build/tree/master/Tasks/Attributes shows that attributes provide more than just actions in the beginning. In any case exposing |
Our use case is somewhat specific, but this feature is very useful to us: we use Invoke-Build as a software platform, not just a single-project build system. We have built our infrastructure-as-code system around Terraform declarations and Invoke-Build processing. This means we have an ever-growing collection of tasks, as every task wraps a semantic portion of our cloud resources. As such, attributes allow us to semantically mark every task. As they are parsed/executed before the task starts, they allow to clearly set the stage before a task runs, and to be combined (important point), which is something functions can't do gracefully (granted, the example above was over-simplified). As the attributes are parsed at job start time, we can process the entire set and use some of them to affect others. Think of something like: sometask { This would do:
THEN the task code starts. It allows the task code to be free of setup code and to have the context clearly marked, making sure that Terraform folks only concentrate on Terraform code while framework folks code all the required support around them. |
@jfpoirier-x2o thanx for detailed explanation, definitely makes much more sense now. Looks like really neat solution. |
We use scriptblock attributes in task definitions to enable easy code reuse, such as
Enter-BuildJob is the ideal spot to process the scriptblock's attributes and run them, but it needs to be supplied with the current job for this to work. At this time, it is called without passing the current job (stored in ${*j}), and we have to break encapsulation to hijack ${*j} and access the attributes, eg
The text was updated successfully, but these errors were encountered: