keptn-terraform/jenkinsfile

85 lines
3.0 KiB
Plaintext

pipeline {
agent {
label 'terraform-slave'
}
environment {
TF_VAR_KEPTN_NAMESPACE="keptn"
TF_VAR_KEPTN_VERSION="1.4.0"
TF_VAR_KEPTN_DOMAIN="keptn.nttdata-xlabs.com"
TF_VAR_DT_TENANT="https://elw69065.live.dynatrace.com"
TF_VAR_DT_API_TOKEN="dt0c01.N2PBLK767N76X77W4DKPZBW3.RPIRL6HTSX6OOPFB4REGWBQEN62LYYVYYR3O5VAWGFW37OVXKB4G6ZQUHPL33LMP"
}
parameters {
choice(name: 'mode', choices: ['apply', 'destroy'], description: '')
}
// parameters {
// booleanParam(name: 'refresh', defaultValue: false, description: 'Refresh pipeline properties')
// }
stages {
// stage('Refresh properties') {
// steps {
// script {
// if (Refresh) {
// currentBuild.result = 'ABORTED'
// error('Stopping early…')
// }
// }
// }
// }
stage('Deploy Keptn') {
when {
expression {
return params.mode == 'apply'
}
}
steps {
container('terraform') {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: "f89b3f7d-23ec-42b9-9687-e4acf01d7507",
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh 'chmod -R 777 ./terraform-kubernetes-get-secret/bin'
sh 'terraform version'
sh 'terraform init -backend-config="key=keptn-demo"'
sh 'terraform apply -auto-approve'
script {
env.KEPTN_BRIDGE_URL = sh(returnStdout: true, script: "terraform output -raw Keptn_Bridge_Url").trim()
env.KEPTN_API_TOKEN = sh(returnStdout: true, script: "terraform output -raw Keptn_API_Token").trim()
}
}
}
}
}
stage('Destroy Keptn') {
when {
expression {
return params.mode == 'destroy'
}
}
steps {
container('terraform') {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: "f89b3f7d-23ec-42b9-9687-e4acf01d7507",
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh 'chmod -R 777 ./terraform-kubernetes-get-secret/bin'
sh 'terraform version'
sh 'terraform init -backend-config="key=keptn-demo"'
sh 'terraform destroy -auto-approve'
}
}
}
}
}
}