-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
92 lines (92 loc) · 3.57 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pipeline {
options {
timestamps()
}
parameters {
string(name: 'BUILD_VERSION', defaultValue: '', description: 'The build version to deploy (optional)')
string(name: 'IMAGE_VERSION', defaultValue: '', description: 'The Docker image version to use (mandatory)')
string(name: 'ENVIRONMENT', defaultValue: 'ci', description: 'Role Name (mandatory)')
}
agent {
label 'ci && deploy && sctl'
}
environment {
PROJECT_NAME = "sctl"
DOCKER_REPO_NAME = "ncats/sctl-rshiny-complex"
INIT_TOKEN = credentials('Vault-Access')
SPHINX_TOKEN = credentials('ncatssvcdvops-sphinx')
ROLE_NAME = "$ENVIRONMENT-$PROJECT_NAME"
APP_TYPE = "keys"
DOCKER_IMAGE = "rstudio/rstudio-connect:${params.IMAGE_VERSION}"
}
stages {
stage('Docker/Apps getSecrets By Role') {
steps {
cleanWs()
checkout scm
script {
sh '''
git clone https://$SPHINX_TOKEN@github.com/Sphinx-Automation/devops-pipeline-artifacts.git
cd devops-pipeline-artifacts/application
/bin/bash getDockerHubSecretsByRole.sh
/bin/bash getAppSecretsByRole.sh
'''
}
}
}
stage('Build Version') {
steps {
script {
env.BUILD_VERSION = VersionNumber(
versionNumberString: 'v${BUILD_YEAR, XX}.${BUILD_MONTH, XX}.${BUILD_DAY, XX}.${BUILDS_TODAY}',
projectStartDate: '1970-01-01',
skipFailedBuilds: true)
currentBuild.displayName = env.BUILD_VERSION
}
}
}
stage('Build') {
steps {
configFileProvider([
configFile(fileId: 'prepare.sh', targetLocation: 'prepare.sh')
]) {
script {
sh '''#!/bin/bash
source prepare.sh
docker login -u "${DOCKERLOGIN}" -p "${DOCKERPASSWORD}"
docker pull ${DOCKER_IMAGE}
docker tag ${DOCKER_IMAGE} ${DOCKER_REPO_NAME}:${BUILD_VERSION}
docker push ${DOCKER_REPO_NAME}:${BUILD_VERSION}
'''
}
}
}
}
stage('Deploy') {
steps {
configFileProvider([
configFile(fileId: 'docker-compose.yml', targetLocation: 'docker-compose.yml'),
configFile(fileId: 'rstudio-connect.gcfg', targetLocation: 'rstudio-connect.gcfg')
]) {
script {
sh '''#!/bin/bash
source prepare.sh
docker-compose -p $PROJECT_NAME down -v --rmi all | xargs echo
docker rmi $DOCKER_REPO_NAME:current | xargs echo
docker pull ${DOCKER_REPO_NAME}:${BUILD_VERSION}
docker tag ${DOCKER_REPO_NAME}:${BUILD_VERSION} ${DOCKER_REPO_NAME}:current
docker-compose -p ${PROJECT_NAME} up -d
docker rmi \$(docker images -aq) | xargs echo
'''
}
}
}
}
}
post {
always {
echo "Clean up the workspace in deploy node!"
cleanWs()
}
}
}