Unpacking Software Livestream

Join our monthly Unpacking Software livestream to hear about the latest news, chat and opinion on packaging, software deployment and lifecycle management!

Learn More

Chocolatey Product Spotlight

Join the Chocolatey Team on our regular monthly stream where we put a spotlight on the most recent Chocolatey product releases. You'll have a chance to have your questions answered in a live Ask Me Anything format.

Learn More

Chocolatey Coding Livestream

Join us for the Chocolatey Coding Livestream, where members of our team dive into the heart of open source development by coding live on various Chocolatey projects. Tune in to witness real-time coding, ask questions, and gain insights into the world of package management. Don't miss this opportunity to engage with our team and contribute to the future of Chocolatey!

Learn More

Calling All Chocolatiers! Whipping Up Windows Automation with Chocolatey Central Management

Webinar from
Wednesday, 17 January 2024

We are delighted to announce the release of Chocolatey Central Management v0.12.0, featuring seamless Deployment Plan creation, time-saving duplications, insightful Group Details, an upgraded Dashboard, bug fixes, user interface polishing, and refined documentation. As an added bonus we'll have members of our Solutions Engineering team on-hand to dive into some interesting ways you can leverage the new features available!

Watch On-Demand
Chocolatey Community Coffee Break

Join the Chocolatey Team as we discuss all things Community, what we do, how you can get involved and answer your Chocolatey questions.

Watch The Replays
Chocolatey and Intune Overview

Webinar Replay from
Wednesday, 30 March 2022

At Chocolatey Software we strive for simple, and teaching others. Let us teach you just how simple it could be to keep your 3rd party applications updated across your devices, all with Intune!

Watch On-Demand
Chocolatey For Business. In Azure. In One Click.

Livestream from
Thursday, 9 June 2022

Join James and Josh to show you how you can get the Chocolatey For Business recommended infrastructure and workflow, created, in Azure, in around 20 minutes.

Watch On-Demand
The Future of Chocolatey CLI

Livestream from
Thursday, 04 August 2022

Join Paul and Gary to hear more about the plans for the Chocolatey CLI in the not so distant future. We'll talk about some cool new features, long term asks from Customers and Community and how you can get involved!

Watch On-Demand
Hacktoberfest Tuesdays 2022

Livestreams from
October 2022

For Hacktoberfest, Chocolatey ran a livestream every Tuesday! Re-watch Cory, James, Gary, and Rain as they share knowledge on how to contribute to open-source projects such as Chocolatey CLI.

Watch On-Demand

Downloads:

11,944

Downloads of v 0.0.27:

458

Last Update:

21 Mar 2015

Package Maintainer(s):

Software Author(s):

  • Chris Dostert

Tags:

powershell poshdevops taskrunner ci continuousintegration build deployment admin

PoshDevOps

This is not the latest version of PoshDevOps available.

  • 1
  • 2
  • 3

0.0.27 | Updated: 21 Mar 2015

Downloads:

11,944

Downloads of v 0.0.27:

458

Maintainer(s):

Software Author(s):

  • Chris Dostert

PoshDevOps 0.0.27

This is not the latest version of PoshDevOps available.

  • 1
  • 2
  • 3

Some Checks Have Failed or Are Not Yet Complete

Not All Tests Have Passed


Validation Testing Unknown


Verification Testing Unknown


Scan Testing Successful:

No detections found in any package files

Details
Learn More

Deployment Method: Individual Install, Upgrade, & Uninstall

To install PoshDevOps, run the following command from the command line or from PowerShell:

>

To upgrade PoshDevOps, run the following command from the command line or from PowerShell:

>

To uninstall PoshDevOps, run the following command from the command line or from PowerShell:

>

Deployment Method:

NOTE

This applies to both open source and commercial editions of Chocolatey.

1. Enter Your Internal Repository Url

(this should look similar to https://community.chocolatey.org/api/v2/)


2. Setup Your Environment

1. Ensure you are set for organizational deployment

Please see the organizational deployment guide

2. Get the package into your environment

  • Open Source or Commercial:
    • Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://community.chocolatey.org/api/v2/. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
    • You can also just download the package and push it to a repository Download

3. Copy Your Script

choco upgrade poshdevops -y --source="'INTERNAL REPO URL'" --version="'0.0.27'" [other options]

See options you can pass to upgrade.

See best practices for scripting.

Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.

If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:


choco upgrade poshdevops -y --source="'INTERNAL REPO URL'" --version="'0.0.27'" 
$exitCode = $LASTEXITCODE

Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
  Exit 0
}

Exit $exitCode

- name: Install poshdevops
  win_chocolatey:
    name: poshdevops
    version: '0.0.27'
    source: INTERNAL REPO URL
    state: present

See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.


chocolatey_package 'poshdevops' do
  action    :install
  source   'INTERNAL REPO URL'
  version  '0.0.27'
end

See docs at https://docs.chef.io/resource_chocolatey_package.html.


cChocoPackageInstaller poshdevops
{
    Name     = "poshdevops"
    Version  = "0.0.27"
    Source   = "INTERNAL REPO URL"
}

Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.


package { 'poshdevops':
  ensure   => '0.0.27',
  provider => 'chocolatey',
  source   => 'INTERNAL REPO URL',
}

Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.


4. If applicable - Chocolatey configuration/installation

See infrastructure management matrix for Chocolatey configuration elements and examples.

Package Approved

