Hi all, I wrote a bit of code in my c# pulumi prog...
# getting-started
w
Hi all, I wrote a bit of code in my c# pulumi program to execute a console app on apply of a variable (To get the variable into another system). However, I noticed that on a preview, this code executes (understandably, as its in the flow). How can I stop this so that the method is only called on an apply?
ah there's an "isdryrun" flag
l
Also, the Command package handles this correctly. https://www.pulumi.com/registry/packages/command/
w
I need some assistence with this. At the moment, I have a method in my pulumi program that uses the command provider, to invoke a program. The name of the command is "random", but it is invoked in a loop. What should the name be? Also, my exe is on the system path (Windows), but i keep getting this error: KillerGaming.Utilities.OctopusDeployVariablesPusher.exe
outside of pulumi the exe is accessible from anywhere ie c:\
think that's fixed, i will assign a guid in the code to fix the duplicate issue
hmm no, still get the error that the command line cant be found. I set the working dir in the command code to the folder contianing my exe?
l
Do you copy the exe to the target machine? Or do you run it locally, and it operates on the target machine?
You need to choose between local.Command and remote.Command.
w
ah do you know the exact object? in c#
this should be local as the command runs on the same server doing the pulumi
i changed to use local command in my code but same thing. I am thinking need to pass in an environment variable?
l
I would need to see the problematic code to understand what's going on. And I'd need a better explanation of what you want to have happen.
w
string arguments = string.Join(" ", "S.exe", variableName, value, projectName, env);
//string exePath = @"S.exe";
var command = new Pulumi.Command.Local.Command (Guid.NewGuid().ToString(), new Pulumi.Command.Local.CommandArgs
{
Dir = @"C:\Repos\",
Create = arguments
}) ;
See above. I've taken out parts of paths to reduce length. The idea is to call that exe, which then does its job (pushes variables into octpus deploy).
ok this works if I use the .NET classes to invoke an exe. Maybe I will go that way, just need to work out why I get an error from Octopus.
l
One problem is the name of the command. It is different each time you run it, which means it's destroying the old command and creating a new one. But that's not the path problem.
w
I've got this working, although not using the command library, but a method that calls the Octopus API (taken out the external console tool). My challenge is understanding the async nature of the apply method. In my callback, a console line is written stating "A" and then towards the end "B". I'd expect output like: A B A B A B Instead, I get: A A A B B
B
It seems like multiple threads run on the Apply callback. Is there an explanation for this? The good news is my Pulumi program works end-to-end and it is satisfying to see. 🙂
l
apply is async. It is called when the thing being applied is resolved. This is correct.