-
Notifications
You must be signed in to change notification settings - Fork 12
/
azure-pipelines.yml
122 lines (107 loc) · 3.87 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
trigger:
tags:
include:
- v*
branches:
include:
- master
variables:
GOVERSION: '1.21.4'
LDFLAGS: "-w -s -X main.Version=$(Build.SourceBranchName) -X main.Commit=$(Build.SourceVersion) -X main.Build=$(Build.BuildNumber)"
jobs:
- job: linux
pool:
vmImage: 'ubuntu-latest'
variables:
CGO_ENABLED: '0'
GOOS: 'linux'
GOARCH: 'amd64'
steps:
- task: GoTool@0
displayName: 'Use Go $(GOVERSION)'
inputs:
version: '$(GOVERSION)'
- task: Go@0
displayName: 'Compile $(GOOS)/$(GOARCH)'
inputs:
command: build
arguments: -ldflags """$(LDFLAGS)""" -o "$(Build.BinariesDirectory)/$(System.TeamProject)"
- task: CopyFiles@2
displayName: 'Stage supporting files'
inputs:
sourceFolder: $(Build.SourcesDirectory)
contents: '$(System.TeamProject).toml'
targetFolder: $(Build.BinariesDirectory)
- task: ArchiveFiles@2
displayName: 'Create application archive'
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: false
archiveType: 'tar'
tarCompression: 'gz'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(System.TeamProject)_$(Build.SourceBranchName)_$(GOOS)_$(GOARCH).tar.gz'
verbose: true
- task: PublishBuildArtifacts@1
displayName: 'Publish $(GOOS) artifacts'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: Drop
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
- task: Docker@2
displayName: 'Build/Push Docker image (master)'
inputs:
command: buildAndPush
buildContext: $(Build.BinariesDirectory)
containerRegistry: bryanklewis-dockerhub
repository: bryanklewis/$(System.TeamProject)
tags: |
$(Build.SourceBranchName)
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
- task: Docker@2
displayName: 'Build/Push Docker image (version)'
inputs:
command: buildAndPush
buildContext: $(Build.BinariesDirectory)
containerRegistry: bryanklewis-dockerhub
repository: bryanklewis/$(System.TeamProject)
tags: |
$(Build.SourceBranchName)
latest
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
- job: windows
pool:
vmImage: 'windows-latest'
variables:
CGO_ENABLED: '0'
GOOS: 'windows'
GOARCH: 'amd64'
steps:
- task: GoTool@0
displayName: 'Use Go $(GOVERSION)'
inputs:
version: '$(GOVERSION)'
- task: Go@0
displayName: 'Compile $(GOOS)/$(GOARCH)'
inputs:
command: build
arguments: -ldflags """$(LDFLAGS)""" -o $(Build.BinariesDirectory)\$(System.TeamProject).exe
- task: CopyFiles@2
displayName: 'Stage supporting files'
inputs:
sourceFolder: $(Build.SourcesDirectory)
contents: '$(System.TeamProject).toml'
targetFolder: $(Build.BinariesDirectory)
- task: ArchiveFiles@2
displayName: 'Create application archive'
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(System.TeamProject)_$(Build.SourceBranchName)_$(GOOS)_$(GOARCH).zip'
verbose: true
- task: PublishBuildArtifacts@1
displayName: 'Publish $(GOOS) artifacts'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: Drop
condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))