1
+ trigger :
2
+ - main
3
+
4
+ pool :
5
+ vmImage : ' ubuntu-latest'
6
+
7
+ stages :
8
+ - stage : Build
9
+ jobs :
10
+ - job : WebApp
11
+ steps :
12
+ - task : Npm@1
13
+ displayName : ' Npm Install'
14
+ inputs :
15
+ command : ' install'
16
+ workingDir : ' app/frontend/'
17
+ - task : Npm@1
18
+ displayName : ' Npm run build'
19
+ inputs :
20
+ command : ' custom'
21
+ workingDir : ' app/frontend/'
22
+ customCommand : ' run build'
23
+
24
+ - task : Maven@4
25
+ displayName : ' Build springboot app'
26
+ inputs :
27
+ mavenPomFile : ' app/backend/pom.xml'
28
+ goals : ' package'
29
+ javaHomeOption : ' JDKVersion'
30
+ jdkVersionOption : ' 1.17'
31
+ jdkArchitectureOption : ' x64'
32
+ publishJUnitResults : true
33
+ mavenVersionOption : ' Default'
34
+ mavenAuthenticateFeed : false
35
+ effectivePomSkip : false
36
+ sonarQubeRunAnalysis : false
37
+
38
+ # get jar name from pom.xml and set it as output variable so Deploy job and use it
39
+ - task : Bash@3
40
+ displayName : ' Get jar file name from pom.xml'
41
+ inputs :
42
+ targetType : ' inline'
43
+ script : |
44
+ version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
45
+ artifactId=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
46
+ echo "##vso[task.setvariable variable=jarfilename;isOutput=true]$artifactId-$version"
47
+ workingDirectory : ' app/backend/'
48
+ name : pomvariable
49
+
50
+ # copy final jar file to target folder
51
+ - task : CopyFiles@2
52
+ displayName : ' Copy jar file'
53
+ inputs :
54
+ Contents : ' app/backend/target/$(pomvariable.jarfilename).jar'
55
+ TargetFolder : ' $(Build.ArtifactStagingDirectory)'
56
+
57
+ # upload the artifact to spring-boot-app container
58
+ - task : PublishBuildArtifacts@1
59
+ displayName : ' Upload springboot app artifacts'
60
+ inputs :
61
+ PathtoPublish : ' $(Build.ArtifactStagingDirectory)'
62
+ ArtifactName : ' spring-boot-app'
63
+ publishLocation : ' Container'
64
+
65
+ - stage : DeployDev
66
+ condition : eq(variables['Build.SourceBranch'], 'refs/heads/dev')
67
+ dependsOn : Build
68
+ variables :
69
+ buildjarfilename : $[ stageDependencies.Build.WebApp.outputs['pomvariable.jarfilename'] ]
70
+ jobs :
71
+ - deployment : DeploySpringbootApp
72
+ displayName : ' Azure Web App'
73
+ variables :
74
+ buildjarfilename : $[ stageDependencies.Build.WebApp.outputs['pomvariable.jarfilename'] ]
75
+ environment : ' dev'
76
+ strategy :
77
+ runOnce :
78
+ deploy :
79
+ steps :
80
+ - task : AzureWebApp@1
81
+ displayName : ' Azure Web App'
82
+ inputs :
83
+ azureSubscription : ' <azureSubscriptionServiceConnection>'
84
+ appType : ' webAppLinux'
85
+ appName : ' <appServiceName>
86
+ package: ' $(Pipeline.Workspace)/**/$(buildjarfilename).jar'
87
+ runtimeStack : ' JAVA|17-java17'
88
+ startUpCommand : ' java -jar /home/site/wwwroot/$(buildjarfilename).jar'
89
+
90
+ - stage : DeployProd
91
+ condition : eq(variables['Build.SourceBranch'], 'refs/heads/main')
92
+ dependsOn : Build
93
+ variables :
94
+ buildjarfilename : $[ stageDependencies.Build.WebApp.outputs['pomvariable.jarfilename'] ]
95
+ jobs :
96
+ - deployment : DeploySpringbootApp
97
+ displayName : ' Azure Web App'
98
+ environment : ' prod'
99
+ strategy :
100
+ runOnce :
101
+ deploy :
102
+ steps :
103
+ - task : AzureWebApp@1
104
+ displayName : ' Azure Web App'
105
+ inputs :
106
+ azureSubscription : ' <azureSubscriptionServiceConnection>'
107
+ appType : ' webAppLinux'
108
+ appName : ' <appServiceName>'
109
+ package : ' $(Pipeline.Workspace)/**/$(buildjarfilename).jar'
110
+ runtimeStack : ' JAVA|17-java17'
111
+ startUpCommand : ' java -jar /home/site/wwwroot/$(buildjarfilename).jar'
0 commit comments