by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Dalmiro Granas
@Dalmirog
image.png

Full Cake build:

  • Restore
  • Build
  • Create Octopus instance (optional)
  • FIll up with data (optional)
  • Run tests (optional)
  • Remove Octopus instance (optional)

Took it from 7-8min to 2:50 :tada:

Dalmiro Granas
@Dalmirog

:tada: We have on official first draft of the contributing guide :tada:

https://github.com/Dalmirog/OctoPosh/blob/master/CONTRIBUTING.md

Still a WIP of cours

ping @kneumei who asked about this weeks ago
Kyle Neumeier
@kneumei
Thanks @Dalmirog
Dalmiro Granas
@Dalmirog

All feedback about it is welcome.

I still haven explained the whole Cake.Build process, but that's because I'm still working on it.

KSchiss
@KSchiss
Newbie question: I would like to use Get-OctopusMachine to output a list of machines (their Display Name) in any given environment to the screen in a single file column.
Dalmiro Granas
@Dalmirog

So just their names and nothing else?

You want the output on the console screen or on a file?

KSchiss
@KSchiss
just the display name, output to screen or file, whatever is easier :)
I swear i did this before, but maybe I used octo.exe... i can't remember
Dalmiro Granas
@Dalmirog
Get-OctopusMachine | select -ExpandProperty Name
or depending on your connection, this could be a bit faster: Get-OctopusMachine -ResourceOnly | select -ExpandProperty Name
KSchiss
@KSchiss
How cool is that.... thank you sir!
Dalmiro Granas
@Dalmirog
No problem!
James Dawson
@JamesDawson
Hi @Dalmirog thanks for your efforts on this project. I'm feeling the pain creating mock domain objects in my pester tests... just wondering what your thoughts were on adding some cmdlets to simplify this? Is that a PR you'd be interested in?
Dalmiro Granas
@Dalmirog
Hi @JamesDawson . Exactly how are you trying to create and use these objects in your pester tests?
Dalmiro Granas
@Dalmirog
If you want to ping me the pester test and try to explain what are you trying to assert
James Dawson
@JamesDawson
As some background, I'm automating a process for updating variable sets with various logic (which I want test coverage for). The tests themselves aren't the problem, it's just the verbose nature of using powershell to create the .NET objects needed when mocking-out calls that would otherwise get their data from the Octopus server (e.g. Get-OctopusVariableSet). Here's a gist of doing it for a variableset object, it's not complete but it will give you the idea: https://gist.github.com/JamesDawson/54a09171911403e4bb68c8bd292031e7 Whilst I could write a bunch of functions to do this, it just struck me that it would be way more efficient to write all the instantiation code in C#... unless I'm missing something and there is already an easier way?
Dalmiro Granas
@Dalmirog

This snippet should work

https://gist.github.com/Dalmirog/e642cab7c157d9497b20202aa4baeb33

In your code I can see you are creating some objects from the Octoposh namespace. You should never do that, as the Octoposh objects are just translations of the actual Octopus objects for the human eyes.

If you want to create/update/delete anything in Octopus, you need to use Octopus objects.

See how in line 13 I'm passing -resourceOnly? That tells the cmdlet to return the actual Octopus resource, instead of the Octoposh object. Later on I add the variable (again an Octopus object, this time of the type Octopus.client.model.variableResource) to the Octopus resource, and finally I pass the variable set Octopus object ($variableSet) to Update-OctopusResource
I realize that the meaning behind the -resourceOnly parameter is super importante and a bit obscure atm. I've been trying to write documentation about it for ages but I always forget. I'll try to get it done this week.
I even have a github issue open for it #157
James Dawson
@JamesDawson
Thanks for the detailed reply @Dalmirog . I had realised the difference between the OctoPosh and Octopus objects, I currently use the .Resource property when updating the server. However, I hadn't noticed the Get-OctopusResourceModel cmdlet which will simplify creating my mock objects if I change my script to use -ResourceOnly throughout. Many thanks for the pointer.
Dalmiro Granas
@Dalmirog
Glad I could help @JamesDawson :)
James Dawson
@JamesDawson
Hi @Dalmirog , I got something going though not quite how I intended, but its working well enough... I've sent a PR with some minor tweaks to Get-OctopusResourceModel that made life easier when using it to create the test data objects I was talking about above... see what you think.
KSchiss
@KSchiss
image.png
Hello @Dalmirog - have another newbie question for you. I'm using your syntax to move some machines from one environment to the other, and it doesn't seem to like Environments with spaces in them. I have tried putting quotes in a few places, but the script errors at the Get-OctopusEnvironment statement . (See above) Any suggestions?
Dalmiro Granas
@Dalmirog
@JamesDawson I'll be reviewing it sometime this week. I'm doing a big refactor with some help of a teammate that knows a ton more about C# than I do :)
Dalmiro Granas
@Dalmirog
@KSchiss Hi there. I can't see anything wrong in that code at simple glance. I even tested the same thing on my end and it works.
image.png
I'm gonna ping you privately here on gitter to ask you for some info about your environment
Dalmiro Granas
@Dalmirog
@JamesDawson I reviewed the PR since it was super small :)
Dalmiro Granas
@Dalmirog