This package was approved as a trusted package on 24 Apr 2015.

Description

PowerShell driven distributed DevOps

Installation notes:
- installs to: C:\ProgramFiles\PoshDevOps
- appends C:\ProgramFiles\PoshDevOps\Modules to PSModulePath environment variable


tools\.git\config
 
tools\.git\description
 
tools\.git\HEAD
 
tools\.git\hooks\applypatch-msg.sample
 
tools\.git\hooks\commit-msg.sample
 
tools\.git\hooks\post-update.sample
 
tools\.git\hooks\pre-applypatch.sample
 
tools\.git\hooks\pre-commit.sample
 
tools\.git\hooks\pre-push.sample
 
tools\.git\hooks\pre-rebase.sample
 
tools\.git\hooks\prepare-commit-msg.sample
 
tools\.git\hooks\update.sample
 
tools\.git\index
 
tools\.git\info\exclude
 
tools\.git\logs\HEAD
 
tools\.git\logs\refs\heads\master
 
tools\.git\logs\refs\remotes\origin\HEAD
 
tools\.git\objects\pack\pack-f2c1c57a81f4ada0ba89781b090253577ed1fc30.idx
 
tools\.git\objects\pack\pack-f2c1c57a81f4ada0ba89781b090253577ed1fc30.pack
 
tools\.git\packed-refs
 
tools\.git\refs\heads\master
 
tools\.git\refs\remotes\origin\HEAD
 
tools\.gitignore
 
tools\Src\Uninstall.ps1
# remove source
$installRootDirPath = "C:\Program Files\PoshDevOps"
$installDirPath = "$installRootDirPath\Modules"

# make idempotent
if(Test-Path "$installRootDirPath"){
    Remove-Item $installRootDirPath -Force -Recurse
}

# remove $PSModulePath modification
$psModulePath = [Environment]::GetEnvironmentVariable('PSModulePath','Machine')

$newPSModulePathParts = @();
$isPSModulePathModified = $false
foreach($part in $psModulePath.Split(';')){
    if($part -eq $installDirPath){
        $isPSModulePathModified = $true
    }
    else{
        $newPSModulePathParts += $part;        
    }
}

$psModulePath = $newPSModulePathParts -join ';'

if($isPSModulePathModified){
    Write-Debug "updating '$env:PSModulePath' to $psModulePath"

    # save
    [Environment]::SetEnvironmentVariable('PSModulePath',$psModulePath,'Machine')
}
tools\Src\Templates\TaskGroup.psd1
 
tools\Src\PsonConverters.ps1
Set-Alias ConvertFrom-Pson Invoke-Expression -Description "Convert variable from PSON"


