archetype-resources.devops.JenkinsfileDeploy.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of foundation-archetype
Show all versions of foundation-archetype
Defines a root level project archetype that can then have pipeline archetypes added to it
def gitId = 'github'
def gitRepo = '${projectGitUrl}'
// Set branch in the Jenkins Job or set here if not variable
def gitBranch = 'refs/heads/${branch}'
def projectDirectory = '${rootArtifactId}'
def jenkinsSteps
// Set URL of ArgoCD server
def argocdUrl = ''
def argocdAppName = '${rootArtifactId}'
def argocdNamespace = 'argocd'
def argocdDestinationServer = 'https://kubernetes.default.svc'
def argocdBranch = '${branch}'
def argocdSyncLabel = 'argocd.argoproj.io/instance=${rootArtifactId}'
node('master') {
dir(projectDirectory) {
checkout([$class: 'GitSCM', branches: [[name: gitBranch]], userRemoteConfigs: [[credentialsId: gitId, url: gitRepo]]])
jenkinsSteps = load 'devops/jenkinsPipelineSteps.groovy'
}
}
stage("Authenticate") {
node('master') {
withCredentials([string(credentialsId: 'argocdPassword', variable: 'argocdPassword')]) {
try {
dir(projectDirectory) {
slackSend color: "warning",
message: "${projectName} authenticating"
jenkinsSteps.argocdAuthenticate(argocdUrl, '${argocdPassword}')
}
} catch (err) {
slackSend color: "danger",
message: "${projectName} failed to authenticate properly"
throw err
}
}
}
}
stage("Deploy") {
node('master') {
try {
dir(projectDirectory) {
slackSend color: "warning",
message: "${projectName} deploying"
jenkinsSteps.argocdDeploy(argocdAppName, argocdUrl, argocdDestinationServer, gitRepo, argocdBranch,
argocdNamespace, ['values.yaml'])
slackSend color: "good",
message: "${projectName} deployed successfully"
}
} catch (err) {
slackSend color: "danger",
message: "${projectName} failed to deploy properly"
throw err
}
}
}
stage("Running") {
node('master') {
try {
timeout(environmentUptime) {
input message: 'Ready to kill the environment?', ok: 'Kill Test Server'
}
} catch (err) {}
}
}
stage("Teardown") {
node('master') {
try {
dir(projectDirectory) {
slackSend color: "warning",
message: "${projectName} shutting down"
jenkinsSteps.argocdTerminate(argocdAppName)
}
} catch (err) {
slackSend color: "danger",
message: "${projectName} failed to shut down properly"
throw err
}
}
}