-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
148 lines (116 loc) · 4.51 KB
/
azure-pipelines.yml
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: $(TeamProject)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
trigger:
branches:
include:
- master
- feature/*
stages:
- stage: BuildTestPackageStage
displayName: Build-Test-Package Stage
jobs:
- job: BuildTestPackageJob
displayName: Build-Test-Package Job
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
############################### Build
- task: NuGetToolInstaller@0
- task: NuGetCommand@2
condition: succeeded()
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
condition: succeeded()
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
############################### TEST
- task: VSTest@2
condition: succeeded()
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
displayName: 'Run VSTest'
############################### Package
- script: md tools
condition: succeeded()
displayName: 'Create tools directory'
# - powershell: |
# Invoke-WebRequest `
# -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
# -OutFile tools\\nuget.exe
# displayName: 'Download nuget.exe'
- powershell: |
nuget install Microsoft.CrmSdk.CoreTools -O tools
md "tools\\CoreTools"
$coreToolsFolder = Get-ChildItem tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.CoreTools.'}
move "tools\\$coreToolsFolder\\content\\bin\\coretools\\*.*" "tools\\CoreTools"
Remove-Item "tools\\$coreToolsFolder" -Force -Recurse
displayName: 'Install CoreTools'
condition: succeeded()
#Pack Solution from repository
# .\bin\coretools\SolutionPackager.exe /action Pack /packagetype Unmanaged /zipfile .\contoso.zip /folder .\package /map: map.xml
- powershell: |
Start-Process tools/CoreTools/SolutionPackager.exe `
-ArgumentList `
"/action: Pack", `
"/zipfile: $(Build.ArtifactStagingDirectory)\solutionpackage.zip", `
"/folder: SolutionPackage/package/", `
"/map: SolutionPackage/map.xml", `
"/packagetype: $env:PackageType" `
-Wait `
-NoNewWindow
env:
PackageType: $(packagetype)
displayName: 'Solution Packager: pack solution'
condition: succeeded()
- task: PublishPipelineArtifact@0
condition: succeeded()
inputs:
artifactName: 'package'
targetPath: $(Build.ArtifactStagingDirectory)
- stage: Deploy2ProductionStage
displayName: Deploy to Production Stage
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
variables: # we had to intro these variables in stage level isntead of PS task because of recent bug that prevented PS receive it's variables.
STAGE_Url: $(eurl)
STAGE_Usr: $(eusername)
STAGE_Pas: $(epassword)
jobs:
- deployment: Deploy2Production_Job
displayName: Deploy to Production Job
pool:
vmImage: 'VS2017-Win2016'
environment: Production
strategy:
runOnce:
deploy:
steps:
- checkout: none
#- script: echo $(STAGE_VAR) $(JOB_VAR) $(STAGE_Url) $(STAGE_Usr) $(STAGE_Pas)
- task: DownloadPipelineArtifact@1
inputs:
artifactName: 'package'
targetPath: $(Build.ArtifactStagingDirectory)
#Import solution into target environment
- powershell: Install-Module Microsoft.Xrm.Data.Powershell -Scope CurrentUser -Force
displayName: 'Install Microsoft.Xrm.Data.PowerShell'
condition: succeeded()
#Connect to CRM and Import
- powershell: |
$connectionString = "AuthType = Office365;Username = $(STAGE_Usr);Password = $(STAGE_Pas);Url = $(STAGE_Url)"
$connection = Get-CrmConnection -ConnectionString $connectionString
$connection
#I had to use Import-CrmSolutionAsync -BlockUntilImportComplete in my case for a fairly bigger solution.
Import-CrmSolution -conn $connection -SolutionFilePath $(Build.ArtifactStagingDirectory)\solutionpackage.zip
#-MaxWaitTimeInSeconds
Publish-CrmAllCustomization -conn $connection
echo "..."
echo "Import Completed"
displayName: 'Import solution'
condition: succeeded()