-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-pipelines.yml
128 lines (121 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
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
variables:
- name: 'KB.ArtifactName'
value: 'drop'
stages:
- stage: BuildSrcCode
jobs:
- job: 'BuildArtifacts'
pool:
vmImage: 'ubuntu-latest'
name: 'Azure Pipelines'
steps:
- task: UseDotNet@2
name: 'InstallDotNetCoreSdk3_x'
inputs:
packageType: 'sdk'
version: '3.x'
- task: Bash@3
name: 'BuildWithCake'
inputs:
filePath: '$(Build.SourcesDirectory)/build.sh'
arguments: '-verbosity=$(cakeVerbosity) -target=$(cakeTaskName) -Configuration=$(buildConfiguration) -Runtime=$(buildRuntime)'
- publish: '$(Build.SourcesDirectory)/artifacts'
artifact: '$(KB.ArtifactName)'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'XUnit'
testResultsFiles: '**/TestResults/**/?(*.xml|*.trx)'
searchFolder: '$(Build.SourcesDirectory)'
- stage: 'DevDeployment'
dependsOn: 'BuildSrcCode'
jobs:
# deployment job will Download pipeline artifact in '$(Pipeline.Workspace)/$(artifactName)' automatically
- deployment: 'deployToTencentCloud'
pool:
name: 'AgentOnTencentCloud'
environment: 'smarthotel-dev'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CopyFiles@2
displayName: 'Copy Files to: /home/ubuntu/Artifacts'
inputs:
SourceFolder: '$(Pipeline.Workspace)/$(KB.ArtifactName)/publish'
TargetFolder: /home/ubuntu/Artifacts
CleanTargetFolder: true
- task: CmdLine@2
inputs:
script: |
echo 'Start Deploy WebApp'
sudo systemctl stop LightBlogWebApp.service
cd ~/www/
sudo rm -r LightBlog/
\cp -rf ../Artifacts/. ./
sudo systemctl start LightBlogWebApp.service
- stage: 'ProcDeployment'
dependsOn: 'BuildSrcCode'
jobs:
- job: 'BuildAndPushImage'
pool:
vmImage: 'ubuntu-latest'
name: 'Azure Pipelines'
steps:
- checkout: none
- download: current
artifact: '$(KB.ArtifactName)'
- task: CmdLine@2
inputs:
script: |
cd $(Pipeline.Workspace)
pwd
echo 'Start'
ls -R
echo 'End'
# Set Variables for Next Task
# Set Variables for Next Job(Next Task Cannot access output variables)
- task: CmdLine@2
name: 'SetContainerImageInfo'
inputs:
script: |
imageVersion=`cat version`
echo "read version from file: $imageVersion"
KBRepositoryName=$(Build.Repository.Id)
KBRepositoryName=${KBRepositoryName,,}
KBRepositoryName=${KBRepositoryName//\//-}
echo "get RepositoryName from Build.Repository.Id: $KBRepositoryName"
echo "##vso[task.setvariable variable=KB.Container.Repository.Name;]$KBRepositoryName"
echo "##vso[task.setvariable variable=KB.Container.Image.Version;]$imageVersion"
echo "##vso[task.setvariable variable=KB.Container.Repository.Name;isOutput=true]$KBRepositoryName"
echo "##vso[task.setvariable variable=KB.Container.Image.Version;isOutput=true]$imageVersion"
workingDirectory: '$(Pipeline.Workspace)/$(KB.ArtifactName)/publish'
- task: Docker@2
name: 'PushToAliyunRegistry'
inputs:
containerRegistry: '阿里云容器镜像私有仓库服务'
repository: '$(KB.Container.RegistryNameSpace)/$(KB.Container.Repository.Name)'
command: 'buildAndPush'
Dockerfile: '$(Pipeline.Workspace)/$(KB.ArtifactName)/publish/LightBlog/Dockerfile'
buildContext: '$(Pipeline.Workspace)/$(KB.ArtifactName)/publish/LightBlog'
tags: '$(KB.Container.Image.Version)'
- job: 'PullAndRunContainer'
pool:
name: 'ContainerOnNoteBook'
dependsOn: 'BuildAndPushImage'
variables:
KB.Container.Repository.Name: $[ dependencies.BuildAndPushImage.outputs['SetContainerImageInfo.KB.Container.Repository.Name'] ]
KB.Container.Image.Version: $[ dependencies.BuildAndPushImage.outputs['SetContainerImageInfo.KB.Container.Image.Version'] ]
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo KB.Container.Repository.Name: $(KB.Container.Repository.Name)
echo KBRepositoryName: $(KB.Container.Image.Version)