-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.bdc
62 lines (57 loc) · 3.92 KB
/
Jenkinsfile.bdc
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
pipeline {
agent any
parameters {
string(name: 'DOCKER_REGISTRY', description: 'Docker registry URL (e.g., ECR URL)', defaultValue: 'hms-dbmi')
string(name: 'REPOSITORY_NAME', description: 'Docker repository name', defaultValue: 'metrics')
booleanParam(name: 'DEPLOY', description: 'Deploy the image to the registry', defaultValue: true)
booleanParam(name: 'ERROR_FILE', description: 'Errors will be sent to a different file than standard metrics.', defaultValue: true)
// Standard log file settings
string(name: 'PATH', description: 'Log file location.', defaultValue: '/home/logs/metrics')
string(name: 'FILE_NAME', description: 'Log file name.', defaultValue: 'pic-sure-metrics.json')
choice(name: 'SHOULD_ROLL_FILE', choices: ['ROLLING_FILE', 'SINGLE_FILE'], description: 'Choose log file mode')
string(name: 'MAX_FILE_SIZE', description: 'If rolling over, this is the size (in MB) each file should be at its max.', defaultValue: '100')
string(name: 'RETENTION_TIME', description: 'Log file retention time in days.', defaultValue: '90')
// Error log file settings (separate file)
string(name: 'ERROR_PATH', description: 'Error log file location.', defaultValue: '/home/logs/errors')
string(name: 'ERROR_FILE_NAME', description: 'Error log file name.', defaultValue: 'pic-sure-errors.json')
choice(name: 'ERROR_SHOULD_ROLL_FILE', choices: ['SINGLE_FILE', 'ROLLING_FILE'], description: 'Choose error log file mode')
string(name: 'ERROR_MAX_FILE_SIZE', description: 'If rolling over, this is the size (in MB) each error log file should be at its max.', defaultValue: '100')
string(name: 'ERROR_RETENTION_TIME', description: 'Error log file retention time in days.', defaultValue: '90')
}
environment {
GIT_BRANCH_SHORT = sh(script: 'echo ${GIT_BRANCH} | cut -d "/" -f 2', returnStdout: true).trim()
GIT_COMMIT_SHORT = sh(script: 'echo ${GIT_COMMIT} | cut -c1-7', returnStdout: true).trim()
IMAGE_TAG = "${GIT_BRANCH_SHORT}_${GIT_COMMIT_SHORT}"
LATEST_TAG = "LATEST"
}
stages {
stage('build') {
steps {
script {
// Define the build args
def buildArgs = " --build-arg DATASOURCE_URL=${params.DATASOURCE_URL} " +
" --build-arg DATASOURCE_USERNAME=${params.DATASOURCE_USERNAME} " +
" --build-arg STACK_SPECIFIC_APPLICATION_ID=${params.STACK_SPECIFIC_APPLICATION_ID} " +
" --build-arg LOG_PATH=${params.PATH} " +
" --build-arg FILE_NAME=${params.FILE_NAME} " +
" --build-arg MODE=${params.SHOULD_ROLL_FILE} " +
" --build-arg MAX_FILE_SIZE=${params.MAX_FILE_SIZE} " +
" --build-arg RETENTION_TIME=${params.RETENTION_TIME} " +
" --build-arg ERROR_LOG_PATH=${params.ERROR_PATH} " +
" --build-arg ERROR_FILE_NAME=${params.ERROR_FILE_NAME} " +
" --build-arg ERROR_MODE=${params.ERROR_SHOULD_ROLL_FILE} " +
" --build-arg ERROR_MAX_FILE_SIZE=${params.ERROR_MAX_FILE_SIZE} " +
" --build-arg ERROR_RETENTION_TIME=${params.ERROR_RETENTION_TIME} " +
" --build-arg APP_LOGGING__SEPARATE_ERROR_LOG=${params.ERROR_FILE} "
sh "docker tag ${params.DOCKER_REGISTRY}/${params.REPOSITORY_NAME}:${IMAGE_TAG} ${params.DOCKER_REGISTRY}/${params.REPOSITORY_NAME}:${LATEST_TAG}"
}
}
}
stage('Upload Docker Image') {
steps {
sh "docker save ${params.DOCKER_REGISTRY}/${params.REPOSITORY_NAME}:${LATEST_TAG} | gzip > metrics.tar.gz"
sh "aws s3 --sse=AES256 cp metrics.tar.gz s3://$S3_BUCKET_NAME/releases/metrics/metrics.tar.gz"
}
}
}
}