-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-NeedsForecaster-sandbox
92 lines (82 loc) · 3.86 KB
/
Jenkinsfile-NeedsForecaster-sandbox
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 {
agent any
tools {
maven 'mvn'
jdk 'openjdk-15'
}
stages {
stage('Build Modules') {
steps {
dir('Core') {
git branch: 'master', changelog: false, credentialsId: 'jenkins-camsys-personal-token', poll: false, url: 'git@github.com:camsys/CSAssetCloud.git'
sh 'mvn -pl -NeedsForecaster,-Oversight clean install'
}
sh "CI= mvn package -U"
}
}
stage('Build Docker Images') {
steps {
sh "mvn docker:build"
}
}
stage('Push Docker Images To Repos') {
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY',
credentialsId: 'mvn-deploy-assetcloud'
]]) {
sh "aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 212764437395.dkr.ecr.us-east-1.amazonaws.com"
sh "mvn docker:push -U"
}
}
}
stage('Update Dev Environment') {
environment {
IMG_VERSION = sh(script:"mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep '^[^[]'", returnStdout: true).trim()
}
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY',
credentialsId: 'mvn-deploy-assetcloud'
]]) {
script {
// See for why xargs: https://superuser.com/questions/1306071/aws-cli-using-cli-input-json-in-a-pipeline
NEEDSFORECASTER_REVISION = sh(script:"cat ${env.WORKSPACE}/task-template-dev.json \
| jq '.containerDefinitions[0].image=\"212764437395.dkr.ecr.us-east-1.amazonaws.com/needs_forecaster:${env.IMG_VERSION}\"' \
| xargs -0 aws ecs register-task-definition --cli-input-json \
| jq .taskDefinition.revision", returnStdout: true).trim()
sh "aws ecs update-service --cluster AssetCloud --service needs-forecaster-dev --task-definition asset-cloud-needs-forecaster-dev:${NEEDSFORECASTER_REVISION}"
}
}
}
}
stage('Update Sandbox Environment') {
environment {
IMG_VERSION = sh(script:"mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep '^[^[]'", returnStdout: true).trim()
}
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY',
credentialsId: 'mvn-deploy-assetcloud'
]]) {
input "Deployed to dev. Do you want to deploy to Sandbox?"
milestone(1)
script {
// See for why xargs: https://superuser.com/questions/1306071/aws-cli-using-cli-input-json-in-a-pipeline
NEEDSFORECASTER_REVISION = sh(script:"cat ${env.WORKSPACE}/task-template-sandbox.json \
| jq '.containerDefinitions[0].image=\"212764437395.dkr.ecr.us-east-1.amazonaws.com/needs_forecaster:${env.IMG_VERSION}\"' \
| xargs -0 aws ecs register-task-definition --cli-input-json \
| jq .taskDefinition.revision", returnStdout: true).trim()
sh "aws ecs update-service --cluster AssetCloud --service needs-forecaster-sandbox --task-definition asset-cloud-needs-forecaster-sandbox:${NEEDSFORECASTER_REVISION}"
}
}
}
}
}
}