AdoExtensions.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function Create-AdoePipelineDefinitionFile
{
    [CmdletBinding()]
    param
    (
        #FilePath
        [Parameter(Mandatory = $true)]
        [string]$FilePath,

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

        #Path
        [Parameter(Mandatory = $false)]
        [string]$Path = '\',        

        #Project
        [Parameter(Mandatory = $true)]
        [PipelineProject]$Project,

        #Queue
        [Parameter(Mandatory = $true)]
        [PipelineQueue]$Queue,

        #Steps
        [Parameter(Mandatory = $true)]
        [PipelinePhase[]]$Phases,

        #Variables
        [Parameter(Mandatory = $false)]
        [Hashtable]$Variables = @{ },

        #Variable Groups
        [Parameter(Mandatory = $false)]
        [VariableGroup[]]$VariableGroups = @(),

        #Repository
        [Parameter(Mandatory = $true)]
        [PipelineRepository]$Repository
    )

    process
    {

        $PipelineDefinition = @{
            variablegroups = $VariableGroups
            variables      = $Variables
            process        = @{
                phases = $Phases
                type   = 1
            }
            queue          = $Queue
            repository     = $Repository
            name           = $Name
            path           = $Path
            project        = $Project
        }

        #Export Definition
        $PipelineDefinitionAsJson = $PipelineDefinition | Convertto-Json -Depth 20 -ErrorAction Stop
        $PipelineDefinitionAsJson | Out-File -FilePath $FilePath -Force -ErrorAction Stop
    }
}

#region Classes

class PipelineProject
{
    [string]$id
    [string]$name
}

class PipelineQueue
{
    [string]$name
}

class PipelineRepository
{
    [ValidateSet('TfsGit')]
    [string]$type = 'TfsGit'
    [string]$name
    [string]$defaultBranch = 'refs/heads/master'
}

class PipelinePhase
{
    [PipelineStep[]]$steps
    [string]$Name
    [string]$RefName
    [string]$condition = "succeeded()"
    [Target]$target
    [int]$jobTimeoutInMinutes = 0
}

class Target
{
    [string[]]$demands
    [int]$type = 1
}

class PipelineStep
{
    [bool]$enabled
    [string]$displayName
    [PipelineTask]$task
    [hashtable]$Inputs = @{ }
}

class PipelineTask
{
    [string]$id
    [string]$versionSpec
    [string]$definitionType = 'task'
}

class VariableGroup
{
    [int]$id
    [string]$type = 'vsts'
}

#endregion