-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
72 lines (60 loc) · 3.1 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
def subject_content = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER}"
def body_content = '${JELLY_SCRIPT,template="html"}'
def stage_tag = 'dev'
def project_name = 'innovation-catalogue-ui-ng'
def deployment_instance = 'innovation.dev.scio.services'
pipeline {
agent any
stages {
stage('Fetching SCM repo') {
steps {
echo 'Fetching SCM repo'
script {
checkout scm
sh 'git rev-parse --short HEAD > .git/commit-id'
commit_id = readFile('.git/commit-id').trim()
}
}
}
stage('Building & pushing docker images to DockerHub') {
steps {
echo 'Building project'
script {
echo 'Downloading from S3 bucket'
withAWS(region: 'us-east-2', credentials:'jenkins-aws') {
s3Download(file: '.env', bucket: 'scio-project-envs', path: "reactjs/${project_name}/${stage_tag}.env", force:true)
s3Download(file: '.npmrc', bucket: 'scio-project-envs', path: "reactjs/fontawesome_npmrc", force:true)
}
docker.withRegistry('https://index.docker.io/v1/', 'DockerHub') {
docker.build("sciohub/${project_name}:${stage_tag}", ".").push()
}
}
}
}
stage('Deploying stage') {
steps {
echo "Deploying to ${stage_name} environment"
script {
sshagent(credentials: ['jenkins-ssh-key']) {
sh "ssh -p1412 -o StrictHostKeyChecking=no scio@${deployment_instance} sudo mkdir -p /var/lib/${project_name}-${stage_tag}"
sh "ssh -p1412 -o StrictHostKeyChecking=no scio@${deployment_instance} sudo chown -R scio:scio /var/lib/${project_name}-${stage_tag}"
sh "ssh -p1412 -o StrictHostKeyChecking=no scio@${deployment_instance} docker rm -f ${project_name}" // stop container if already running under the defined container name
sh "scp -P 1412 -o StrictHostKeyChecking=no docker-compose.${stage_tag}.yml scio@${deployment_instance}:/var/lib/${project_name}-${stage_tag}"
sh "ssh -p1412 -o StrictHostKeyChecking=no scio@${deployment_instance} docker-compose -f /var/lib/${project_name}-${stage_tag}/docker-compose.${stage_tag}.yml pull"
sh "ssh -p1412 -o StrictHostKeyChecking=no scio@${deployment_instance} docker-compose -f /var/lib/${project_name}-${stage_tag}/docker-compose.${stage_tag}.yml up -d"
}
}
}
}
}
// Cleaning Jenkins workspace
post {
always {
sh 'docker image prune -a -f' // remove built images
emailext(body: body_content, mimeType: 'text/html',
replyTo: '$DEFAULT_REPLYTO', subject: subject_content,
to: 'dev@scio.systems', attachLog: true)
cleanWs()
}
}
}