https://pulumi.com logo
Title
w

witty-vegetable-61961

06/16/2022, 7:02 PM
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

little-cartoon-10569

06/16/2022, 9:07 PM
Also, the Command package handles this correctly. https://www.pulumi.com/registry/packages/command/
w

witty-vegetable-61961

06/16/2022, 11:27 PM
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

little-cartoon-10569

06/17/2022, 12:31 AM
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

witty-vegetable-61961

06/17/2022, 1:04 PM
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

little-cartoon-10569

06/19/2022, 2:22 AM
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

witty-vegetable-61961

06/20/2022, 10:56 AM
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

little-cartoon-10569

06/20/2022, 8:46 PM
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

witty-vegetable-61961

06/21/2022, 10:01 PM
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

little-cartoon-10569

06/21/2022, 10:03 PM
apply is async. It is called when the thing being applied is resolved. This is correct.