forked from azure-devops/javawebappsample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
37 lines (33 loc) · 1.14 KB
/
Jenkinsfile
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
import groovy.json.JsonSlurper
def getFtpPublishProfile(def publishProfilesJson) {
def pubProfiles = new JsonSlurper().parseText(publishProfilesJson)
for (p in pubProfiles)
if (p['publishMethod'] == 'FTP')
return [url: p.publishUrl, username: p.userName, password: p.userPWD]
}
node {
stage('init') {
checkout scm
}
stage('build') {
sh 'mvn clean package'
}
stage('deploy') {
def resourceGroup = '<myResourceGroup>'
def webAppName = '<app_name>'
// login Azure
withCredentials([azureServicePrincipal('<mySrvPrincipal>')]) {
sh '''
az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID
az account set -s $AZURE_SUBSCRIPTION_ID
'''
}
// get publish settings
def pubProfilesJson = sh script: "az webapp deployment list-publishing-profiles -g $resourceGroup -n $webAppName", returnStdout: true
def ftpProfile = getFtpPublishProfile pubProfilesJson
// upload package
sh "curl -T target/calculator-1.0.war $ftpProfile.url/webapps/ROOT.war -u '$ftpProfile.username:$ftpProfile.password'"
// log out
sh 'az logout'
}
}