Function ConvertTo-Pson(
[Parameter(
    ValueFromPipeline=$true)]
$InputObject, 
[Int]
$Depth = 9, 
[Int]
$Layers = 1,
[Switch]
$Strict) {
<#
    .LINK http://stackoverflow.com/questions/15139552/save-hash-table-in-powershell-object-notation-pson
#>

    $Format = $Null
    $Quote = If ($Depth -le 0) {""} Else {""""}
    $Space = If ($Layers -le 0) {""} Else {" "}

    If ($InputObject -eq $Null) {"`$Null"} Else {
        
        $Type = "[" + $InputObject.GetType().Name + "]"

        $PSON = If ($InputObject -is [Array]) {
            
            $Format = "@(", ",$Space", ")"
            
            If ($Depth -gt 1) {

                For ($i = 0; $i -lt $InputObject.Count; $i++) {

                    ConvertTo-PSON $InputObject[$i] ($Depth - 1) ($Layers - 1) -Strict:$Strict

                }
            
            }

        } ElseIf ($InputObject -is [Xml]) {

            $Type = "[Xml]"
            $String = New-Object System.IO.StringWriter
            $InputObject.Save($String)
            $Xml = "'" + ([String]$String).Replace("`'", "&apos;") + "'"
            If ($Layers -le 0) {
            
                ($Xml -Replace "\r\n\s*", "") -Replace "\s+", " "

            } ElseIf ($Layers -eq 1) {

                $Xml
            
            } Else {
            
                $Xml.Replace("`r`n", "`r`n`t")
            
            }

            $String.Dispose()

        } ElseIf ($InputObject -is [DateTime]) {

            "$Quote$($InputObject.ToString('s'))$Quote"
        
        } ElseIf ($InputObject -is [String]) {

            0..11 | ForEach {$InputObject = $InputObject.Replace([String]"```'""`0`a`b`f`n`r`t`v`$"[$_], ('`' + '`''"0abfnrtv$'[$_]))}; "$Quote$InputObject$Quote"
        
        } ElseIf ($InputObject -is [Boolean]) {

            "`$$InputObject"
        
        } ElseIf ($InputObject -is [Char]) {
            
            If ($Strict) {[Int]$InputObject} Else {"$Quote$InputObject$Quote"}

        } ElseIf ($InputObject -is [ValueType]) {

            $InputObject

        } ElseIf ($InputObject -as [Hashtable]){

            if($InputObject -is [System.Collections.Specialized.OrderedDictionary]){              
                $Type = "[Ordered]"  
            }
            
            $Format = "@{", ";$Space", "}"
            
            If ($Depth -gt 1){

                $InputObject.GetEnumerator() | ForEach {$_.Name + "$Space=$Space" + (ConvertTo-PSON $_.Value ($Depth - 1) ($Layers - 1) -Strict:$Strict)}
            
            }
        } ElseIf ($InputObject -is [Object]) {

            $Format = "@{", ";$Space", "}"

            If ($Depth -gt 1) {

                $InputObject.PSObject.Properties | ForEach {$_.Name + "$Space=$Space" + (ConvertTo-PSON $_.Value ($Depth - 1) ($Layers - 1) -Strict:$Strict)}
            
            }
        
        } Else {

            $InputObject
        
        }

        If ($Format) {

            $PSON = $Format[0] + (&{

                If (($Layers -le 1) -or ($PSON.Count -le 0)) {

                    $PSON -Join $Format[1]
                
                } Else {
                
                    ("`r`n" + ($PSON -Join "$($Format[1])`r`n")).Replace("`r`n", "`r`n`t") + "`r`n"
                
                }
            
            }) + $Format[2]
        
        }

        If ($Strict) {
            "$Type$PSON"
        } Else {
            "$PSON"
        }
    }
}



tools\LICENSE
 
tools\Docs\Variables.md
###1 Configurable Parameters
When developing a DevOps task that requires/allows configuration, add parameters to your Invoke-PoshDevOpsTask method signature with type `string` and any desired name (excluding names beginning with PoshDevOps which is reserved for Automatic Parameters).

Example:
```PowerShell
function Invoke-PoshDevOpsTask(
[string][Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]$CustomParam1,
[string][Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]$CustomParam2)
{
    # implementation snipped...
}

```

###2 Automatic Parameters
PoshDevOps will automatically populate certain DevOps task parameters, the names of which always start with the prefix `PoshDevOps`.
These parameters provide information about the executing task group/DevOps task. 

To use automatic parameters, add parameters matching the type and name of defined automatic parameters to your Invoke-PoshDevOpsTask method signature and PoshDevOps will populate them at invocation time.

Example:
```PowerShell
function Invoke-PoshDevOpsTask(
[string][Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]$PoshDevOpsProjectRootDirPath,
[string][Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]$PoshDevOpsTaskName)
{
    # implementation snipped...
}

```

#####2.1 [string]$PoshDevOpsProjectRootDirPath
Always available;equals the project root dir path of the currently executing task group

#####2.2 [string]$TaskName
Always available;equals the name of the currently executing DevOps task
tools\Docs\QuickStart.md
From your source root:
```PowerShell
PoshDevOps\New-Build
```
tools\Docs\Index.md
* [QuickStart](./QuickStart.md)
tools\Docs\DesignGuidelines.md
#Project Guidelines

##Feature Design
When designing features:

1.	All features must support both interactive and non-interactive consumption via PowerShell. 


##Development

####1 General
#####1.1 Follow MSDN Guidelines
PowerShell usage must be consistent with, [MSDN guidelines](https://msdn.microsoft.com/en-us/library/dd835506(v=vs.85).aspx). (some useful links within those guidelines are: [Module Installation](https://msdn.microsoft.com/en-us/library/dd878350%28v=vs.85%29.aspx), [Command naming](https://msdn.microsoft.com/en-us/library/ms714428%28v=vs.85%29.aspx), [Standard Cmdlet parameter Names and Types](https://msdn.microsoft.com/en-us/library/dd878352(v=vs.85).aspx)

####2 CI-Tasks
#####2.1 Use string[] For Parameters Being Passed To Things Outside Powershell
When defining a DevOps task, if a parameter will be used asa pass-through to something outside Powershell (example: invoking a .exe), make the parameter of type string[]. For a great background on why see [powershell-call-operator-using-an-array-of-parameters-to-solve-all-your-quoting-problems](https://com2kid.wordpress.com/2011/09/25/powershell-call-operator-using-an-array-of-parameters-to-solve-all-your-quoting-problems/)
tools\.PoshDevOps\TaskGroup.psd1
 
tools\.PoshDevOps\Packages\CreateChocolateyPackage.0.0.21\tools\CreateChocolateyPackage\CreateChocolateyPackage.psm1
# halt immediately on any errors which occur in this module
$ErrorActionPreference = "Stop"

function EnsureChocolateyInstalled(
[String]
[ValidateNotNullOrEmpty()]
$PathToChocolateyExe){
    # install chocolatey
    try{
        Get-Command $PathToChocolateyExe -ErrorAction Stop | Out-Null
    }
    catch{             
        iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
    }   
}

function Invoke-PoshDevOpsTask(

[String]
[ValidateNotNullOrEmpty()]
[Parameter(
    Mandatory=$true,
    ValueFromPipelineByPropertyName=$true)]
$PoshDevOpsProjectRootDirPath,

[String[]]
[ValidateCount(1,[Int]::MaxValue)]
[Parameter(
    ValueFromPipelineByPropertyName = $true)]
$IncludeNuspecPath = @(gci -Path $PoshDevOpsProjectRootDirPath -File -Filter '*.nuspec' -Recurse | %{$_.FullName}),

[String[]]
[Parameter(
    ValueFromPipelineByPropertyName = $true)]
$ExcludeNuspecNameLike,

[Switch]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$Recurse,

[String]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$OutputDirectoryPath,

[String]
[Parameter(
    ValueFromPipelineByPropertyName = $true)]
$Version,

[String]
[ValidateNotNullOrEmpty()]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$PathToChocolateyExe = 'C:\ProgramData\chocolatey\bin\chocolatey.exe'){

    EnsureChocolateyInstalled -PathToChocolateyExe $PathToChocolateyExe

    $NuspecFilePaths = gci -Path $IncludeNuspecPath -Filter '*.nuspec' -File -Exclude $ExcludeNuspecNameLike -Recurse:$Recurse | ?{!$_.PSIsContainer} | %{$_.FullName}

Write-Debug `
@"
`Located .nuspec's:
$($NuspecFilePaths | Out-String)
"@

    if($OutputDirectoryPath){
        Push-Location ( Resolve-Path $OutputDirectoryPath)        
    }
    else{            
        Push-Location (Get-Location)       
    }

Write-Debug  `
@"
output directory is:
$OutputDirectoryPath
"@

    foreach($nuspecFilePath in $NuspecFilePaths)
    {
    
        $chocolateyParameters = @('pack',$nuspecFilePath)
        
        if($Version){
            $chocolateyParameters += @('-version',$Version)
        }

Write-Debug `
@"
Invoking choco:
& $PathToChocolateyExe $($chocolateyParameters|Out-String)
"@
        & $PathToChocolateyExe $chocolateyParameters

        # handle errors
        if ($LastExitCode -ne 0) {
            throw $Error
        }
    }

    # revert location
    Pop-Location
}

Export-ModuleMember -Function Invoke-PoshDevOpsTask 
tools\Src\PoshDevOps.psm1
Write-Debug "Dot Sourcing $PSScriptRoot\PsonConverters.ps1"
. "$PSScriptRoot\PsonConverters.ps1"

$defaultPackageSources = @('https://www.myget.org/F/poshdevops')

function EnsureNuGetInstalled(){
    try{
        Get-Command nuget -ErrorAction Stop | Out-Null
    }
    catch{
Write-Debug "installing nuget.commandline"
        chocolatey install nuget.commandline | Out-Null
    }
}

function Get-PoshDevOpsTaskGroup(
[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){
    <#
        .SYNOPSIS
        parses a task group file
    #>

    $taskGroupFilePath = Resolve-Path "$ProjectRootDirPath\.PoshDevOps\TaskGroup.psd1"   
Write-Output (Get-Content $taskGroupFilePath | Out-String | ConvertFrom-Pson)

}

function Save-TaskGroup(
[PsCustomObject]
$TaskGroup,

[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){
    <#
        .SYNOPSIS
        an internal utility function to snapshot and save a TaskGroup to disk
    #>
    
    $taskGroupFilePath = Resolve-Path "$ProjectRootDirPath\.PoshDevOps\TaskGroup.psd1"    
    Set-Content $taskGroupFilePath -Value (ConvertTo-Pson -InputObject $TaskGroup -Depth 12 -Layers 12 -Strict)
}

function Get-UnionOfHashtables(
[Hashtable]
[ValidateNotNull()]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$Source1,

[Hashtable]
[ValidateNotNull()]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$Source2){
    $destination = $Source1.Clone()
    Write-Debug "After adding `$Source1, destination is $($destination|Out-String)"

    $Source2.GetEnumerator() | ?{!$destination.ContainsKey($_.Key)} |%{$destination[$_.Key] = $_.Value}
    Write-Debug "After adding `$Source2, destination is $($destination|Out-String)"

    Write-Output $destination
}

function Get-IndexOfKeyInOrderedDictionary(
[string]
[ValidateNotNullOrEmpty()]
$Key,

[System.Collections.Specialized.OrderedDictionary]
[ValidateNotNullOrEmpty()]
$OrderedDictionary){
    <#
        .SYNOPSIS
        an internal utility function to find the index of a key in an ordered dictionary
    #>

    $indexOfKey = -1
    $keysArray = [string[]]$OrderedDictionary.Keys
    for ($i = 0; $i -lt $OrderedDictionary.Count; $i++){
        if($keysArray[$i] -eq $Key){
            $indexOfKey = $i
            break
        }
    }

Write-Output $indexOfKey
}

function Get-LatestPackageVersion(

[string[]]
[Parameter(
    Mandatory=$true)]
$PackageSources = $defaultPackageSources,

[string]
[ValidateNotNullOrEmpty()]
[Parameter(
    Mandatory=$true)]
$PackageId){
    
    $versions = @()

    foreach($packageSource in $PackageSources){
        $uri = "$packageSource/api/v2/package-versions/$PackageId"
Write-Debug "Attempting to fetch package versions:` uri: $uri "
        $versions = $versions + (Invoke-RestMethod -Uri $uri)
Write-Debug "response from $uri was: ` $versions"
    }
    if(!$versions -or ($versions.Count -lt 1)){
throw "no versions of $PackageId could be located.` searched: $PackageSources"
    }

Write-Output ([Array]($versions| Sort-Object -Descending))[0]
}

function Add-PoshDevOpsTask(
[CmdletBinding(
    DefaultParameterSetName="add-TaskLast")]

[string]
[ValidateNotNullOrEmpty()]
[Parameter(
    Mandatory=$true)]
$Name,

[string]
[Parameter(
    Mandatory=$true)]
$PackageId,

[string]
$PackageVersion,

[switch]
[Parameter(
    Mandatory=$true,
    ParameterSetName='add-TaskFirst')]
$First,

[switch]
[Parameter(
    ParameterSetName='add-TaskLast')]
$Last,

[string]
[Parameter(
    Mandatory=$true,
    ParameterSetName='add-TaskAfter')]
$After,

[string]
[Parameter(
    Mandatory=$true,
    ParameterSetName='add-TaskBefore')]
$Before,

[string[]]
$PackageSources=$defaultPackageSources,

[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){

    <#
        .SYNOPSIS
        Adds a new task to a task group
        
        .EXAMPLE
        Add-PoshDevOpsTask -Name "LastTask" -PackageId "DeployNupkgToAzureWebsites" -PackageVersion "0.0.3"
        
        Description:

        This command adds a task (named LastTask) after all existing tasks

        .EXAMPLE
        Add-PoshDevOpsTask -Name "FirstTask" -PackageId "DeployNupkgToAzureWebsites" -First

        Description:

        This command adds a task (named FirstTask) before all existing tasks

        .EXAMPLE
        Add-PoshDevOpsTask -Name "AfterSecondTask" -PackageId "DeployNupkgToAzureWebsites" -After "SecondTask"

        Description:

        This command adds a task (named AfterSecondTask) after the existing task named SecondTask

        .EXAMPLE
        Add-PoshDevOpsTask -Name "BeforeSecondTask" -PackageId "DeployNupkgToAzureWebsites" -Before "SecondTask"

        Description:

        This command adds a task (named BeforeSecondTask) before the existing task named SecondTask

    #>

    $taskGroup = Get-PoshDevOpsTaskGroup -ProjectRootDirPath $ProjectRootDirPath
    
    if($taskGroup.Tasks.Contains($Name)){

throw "A task with name $Name already exists.`n Tip: You can remove the existing task by invoking Remove-PoshDevOpsTask"
            
    }
    else{
        
        if([string]::IsNullOrWhiteSpace($PackageVersion)){
            $PackageVersion = Get-LatestPackageVersion -PackageSources $PackageSources -PackageId $PackageId
Write-Debug "using greatest available module version : $PackageVersion"
        }


        $key = $Name
        $value = [PSCustomObject]@{'Name'=$Name;'PackageId'=$PackageId;'PackageVersion'=$PackageVersion}

        if($First.IsPresent){
        
            $taskGroup.Tasks.Insert(0,$key,$value)
        
        }
        elseif('add-TaskAfter' -eq $PSCmdlet.ParameterSetName){

            $indexOfAfter = Get-IndexOfKeyInOrderedDictionary -Key $After -OrderedDictionary $taskGroup.Tasks
            # ensure task with key $After exists
            if($indexOfAfter -lt 0){
                throw "A task with name $After could not be found."
            }
            $taskGroup.Tasks.Insert($indexOfAfter + 1,$key,$value)
        
        }
        elseif('add-TaskBefore' -eq $PSCmdlet.ParameterSetName){        
        
            $indexOfBefore = Get-IndexOfKeyInOrderedDictionary -Key $Before -OrderedDictionary $taskGroup.Tasks
            # ensure task with key $Before exists
            if($indexOfBefore -lt 0){
                throw "A task with name $Before could not be found."
            }
            $taskGroup.Tasks.Insert($indexOfBefore,$key,$value)
        
        }
        else{
        
            # by default add as last task
            $taskGroup.Tasks.Add($key, $value)        
        }

Write-Debug "saving task group"
        Save-TaskGroup -TaskGroup $taskGroup -ProjectRootDirPath $ProjectRootDirPath    

    }
}

function Set-PoshDevOpsTaskParameters(

[string]
[ValidateNotNullOrEmpty()]
[Parameter(
    Mandatory=$true)]
$PoshDevOpsTaskName,

[hashtable]
[Parameter(
    Mandatory=$true)]
$Parameters,

[switch]$Force,

[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){
    <#
        .SYNOPSIS
        Sets configurable parameters of a task
        
        .EXAMPLE
        Set-PoshDevOpsTaskParameters -PoshDevOpsTaskName "GitClone" -Parameters @{GitParameters=@("status")} -Force
        
        Description:

        This command sets a parameter (named "GitParameters") for a task (named "GitClone") to @("status")
    #>

    $taskGroup = Get-PoshDevOpsTaskGroup -ProjectRootDirPath $ProjectRootDirPath
    $ciTask = $taskGroup.Tasks.$PoshDevOpsTaskName
    $parametersPropertyName = "Parameters"

Write-Debug "Checking task `"$PoshDevOpsTaskName`" for property `"$parametersPropertyName`""
    $parametersPropertyValue = $ciTask.$parametersPropertyName    
    if($parametersPropertyValue){
        foreach($parameter in $Parameters.GetEnumerator()){

            $parameterName = $parameter.Key
            $parameterValue = $parameter.Value

Write-Debug "Checking if parameter `"$parameterName`" previously set"
            $previousParameterValue = $parametersPropertyValue.$parameterName
            if($previousParameterValue){
Write-Debug "Found parameter `"$parameterName`" previously set to `"$($previousParameterValue|Out-String)`""
$confirmationPromptQuery = 
@"
For task `"$PoshDevOpsTaskName`",
are you sure you want to change the value of parameter `"$parameterName`"?
    old value: $($previousParameterValue|Out-String)
    new value: $($parameterValue|Out-String)
"@

                $confirmationPromptCaption = "Confirm parameter value change"

                if($Force.IsPresent -or !$PSCmdlet.ShouldContinue($confirmationPromptQuery,$confirmationPromptCaption)){
Write-Debug "Skipping parameter `"$parameterName`". Overwriting existing parameter value was not confirmed."
                    continue
                }
            }
Write-Debug "Setting parameter `"$parameterName`" = `"$($parameterValue|Out-String)`" "
            $parametersPropertyValue.$parameterName = $parameterValue
        }
    }
    else {        
Write-Debug `
@"
Property `"$parametersPropertyName`" has not previously been set for task `"$PoshDevOpsTaskName`"
Adding with value:
$($Parameters|Out-String)
"@
        Add-Member -InputObject $ciTask -MemberType 'NoteProperty' -Name $parametersPropertyName -Value $Parameters -Force
    }
    
    Save-TaskGroup -TaskGroup $taskGroup -ProjectRootDirPath $ProjectRootDirPath
}

function Remove-PoshDevOpsTask(
[string]
[ValidateNotNullOrEmpty()]
[Parameter(
    Mandatory=$true)]
$Name,

[switch]$Force,

[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){

    $confirmationPromptQuery = "Are you sure you want to delete the task with name $Name`?"
    $confirmationPromptCaption = 'Confirm task removal'

    if($Force.IsPresent -or $PSCmdlet.ShouldContinue($confirmationPromptQuery,$confirmationPromptCaption)){

        $taskGroup = Get-PoshDevOpsTaskGroup -ProjectRootDirPath $ProjectRootDirPath
Write-Debug "Removing task $Name"
        $taskGroup.Tasks.Remove($Name)
        Save-TaskGroup -TaskGroup $taskGroup -ProjectRootDirPath $ProjectRootDirPath
    }

}

function New-PoshDevOpsTaskGroup(
[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){
    $taskGroupDirPath = "$(Resolve-Path $ProjectRootDirPath)\.PoshDevOps"

    if(!(Test-Path $taskGroupDirPath)){    
        $templatesDirPath = "$PSScriptRoot\Templates"

Write-Debug "Creating a directory for the task group at path $taskGroupDirPath"
        New-Item -ItemType Directory -Path $taskGroupDirPath

Write-Debug "Adding default files to path $taskGroupDirPath"
        Copy-Item -Path "$templatesDirPath\TaskGroup.psd1" $taskGroupDirPath
    }
    else{        
throw ".PoshDevOps directory already exists at $taskGroupDirPath. If you are trying to recreate your task group from scratch you must invoke Remove-PoshDevOpsTaskGroup first"
    }
}

function Remove-PoshDevOpsTaskGroup(
[switch]$Force,
[string]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath = '.'){
    
    $taskGroupDirPath = Resolve-Path "$ProjectRootDirPath\.PoshDevOps"

    $confirmationPromptQuery = "Are you sure you want to delete the task group located at $TaskGroupDirPath`?"
    $confirmationPromptCaption = 'Confirm task group removal'

    if($Force.IsPresent -or $PSCmdlet.ShouldContinue($confirmationPromptQuery,$confirmationPromptCaption)){
        Remove-Item -Path $taskGroupDirPath -Recurse -Force
    }
}

function Invoke-PoshDevOpsTaskGroup(

[Hashtable]
[Parameter(
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
$Parameters,

[string[]]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$PackageSources = $defaultPackageSources,

[String]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$ProjectRootDirPath='.'){
    
    $taskGroupDirPath = Resolve-Path "$ProjectRootDirPath\.PoshDevOps"
    $taskGroupFilePath = "$taskGroupDirPath\TaskGroup.psd1"
    $packagesDirPath = "$taskGroupDirPath\Packages"

    if(Test-Path $taskGroupFilePath){

        EnsureNuGetInstalled

        $TaskGroup = Get-PoshDevOpsTaskGroup -ProjectRootDirPath $ProjectRootDirPath

        foreach($task in $TaskGroup.Tasks.Values){
                    
            if($Parameters.($task.Name)){

                if($task.Parameters){

Write-Debug "Adding union of passed parameters and archived parameters to pipeline. Passed parameters will override archived parameters"
                
                    $taskParameters = Get-UnionOfHashtables -Source1 $Parameters.($task.Name) -Source2 $task.Parameters

                }
                else{

Write-Debug "Adding passed parameters to pipeline"

                    $taskParameters = $Parameters.($task.Name)
            
                }

            }
            elseif($task.Parameters){

Write-Debug "Adding archived parameters to pipeline"    
                $taskParameters = $task.Parameters

            }
            else{
                
                $taskParameters = @{}
            
            }

Write-Debug "Adding automatic parameters to pipeline"
            
            $taskParameters.PoshDevOpsProjectRootDirPath = (Resolve-Path $ProjectRootDirPath)
            $taskParameters.PoshDevOpsTaskName = $task.Name

Write-Debug "Ensuring task module package installed"
            nuget install $task.PackageId -Version $task.PackageVersion -OutputDirectory $packagesDirPath -Source $PackageSources -NonInteractive

            $moduleDirPath = "$packagesDirPath\$($task.PackageId).$($task.PackageVersion)\tools\$($task.PackageId)"
Write-Debug "Importing module located at: $moduleDirPath"
            Import-Module $moduleDirPath -Force

Write-Debug `
@"
Invoking task $($task.Name) with parameters: 
$($taskParameters|Out-String)
"@
            # Parameters must be PSCustomObject so [Parameter(ValueFromPipelineByPropertyName = $true)] works
            [PSCustomObject]$taskParameters.Clone() | Invoke-PoshDevOpsTask

        }
    }
    else{

throw "TaskGroup.psd1 not found at: $taskGroupFilePath"

    }
}

Export-ModuleMember -Function Invoke-PoshDevOpsTaskGroup,New-PoshDevOpsTaskGroup,Remove-PoshDevOpsTaskGroup,Add-PoshDevOpsTask,Set-PoshDevOpsTaskParameters,Remove-PoshDevOpsTask,Get-PoshDevOpsTaskGroup
tools\Src\Install.ps1
# installer based on guidelines provided by Microsoft 
# for installing shared/3rd party powershell modules
# (see: https://msdn.microsoft.com/en-us/library/dd878350%28v=vs.85%29.aspx )
if($PSVersionTable.PSVersion.Major -lt 3) {
    Write-Warning "PoshDevOps requires PowerShell 3.0 or better; you have version $($Host.Version)."
    return
}

# prepare install dir
$installRootDirPath = "$env:ProgramFiles\PoshDevOps"
$installDirPath = "$installRootDirPath\Modules"

# handle upgrade scenario
if(Test-Path "$installRootDirPath"){
    Write-Debug 'removing previous PoshDevOps installation'
    . "$PSScriptRoot\Uninstall.ps1"
}
New-Item $installDirPath -ItemType Directory | Out-Null

Copy-Item -Path "$PSScriptRoot" -Destination $installDirPath -Recurse

$psModulePath = [Environment]::GetEnvironmentVariable('PSModulePath','Machine')

# if installation dir path is not already in path then add it.
if(!($psModulePath.Split(';').Contains($installDirPath))){
    Write-Debug "adding $installDirPath to '$env:PSModulePath'"
    
    # trim trailing semicolon if exists
    $psModulePath = $psModulePath.TrimEnd(';');

    # append path to PoshDevOps installation
    $psModulePath = $psModulePath + ";$installDirPath"
    
    # save
    [Environment]::SetEnvironmentVariable('PSModulePath',$psModulePath,'Machine')    
    
    # make effective in current session
    $env:PSModulePath = $env:PSModulePath + ";$installDirPath"
}
tools\Src\chocolateyUninstall.ps1
try {

    . "$PSScriptRoot\Uninstall.ps1"

} catch {

    Write-ChocolateyFailure 'PoshDevOps' $_.Exception.Message

    throw 
}
tools\Src\chocolateyInstall.ps1
try {    
    
    . "$PSScriptRoot\Install.ps1"

} catch {

    Write-ChocolateyFailure 'PoshDevOps' $_.Exception.Message

    throw 
}
tools\README.md
###What problems does PoshDevOps attempt to solve?

Build/Deployment services today are extremely powerfull and easy to use. However, if you throw your DevOps together in most of these services you are left with: 
######-1 lack of versioning side by side source code 
######-2 coupling of implementation to a proprietary build/deployment service.
######-3 no capability to run outside of a proprietary build/deployment
######-4 expenses (subscriptions, licenses, hardware,  etc...)
######-5 one off scripts lacking any any sort of modularity
######-6 rampant copying/pasting, general lack of reuse

###How does PoshDevOps attempt to solve them?
######+1 versioning side by side source code
######+2 implemented as plain old PowerShell modules
######+3 ability to run anything capable of running PowerShell
######+4 no expenses (as long as you have something capable of running PowerShell ;))
######+5 all tasks are implemented as PowerShell modules
######+6 all tasks are package sourced and inherently reuseable

###How do I install it?
Make sure you have [Chocolatey](https://chocolatey.org) installed, then from PowerShell run
```POWERSHELL
choco install poshdevops -version 0.0.20; # 0.0.20 was latest at time of writing
Import-Module "C:\Program Files\PoshDevOps\Modules\PoshDevOps" -Force
```
###In a nutshell, hows it work?
***Conceptually:***
- `task groups` contain an ordered set of tasks
- `tasks` are arbitrary operations implemented as PowerShell modules and packaged as .nupkg's.

***Operationally:***
- everything takes place within PowerShell
- as you [CRUD](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete) each `task group` a snapshot is maintained in a `TaskGroup.psd1` file.
- at any time you can invoke your `task group` and pass in any parameters your `tasks` rely on

###How do I get started?
navigate to the root directory of your project:
```POWERSHELL
Set-Location "PATH-TO-ROOT-DIR-OF-YOUR-PROJECT"
```
create a new task group:
```POWERSHELL
New-PoshDevOpsTaskGroup
```
add a task to your plan:
```POWERSHELL
Add-PoshDevOpsTask -Name "Compile" -ModulePath "PATH-TO-DIR-CONTAINING-MODULE"
```
invoke your task group:
```POWERSHELL
@{Compile=@{Var1='Value1';Var2='Value2'}} | Invoke-PoshDevOpsTaskGroup
```

###How do I distribute my task group?
When you run `New-PoshDevOpsTaskGroup` it creates a folder named `.PoshDevOps` at the root of your project. From then on all modifications to your task groups are maintained inside that folder so your .PoshDevOps folder is all you need!

(pro-tip: check your .PoshDevOps folder in to source control to version your task group along with your code.)

###Where's the documentation?
[Here](Docs)

###What's the build status
![](https://ci.appveyor.com/api/projects/status/jt0ppwagy4kmreap?svg=true)

###Interesting reading
[Distributed Continuous Integration - Keep the Mainline Clean](http://blog.assembla.com/AssemblaBlog/tabid/12618/bid/96937/Distributed-Continuous-Integration-Keep-the-Mainline-Clean.aspx)

tools\.PoshDevOps\Packages\CreateChocolateyPackage.0.0.19\tools\CreateChocolateyPackage\CreateChocolateyPackage.psm1
# halt immediately on any errors which occur in this module
$ErrorActionPreference = "Stop"

function EnsureChocolateyInstalled(
[String]
[ValidateNotNullOrEmpty()]
$PathToChocolateyExe){
    # install chocolatey
    try{
        Get-Command $PathToChocolateyExe -ErrorAction Stop | Out-Null
    }
    catch{             
        iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
    }   
}

function Invoke-PoshDevOpsTask(

[String]
[ValidateNotNullOrEmpty()]
[Parameter(
    Mandatory=$true,
    ValueFromPipelineByPropertyName=$true)]
$PoshDevOpsProjectRootDirPath,

[String[]]
[ValidateCount(1,[Int]::MaxValue)]
[Parameter(
    ValueFromPipelineByPropertyName = $true)]
$IncludeNuspecPath = @(gci -Path $PoshDevOpsProjectRootDirPath -File -Filter '*.nuspec' -Recurse | %{$_.FullName}),

[String[]]
[Parameter(
    ValueFromPipelineByPropertyName = $true)]
$ExcludeNuspecNameLike,

[Switch]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$Recurse,

[String]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$OutputDirectoryPath,

[String]
[Parameter(
    ValueFromPipelineByPropertyName = $true)]
$Version,

[String]
[ValidateNotNullOrEmpty()]
[Parameter(
    ValueFromPipelineByPropertyName=$true)]
$PathToChocolateyExe = 'C:\ProgramData\chocolatey\bin\chocolatey.exe'){

    EnsureChocolateyInstalled -PathToChocolateyExe $PathToChocolateyExe

    $NuspecFilePaths = gci -Path $IncludeNuspecPath -Filter '*.nuspec' -File -Exclude $ExcludeNuspecNameLike -Recurse:$Recurse | ?{!$_.PSIsContainer} | %{$_.FullName}

Write-Debug `
@"
`Located .nuspec's:
$($NuspecFilePaths | Out-String)
"@

    if($OutputDirectoryPath){
        Push-Location ( Resolve-Path $OutputDirectoryPath)        
    }
    else{            
        Push-Location (Get-Location)       
    }

Write-Debug  `
@"
output directory is:
$OutputDirectoryPath
"@

    foreach($nuspecFilePath in $NuspecFilePaths)
    {
    
        $chocolateyParameters = @('pack',$nuspecFilePath)
        
        if($Version){
            $chocolateyParameters += @('-version',$Version)
        }

Write-Debug `
@"
Invoking choco:
& $PathToChocolateyExe $($chocolateyParameters|Out-String)
"@
        & $PathToChocolateyExe $chocolateyParameters

        # handle errors
        if ($LastExitCode -ne 0) {
            throw $Error
        }
    }

    # revert location
    Pop-Location
}

Export-ModuleMember -Function Invoke-PoshDevOpsTask 

Log in or click on link to see number of positives.

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Add to Builder Version Downloads Last Updated Status
PoshDevOps 0.0.71 398 Friday, March 27, 2015 Approved
PoshDevOps 0.0.69 394 Friday, March 27, 2015 Approved
PoshDevOps 0.0.68 419 Thursday, March 26, 2015 Approved
PoshDevOps 0.0.64 440 Thursday, March 26, 2015 Approved
PoshDevOps 0.0.63 408 Wednesday, March 25, 2015 Approved
PoshDevOps 0.0.62 381 Wednesday, March 25, 2015 Approved
PoshDevOps 0.0.42 445 Wednesday, March 25, 2015 Approved
PoshDevOps 0.0.41 392 Tuesday, March 24, 2015 Approved
PoshDevOps 0.0.40 386 Tuesday, March 24, 2015 Approved
PoshDevOps 0.0.39 393 Tuesday, March 24, 2015 Approved
PoshDevOps 0.0.38 394 Monday, March 23, 2015 Approved
PoshDevOps 0.0.37 426 Monday, March 23, 2015 Approved
PoshDevOps 0.0.36 414 Sunday, March 22, 2015 Approved
PoshDevOps 0.0.35 417 Sunday, March 22, 2015 Approved
PoshDevOps 0.0.34 393 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.33 457 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.32 355 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.31 401 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.30 403 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.28 416 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.27 458 Saturday, March 21, 2015 Approved
PoshDevOps 0.0.13 509 Friday, March 20, 2015 Approved
PoshDevOps 0.0.12 395 Friday, March 20, 2015 Approved
PoshDevOps 0.0.6 411 Wednesday, March 18, 2015 Approved
PoshDevOps 0.0.4 357 Wednesday, March 18, 2015 Approved
PoshDevOps 0.0.2 363 Monday, March 30, 2015 Approved

This package has no dependencies.

Discussion for the PoshDevOps Package

Ground Rules:

  • This discussion is only about PoshDevOps and the PoshDevOps package. If you have feedback for Chocolatey, please contact the Google Group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or PoshDevOps, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.
comments powered by Disqus