Hi! How can I access my output from the azure pulu...
# azure
Hi! How can I access my output from the azure pulumi task in another task in the same release pipeline?
Basically you use the result of the
Copy code
pulumi stack output
@millions-journalist-34868 can I use the following approach to set it?
Console.WriteLine($"##vso[task.setvariable variable=FormExtractor;]{new StackReference("CI").GetOutput("FormExtractor").Apply(u=>u)}");
I can set a normal task level variable in the pipeline using this approach. However in this case although I can see the values with the o/p command it isn't set.
basically would like to know if there is an approach using C#
I don't understand exactly what you are trying to do. You have multiple pulumi tasks in your azure pipeline ? What is exactly your use case ?
I'm using a pulumi task to deploy our resources in an azure release pipeline
I have outputs defined in my C# code
[Output] public Output<string> FormExtractor { get; set; }
[Output] public Output<string> Orchestrator { get; set; }
[Output] public Output<string> ConfirmationApi { get; set; }
I'm trying to populate these with function app names
they are populated correctly and I can see them using
pulumi stack output
I want to use these 3 outputs in another task within the same stage in my release pipeline
I tried this
Console.WriteLine($"##vso[task.setvariable variable=FormExtractor;]{new StackReference("matchnetcloud-CI").GetOutput("FormExtractor").Apply(u => u)}");
but it only outputs
I would like it to write the correct value, which is the name of the function app
What you have to do is set Environment variables in your azure pipeline that correspond to your outputs. This way you will be able to use them in another task of your pipeline. That's exactly what the link I gave you do
But this is something to do in an azure pipeline taks not in pulumi in csharp
Copy code
- script: |
      echo "##vso[task.setvariable variable=resourceGroupName;isOutput=true]$(pulumi stack output resourceGroupName)"
      echo "##vso[task.setvariable variable=storageAccountName;isOutput=true]$(pulumi stack output storageAccountName)"
      echo "##vso[task.setvariable variable=containerName;isOutput=true]$(pulumi stack output containerName)"
this azure pipeline task set environment variable resourceGroupname, storageAccountName and containerName with their corresponding outputs from the pulumi task
once done you just have to use $(resourceGroupName) for instance in the azure pipeline task you need
i'm using the pulumi task extension
so does that mean I need to have a seperate script after that?
so that script would have to install pulumi etc..? is it?
This is the first time I'm trying to do this, so thanks for bearing up with my silly questions
No problem it's just I don't understand your need. You have a pulumi task in your azure pipeline : it will run, deploy your stack (provision your resources) and log your outputs automatically. Why do you need to have your outputs, what will you do with them in your pipeline ?
We only deploy the function apps, not the functions
so we want the function app names to deploy the functions in a later task
okay then you just need to add a script task which will get the outputs from the stack using the command
pulumi stack output
and set them in azure pipelines environment variables. you will then use this environment variables as parameter to your azure function deployment task
this script is just the one I copied to you, that is present in the pulumi documentation. It just call the pulumi command, take the result an put it in an environment variable. that's just it, your have nothing to do
error: no Pulumi.yaml project file found (searching upwards from D:\a\r1\a). If you have not created a project yet, use 
pulumi new
 to do so