As for the addition of VariableSetResource: In Octopus a VariableSetResource is a type of object that holds a collection of variables. This VariableSetResource can belong to 2 other different kinds of objects:

1 - a ProjectResource

2 - a LibraryVariableSetResource

A VariableSetResource object doesn't exist by itself, but only as a child object of these 2. Therefore the only organic way to create a VariableSetResource must be through the creation of either a ProjectResource or a LibraryVariableSet resource.

For that reason in the snippet I gave you in line 10 I'm creating a LibraryVariableSet, and then in line 13 I'm getting the VariableSetResource that was associated with the LibraryVariableSet that I previously created. I'm never directly creating a VariableSetResource.

I'm afraid that if the module gives users the ability to create orphan an VariableSetResource , It'll confuse more ppl than it would help. Advanced users such as yourself should be able to work around this by creating a VariableSetResource using raw powershell like new-object Octopus.Client.Model.VariableSet

That said, I'm curious of how are you setting up your tests in a way that you need to create an orphan VariableSetResource like this.

Does that make sense to you?
James Dawson
@JamesDawson
I get what you're saying, personally I'd just like a consistent way of writing these scripts as it makes it easier for others to follow. Octopus has an API endpoint that allows you to update a VariableSetResource object directly (/api/variables) so I don't see it has inherently wrong - presumably the API has consistency checks to ensure that the 'OwnerId' property is valid to avoid actual orphans?.
In terms of helping new or less experienced users, I was wondering whether having a set of New-* cmdlets would be an effective way of leading them into the 'pit of success' of only creating the right types objects?
James Dawson
@JamesDawson
As to the specifics of my scenario... I needed to unit test some code that contained a call to Update-OctopusResource - mocking a function in Pester doesn't override its parameter validation so when I attempted to use my original mock object (a hashtable that mimicked the required properties), it didn't match the required type Octopus.Client.Mode.Resource.
James Dawson
@JamesDawson
As you say, this is hardly a core scenario and there are multiple ways around it one way or another... so you need to do whatever you're most comfortable with for the project as a whole. Thanks for your responsiveness.
jigneshjdesai
@jigneshjdesai
@Dalmirog any example on how to delete releases? I am trying Remove-OctopusResource -Resource $release but it is throwing error Remove-OctopusResource : Cannot bind parameter 'Resource'. Cannot convert the "Octoposh.Model.OutputOctopusRelease" value of type
"Octoposh.Model.OutputOctopusRelease" to type "Octopus.Client.Model.Resource".
jigneshjdesai
@jigneshjdesai
@jigneshjdesai
@Dalmirog any example on how to delete releases? I am trying Remove-OctopusResource -Resource $release but it is throwing error Remove-OctopusResource : Cannot bind parameter 'Resource'. Cannot convert the "Octoposh.Model.OutputOctopusRelease" value of type
"Octoposh.Model.OutputOctopusRelease" to type "Octopus.Client.Model.Resource". hey @Dalmirog not sure if you had chance to look into this. Appreciate your help.
ConwayO
@ConwayO
@Dalmirog , Is there any reason why the Powershell Module New-OctopusAPIKey isn't available in the latest Octoposh Build : 0.6.11? I have been able to Load up the Module in Powershell, but would obviously prefer that it be included in a future build. Kind Regards
ConwayO
@ConwayO
@Dalmirog Is there a way to retrieve all Deploy Environments that does not force Octopus deploy to Skip 10 Environments when sourcing the Required Environment?
@Dalmirog is there a way to interact with the api directly, using custom calls without the use of the defined octoposh methods? (Maintaining the authentication)
Dalmiro Granas
@Dalmirog

@jigneshjdesai remove-OctopusResource doesn't currently delete releases. I'm on a bus right now so can't get into the specifics of why, but the recommendation would be to use octo.exe delete-release.

I can give you the full explanation later tonight :)

Dalmiro Granas
@Dalmirog

@ConwayO

New-OctopusAPIKey - I simply didn't port this cmdlet after porting things to C#. I have #259 open for it. I'll do it this week as I've been asked about it quite enough :)

Environment question - Not sure Im following this one. Which cmdlet are you running and what you mean by "skip 10"

calling API directly - Yes you can run $c = new-Octopusconnection. Then you could do $c.repository.projects.findall() for example to get all the projects. $c will be an object that holds an authenticated connection with your Octopus instance. Is this what you needed?

@jigneshjdesai about using Octo.exe delete-releases, here's do documentation for it: https://octopus.com/docs/api-and-integration/octo.exe-command-line/deleting-releases

Remember that you can download Octo.exe using Octoposh as explained here: http://octoposh.readthedocs.io/en/latest/advancedexamples/running-deployments-with-octoposh/

ConwayO
@ConwayO
image.png
@Dalmirog Thank you for your Speedy response, New-OctopusKey would be awesome! , In terms of the environment question, please see image attached
On a side note, is there any way you know of to Use the AD Credentials for User / Password Login, instead of having to prompt the user continuously.