107 lines
3.9 KiB
Groovy
107 lines
3.9 KiB
Groovy
#!/usr/bin/env groovy
|
|
|
|
env.APPLICATION_NAME = 'price-collector'
|
|
env.APPLICATION_LABEL = 'pricing'
|
|
env.GIT_BRANCH = 'master'
|
|
env.GIT_REPOSITORY_PATH = "github.com/andyjk15/${env.APPLICATION_NAME}.git"
|
|
env.GIT_REPOSITORY_URL = "https://${env.GIT_REPOSITORY_PATH}"
|
|
env.GITHUB_CREDENTIALS_ID = 'Github'
|
|
env.DIGITAL_OCEAN = 'registry.digitalocean.com'
|
|
env.DOCKER_BUILDER = 'registry.cryptosky.me'
|
|
env.DOCKER_REPOSITORY = "${env.DIGITAL_OCEAN}/cryptosky-image-registry"
|
|
env.DOCKER_REPOSITORY_TCP = "tcp://${env.DOCKER_BUILDER}:4243"
|
|
|
|
|
|
|
|
env.NAMESPACE = 'production'
|
|
env.SLAVE_LABEL = "cryptosky-aio-build"
|
|
|
|
def mvn( String gloals ) {
|
|
sh "mvn -s configuration/settings.xml --show-version --batch-mode ${gloals}"
|
|
}
|
|
|
|
String get_application_version() {
|
|
"1.0.0-b${env.BUILD_NUMBER}"
|
|
}
|
|
|
|
String executeShellScript( String shellPath, String arg1 = '', String arg2 = '', String arg3 = '', String arg4 = '' ) {
|
|
sh "./${shellPath} ${arg1} ${arg2} ${arg3} ${arg4}"
|
|
}
|
|
|
|
try {
|
|
timestamps {
|
|
node ("${env.SLAVE_LABEL}") {
|
|
stage('Initialise') {
|
|
checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'Github', url: 'https://github.com/andyjk15/price-collector.git']]])
|
|
|
|
env.APPLICATION_VERSION = get_application_version()
|
|
|
|
withCredentials(
|
|
[usernamePassword(
|
|
credentialsId: 'doctl',
|
|
passwordVariable: 'DOCTL_TOKEN',
|
|
usernameVariable: 'DOCTL_USERNAME'
|
|
)]
|
|
) {
|
|
sh "doctl auth init --access-token ${DOCTL_TOKEN}"
|
|
// sh "doctl kubernetes cluster kubeconfig save cryptosky-kubernetes-cluster-production"
|
|
}
|
|
}
|
|
|
|
stage('Test Artifact') {
|
|
try {
|
|
// mvn 'verify -DskipUTs -DskipTests'
|
|
} finally {
|
|
// mvn 'test'
|
|
}
|
|
}
|
|
|
|
stage('Build Image') {
|
|
// mvn 'clean package -DskipTests'
|
|
|
|
executeShellScript("configuration/scripts/mapVarsToConfigs.sh",
|
|
env.DOCKER_REPOSITORY,
|
|
env.APPLICATION_NAME,
|
|
env.APPLICATION_VERSION,
|
|
env.APPLICATION_LABEL)
|
|
|
|
}
|
|
|
|
stage('Tag Repository') {
|
|
|
|
withDockerServer([uri: "${env.DOCKER_REPOSITORY_TCP}"]) {
|
|
docker.build("${env.APPLICATION_NAME}:${env.APPLICATION_VERSION}")
|
|
docker.build("${env.APPLICATION_NAME}:latest")
|
|
|
|
sh "docker tag ${env.APPLICATION_NAME}:${env.APPLICATION_VERSION} ${env.DOCKER_REPOSITORY}/${env.APPLICATION_NAME}:${env.APPLICATION_VERSION}"
|
|
sh "docker tag ${env.APPLICATION_NAME}:latest ${env.DOCKER_REPOSITORY}/${env.APPLICATION_NAME}:latest"
|
|
|
|
sh "docker push ${env.DOCKER_REPOSITORY}/${env.APPLICATION_NAME}:${env.APPLICATION_VERSION}"
|
|
sh "docker push ${env.DOCKER_REPOSITORY}/${env.APPLICATION_NAME}:latest"
|
|
}
|
|
|
|
withCredentials(
|
|
[usernamePassword(
|
|
credentialsId: env.GITHUB_CREDENTIALS_ID,
|
|
passwordVariable: 'GIT_PASSWORD',
|
|
usernameVariable: 'GIT_USERNAME'
|
|
)]
|
|
) {
|
|
sh "git tag ${env.APPLICATION_VERSION}"
|
|
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@${env.GIT_REPOSITORY_PATH} ${env.APPLICATION_VERSION}"
|
|
}
|
|
}
|
|
|
|
stage('Deploy') {
|
|
// executeShellScript("configuration/scripts/deployToKubernetes.sh",
|
|
// env.APPLICATION_NAME)
|
|
}
|
|
}
|
|
}
|
|
} catch ( exception ) {
|
|
currentBuild.result = 'FAILURE'
|
|
throw exception
|
|
} finally {
|
|
currentBuild.result = 'SUCCESS'
|
|
}
|