forked from Azure/terraform-with-jenkins-samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
51 lines (47 loc) · 2.04 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
41
42
43
44
45
46
47
48
49
50
51
// ******
// Exptected parameters for HTTP request to pipeline
// ******
//deployment="client01"
podTemplate(label: 'azurevm', containers: [
containerTemplate(name: 'terraform-az', image: '<containerRegistry>/terraform-az', ttyEnabled: true, command: 'cat',envVars: [
secretEnvVar(key: 'ARM_CLIENT_ID', secretName: '<your-secret-name>', secretKey: 'clientid'),
secretEnvVar(key: 'ARM_CLIENT_SECRET', secretName: '<your-secret-name>', secretKey: 'clientsecret'),
secretEnvVar(key: 'ARM_TENANT_ID', secretName: '<your-secret-name>', secretKey: 'tenantid'),
secretEnvVar(key: 'ARM_SUBSCRIPTION_ID', secretName: '<your-secret-name>', secretKey: 'subscriptionid')
]),
])
{
node('azurevm') {
currentBuild.result = "SUCCESS"
try {
stage('Init parameters'){
container('terraform-az') {
// Get SSH public for the VMSS from Jenkins
withCredentials([sshUserPrivateKey(credentialsId: '<your-public-key-id>', keyFileVariable: 'PUBLICKEY')]) {
sh """
mkdir /home/jenkins/.ssh
cat $PUBLICKEY >/home/jenkins/.ssh/id_rsa.pub
"""
}
}
}
stage('Download files'){
container('terraform-az') {
// Download existing tfstate from Azure Blob storage
azureDownload containerName: '<container-name>', downloadType: 'container', fileShare: '', includeArchiveZips: true, includeFilesPattern: '${deployment}.tar.gz', storageCredentialId: '<jenkins-storage-id>'
}
}
stage('Terraform destroy'){
container('terraform-az') {
sh (script:"tar -xzvmf $deployment'.tar.gz'")
// Destroy the VMSS cluster
sh (script:"terraform destroy -force -var='terraform_image_id=foo'")
}
}
}
catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}
}