You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-music-cf/spring-music-cf-service-pip...

278 lines
12 KiB
Groovy

/*
* spring-music-cf service pipeline, file lives inside of app repository.
*
* See https://jenkins.io/doc/book/pipeline/syntax/ for details on the file format.
*/
// Branch to build
def gitBranch
// Build version of parcel-shipping-service
def deployVersion
// Whether the build will be deployed to production
def officialBuild
def deployToDev
def deployToTest
def deployToAze
// Pipeline should run build stage
def doBuild
pipeline {
// Choose the Jenkins VM configuration (definitions are in vault)
agent {
node {
label 'pipes-docker-agent'
}
}
// A pipeline consists of a series of stages
stages {
stage('Ingest Build Options') {
steps {
echo 'Parsing options passed in through Jenkins'
echo ''
echo "Unparsed content: ${params}"
script {
// Use version passed in through Jenkins if possible; otherwise, get new version
deployVersion = params.ARTIFACT_VERSION
if (!deployVersion) {
deployVersion = sh(returnStdout: true, script: "./version.sh").trim()
}
echo "deployVersion: '${deployVersion}'"
}
script {
gitBranch = params.GIT_BRANCH
echo "gitBranch: '${gitBranch}'"
}
script{
officialBuild = (params.OFFICIAL_BUILD as boolean)
deployToDev = (params.deploy_to_dev as boolean)
deployToTest = (params.deploy_to_test as boolean)
deployToAze = (params.deploy_to_aze as boolean)
echo "officialBuild: '${officialBuild}'"
}
script {
doBuild = (params.ARTIFACT_VERSION == '')
echo "doBuild: ${doBuild}"
}
// validate the combination of flags passed
script {
if (doBuild) {
echo "Building version '${deployVersion}'"
}
if (!doBuild) {
echo "Deploying previous build ${deployVersion}"
}
}
}
}
/* stage('Checkout Config Repository') {
when { expression { doBuild } }
steps {
echo 'Checkout Config Repository'
dir("./../parcel-shipping-service-config") {
git branch: "master",
credentialsId: 'github_credential',
url: 'https://github.gapinc.com/parcel-shipping/parcel-shipping-service-config.git'
}
}
}*/
stage('Build Artifacts') {
when { expression { doBuild } }
steps {
echo 'Build, deploy to Artifactory'
/* withCredentials(bindings: [
sshUserPrivateKey(credentialsId: 'pss-prod-rsakey', keyFileVariable: 'PSS_PROD_KEY', passphraseVariable: 'PSS_PROD_PASSPHRASE', usernameVariable: 'PSS_PROD_USERNAME'),
sshUserPrivateKey(credentialsId: 'pss-dev-rsakey', keyFileVariable: 'PSS_DEV_KEY', passphraseVariable: 'PSS_DEV_PASSPHRASE', usernameVariable: 'PSS_DEV_USERNAME')
]){
sh "./cpfile.sh $PSS_DEV_KEY 'src/main/resources/pssdev.rsa'"
sh "./cpfile.sh $PSS_PROD_KEY 'src/main/resources/pssprod.rsa'"
}
withCredentials(bindings: [ string(credentialsId: 'pss-oci-sso-wallet-dev', variable: 'PSS_OCI_SSO_WALLET_DEV'),
string(credentialsId: 'pss-oci-sso-p12-dev', variable: 'PSS_OCI_SSO_P12_DEV'),
string(credentialsId: 'pss-oci-sso-wallet-test', variable: 'PSS_OCI_SSO_WALLET_TEST'),
string(credentialsId: 'pss-oci-sso-p12-test', variable: 'PSS_OCI_SSO_P12_TEST')]) {
sh "mkdir -p src/main/resources/wallet"
sh "./oci_wallet_cpfile.sh $PSS_OCI_SSO_WALLET_DEV 'src/main/resources/wallet' 'dev' 'dev/cwallet.sso'"
sh "./oci_wallet_cpfile.sh $PSS_OCI_SSO_P12_DEV 'src/main/resources/wallet' 'dev' 'dev/ewallet.p12'"
sh "./oci_wallet_cpfile.sh $PSS_OCI_SSO_WALLET_TEST 'src/main/resources/wallet' 'test' 'test/cwallet.sso'"
sh "./oci_wallet_cpfile.sh $PSS_OCI_SSO_P12_TEST 'src/main/resources/wallet' 'test' 'test/ewallet.p12'"
}
withCredentials(bindings: [ string(credentialsId: 'pss-confluent-client-keystore-dev-jks', variable: 'PSS_CONFLUENT_CLIENT_KEYSTORE_DEV_JKS'),
string(credentialsId: 'pss-confluent-client-keystore-stage-jks', variable: 'PSS_CONFLUENT_CLIENT_KEYSTORE_STAGE_JKS'),
string(credentialsId: 'pss-confluent-client-keystore-prod-jks', variable: 'PSS_CONFLUENT_CLIENT_KEYSTORE_PROD_JKS'),
string(credentialsId: 'pss-confluent-client-truststore-jks', variable: 'PSS_CONFLUENT_CLIENT_TRUSTSTORE_JKS')]) {
sh "./oci_wallet_cpfile.sh $PSS_CONFLUENT_CLIENT_KEYSTORE_DEV_JKS 'src/main/resources' 'clientSSL' 'clientSSL/confluent.client.keystore.dev.jks'"
sh "./oci_wallet_cpfile.sh $PSS_CONFLUENT_CLIENT_KEYSTORE_STAGE_JKS 'src/main/resources' 'clientSSL' 'clientSSL/confluent.client.keystore.stage.jks'"
sh "./oci_wallet_cpfile.sh $PSS_CONFLUENT_CLIENT_KEYSTORE_PROD_JKS 'src/main/resources' 'clientSSL' 'clientSSL/confluent.client.keystore.prod.jks'"
sh "./oci_wallet_cpfile.sh $PSS_CONFLUENT_CLIENT_TRUSTSTORE_JKS 'src/main/resources' 'clientSSL' 'clientSSL/confluent.client.truststore.jks'"
}*/
withCredentials([usernamePassword(usernameVariable: 'GITHUB_USERNAME', passwordVariable: 'GITHUB_PASSWORD', credentialsId: 'github_credential'),
usernamePassword(usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD', credentialsId: 'pt-classroom-artifactory-token')]) {
sh "./gradlew clean build uploadBootArchives"
}
//sh "./gradlew clean build uploadArchives"
//sh "./gradlew clean build"
}
}
stage('Deploy to DEV') {
when { expression { deployToDev } }
steps {
echo 'Deploy from Artifactory to DEV'
build job: 'spring_music_cf_service_deploy_to_dev', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
}
}
stage('Deploy to TEST') {
when { expression { deployToTest } }
steps {
echo 'Deploy from Artifactory to TEST'
build job: 'spring_music_cf_service_deploy_to_test', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
}
}
stage('Deploy to E2E2') {
when { expression { officialBuild } }
steps {
echo 'Deploy from Artifactory to E2E2'
build job: 'spring_music_cf_service_deploy_to_e2e2', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
}
}
stage('Deploy to AZE DEV') {
when { expression { deployToAze} }
steps {
echo 'Deploy from Artifactory to AZE DEV'
build job: 'spring_music_cf_service_deploy_to_azedev', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
}
}
stage('Deploy to AZE TEST') {
when { expression { deployToTest && deployToAze } }
steps {
echo 'Deploy from Artifactory to AZE TEST'
build job: 'spring_music_cf_service_deploy_to_azetest', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
}
}
stage('Deploy to AZE E2E2') {
when { expression { officialBuild && deployToAze} }
steps {
echo 'Deploy from Artifactory to AZE E2E2'
build job: 'parcel_shipping_service_deploy_to_azee2e2', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
}
}
// stage('Deploy to PROD') {
// when { expression { officialBuild } }
// steps {
// echo 'Deploy from Artifactory to PROD'
// build job: 'parcel_shipping_service_deploy_to_prod', parameters: [[$class: 'StringParameterValue', name: 'ARTIFACT_VERSION', value: "${deployVersion}"]]
// }
// }
}
post {
success {
notifyTeam(deployVersion, 'SUCCESS')
}
failure {
notifyTeam(deployVersion, 'FAILURE')
}
}
}
def notifyTeam(deployVersion, status) {
// don't send an email just for refreshing parameters, unless it fails
if (params.refreshParameters && (status == 'SUCCESS')) {
return
}
def recipients = 'nathan_wagner@gap.com'
def presendScript
if (status == 'SUCCESS') {
presendScript = ''
} else {
// failed builds are marked important
presendScript = """
msg.addHeader("X-Priority", "1 (Highest)");
msg.addHeader("Importance", "High");
"""
}
def buildStart = new java.text.SimpleDateFormat("h:mm a z 'on' MMMM d").format(new Date(currentBuild.startTimeInMillis))
def durationSeconds = (currentBuild.duration / 1000) as Long
def buildDuration = [
'hour': (durationSeconds / 3600) as Long,
'minute': (((durationSeconds / 60) as Long) % 60),
'second': durationSeconds % 60,
].findAll { it.value > 0 }.collect { "${it.value} ${it.key}${it.value == 1 ? '' : 's'}" }.join(', ')
def changeSet
if (currentBuild.changeSets.every { it.emptySet }) {
changeSet = '<tr><td colspan="2"><code>No changes since last build.</code></td></tr>'
} else {
changeSet = currentBuild.changeSets.collect {
it.items.collect { "<tr><td>${it.author.fullName}</td><td>${it.msg}</td></tr>" }
}.flatten().join('\n')
}
def touchedFiles = currentBuild.changeSets.collect {
it.items.collect { it.affectedPaths.collect { "<li><code>${it}</code></li>" } }
}.flatten().sort().unique(false).join('\n') ?: '<li>No files changed since last build.</li>'
def emailBody = [
"<h2>${currentBuild.fullDisplayName}</h2>",
"<p>${currentBuild.buildCauses[0].shortDescription} at ${buildStart}.</p>",
"<p>The build took ${buildDuration}.</p>",
"<p>View the build <a href='${currentBuild.absoluteUrl}'>in Jenkins</a>.</p>",
"<p>To redeploy the same artifacts, use deployVersion: <code>${deployVersion}</code></p>",
'<h3>Commits:</h3>',
'<style>tr:nth-child(3n) { background: #eee; }</style>',
'<table>',
'<thead style="background: #ddd;"><tr><th>Git Author</th><th>Commit Message</th></tr></thead>',
'<tbody>',
changeSet,
'</tbody>',
'</table>',
'<h3>Touched files:</h3>',
'<ul style="list-style-type: none;">',
touchedFiles,
'</ul>',
].join('\n')
emailext(
subject: "${status}: ${currentBuild.fullDisplayName}",
to: recipients,
body: emailBody,
mimeType: 'text/html',
presendScript: presendScript
)
}