forked from azure-devops/javawebappsample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
40 lines (36 loc) · 1.4 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
38
39
40
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 {
withEnv(['AZURE_SUBSCRIPTION_ID=6e709e97-cd50-4b0a-975c-d18d1b3fe1c5',
'AZURE_TENANT_ID=1256f274-2fc6-41cf-9e46-d46feb5ada53']) {
stage('init') {
checkout scm
}
stage('build') {
sh 'mvn clean package'
}
stage('deploy') {
def resourceGroup = 'QuickstartJenkins-rg'
def webAppName = 'AparnaWebApp'
// login Azure
withCredentials([usernamePassword(credentialsId: 'AzureServicePrincipal', passwordVariable: 'AZURE_CLIENT_SECRET', usernameVariable: 'AZURE_CLIENT_ID')]) {
sh '''
az login -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'
}
}
}