probably I need to set some stuff in the bash script
You have to execute it in the folder where your pulumi project is
in order for it to find what is your stack
Maybe there is an easier to do that than using this script task but I can't see what. @tall-librarian-49374 any idea ?
I guess if the pulumi task had an option to automatically set environment variables corresponding to outputs names it would be easier.
I think using
pulumi stack output
would be the default suggestion. @rhythmic-vegetable-87369 your original snippet might work if you change the call from
which doesn’t look nice but returns a plain string, not an output.
cc the ADO task author @clever-sunset-76585
@tall-librarian-49374 That worked well locally. It reads correctly. In the pipeline it throws an error.
error: the current deployment has 1 resource(s) with pending operations:
2020-06-03T14:37:00.8712250Z   * urn:pulumi:CI::matchnetcloud::pulumi:pulumi:StackReference::CI, interrupted while reading
2020-06-03T14:37:00.8712946Z These resources are in an unknown state because the Pulumi CLI was interrupted while
2020-06-03T14:37:00.8713441Z waiting for changes to these resources to complete. You should confirm whether or not the
2020-06-03T14:37:00.8714068Z operations listed completed successfully by checking the state of the appropriate provider.
2020-06-03T14:37:00.8715290Z For example, if you are using AWS, you can confirm using the AWS Console.
2020-06-03T14:37:00.8716175Z Once you have confirmed the status of the interrupted operations, you can repair your stack
2020-06-03T14:37:00.8717238Z using 'pulumi stack export' to export your stack to a file. For each operation that succeeded,
2020-06-03T14:37:00.8718603Z remove that operation from the "pending_operations" section of the file. Once this is complete,
2020-06-03T14:37:00.8721480Z use 'pulumi stack import' to import the repaired stack.
2020-06-03T14:37:00.8778231Z refusing to proceed
Got it fixed
var stackReference = new StackReference($"{ Pulumi.Deployment.Instance.StackName }");
Console.WriteLine($"##vso[task.setvariable variable=Orchestrator;]{stackReference.GetValueAsync("Orchestrator").Result}");
Console.WriteLine($"##vso[task.setvariable variable=FormExtractor;]{stackReference.GetValueAsync("FormExtractor").Result}");
Console.WriteLine($"##vso[task.setvariable variable=ConfirmationApi;]{stackReference.GetValueAsync("ConfirmationApi").Result}");
@tall-librarian-49374 @*Alexandre Nedelec Thank you for all the help. Much appreciated.*
You're welcome. I also learn something, good to know that outputs can also be exported in env variables directly from C# code 🙂
@rhythmic-vegetable-87369 to extract outputs, an easy way without having to write the AzDO output statements in Pulumi app is to use a
task as @millions-journalist-34868 was eluding to above as well. See https://www.pulumi.com/docs/guides/continuous-delivery/azure-devops/#sample-azure-pipelines-yml for an example of how this is done. Here’s the part about defining output variables (https://www.pulumi.com/docs/guides/continuous-delivery/azure-devops/#user-defined-output-variables). Here’s the official AzDO docs page about defining variables https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&amp;tabs=yaml%2Cbatch#share-variables-across-pipelines
Glad you were able to solve it in another way too!
Hi @clever-sunset-76585, I'm trying to follow the link you point to in order to to get my Azure DevOps pipeline to output a Pulumi Output variable but can't get it to work. I am using an Azure Storage Account as my backend for Pulumi so I'm not sure if this is the cause of my problems. The Pulumi task itself to deploy the stack work well and after it runs I can manually run a pulumi stack output from my local development box and see the outputs have been correctly stored. If have no luck trying to access them from a script in my pipeline after the Pulumi task however. I run a pulumi login azblog://pulumi/<project> (which are the same login args I provide to the pulumi task that runs ok) but if I try to follow that with a pulumi stack ls I get an error [error listing stacks: could not list bucket: blob (code=NotFound)]. Any idea what could be going wrong?
Hi @mysterious-australia-14256, are you sure you are running the
pulumi stack ls
in the same folder where your
Pulumi.<stack name>.yaml
file exists, where
<stack name>
is your stack’s name?
Hi @clever-sunset-76585, yes I am doing a cd in to that before I run anything.
My guess is that it is an auth issue to the Azure backend but I'm not sure how to rectify that give I have the required environmental variables configured and they can certainly be accessed by the Pulumi Tasks. The Pulumi Up via a task runs and I can aslo ready the Output variable using a Pulumi Output task. It is only trying to access the via a script to make them available to other tasks in the pipeline that is failing
Are you able to send me your pipeline configuration via a DM?