forked from NationalSecurityAgency/emissary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile_package
77 lines (77 loc) · 3.78 KB
/
Jenkinsfile_package
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
pipeline {
agent any
tools {
maven 'Maven 3.6.1'
}
options { skipDefaultCheckout() }
parameters {
string(defaultValue: "", description: 'String used to tag and release emissary if pipeline successfully builds.', name: 'TAG_EMISSARY')
string(defaultValue: "", description: 'String used to tag and release burrito if pipeline successfully builds.', name: 'TAG_BURRITO')
string(defaultValue: "default", description: 'String used as git username for tag and release purposes and credentials to do so.', name:'GIT_NAME')
}
stages {
stage('Build Emissary') {
steps {
checkout scm
sh 'sudo yum install -y java-1.8.0-openjdk-devel java-1.8.0-openjdk tar expect which docker docker-compose'
sh 'cat src/test/resources/jenkins_config/bashrc_addition >> ~/.bashrc'
sh 'mkdir -p ~/.m2'
sh 'sudo chown -R $(whoami):$(whoami) ~/.m2'
sh 'rm -rf ~/.m2/repository'
sh 'sudo chown -R $(whoami):$(whoami) $(pwd)'
sh 'mvn clean install'
sh 'mvn clean compile'
sh ('if [ "$TAG_EMISSARY" != "" ]; then mvn versions:set -DnewVersion=${TAG_EMISSARY}; fi;')
sh ('if [ "$TAG_EMISSARY" != "" ]; then mvn versions:commit; fi;')
}
}
stage('Build Docker Images'){
steps {
sh 'sudo systemctl start docker'
sh 'echo ${TAG_EMISSARY}'
sh 'mvn clean package -Pdist'
sh ('if [ "$TAG_EMISSARY" == "" ]; then docker build -t emissary:latest --build-arg PROJ_VERS=$(./emissary version | grep Version: | awk {\'print $3 " " \'}) --build-arg IMG_NAME=latest .; else docker build -t emissary:${TAG_EMISSARY} --build-arg PROJ_VERS=${TAG_EMISSARY} --build-arg IMG_NAME=${TAG_EMISSARY} .; fi;')
sh ('if [ "$TAG_EMISSARY" == "" ]; then docker build -f Dockerfile-test-feeder -t emissary-test-feeder:latest --build-arg PROJ_VERS=$(./emissary version | grep Version: | awk {\'print $3 " " \'}) --build-arg IMG_NAME=latest .; else docker build -f Dockerfile-test-feeder -t emissary-test-feeder:${TAG_EMISSARY} --build-arg PROJ_VERS=${TAG_EMISSARY} --build-arg IMG_NAME=${TAG_EMISSARY} .; fi;')
}
}
stage('Test') {
steps {
sh 'mvn test'
sh 'rm -f test_results'
sh 'sudo ./Docker_compose_test_script.sh'
}
}
stage('Build JAR for Burrito consumption'){
steps {
sh 'mvn package'
sh 'mv target/emissary*.jar target/emissary.jar'
archiveArtifacts artifacts: 'target/emissary.jar', fingerprint: true
archiveArtifacts artifacts: 'pom.xml', fingerprint: true
}
}
stage('Tag + Release'){
steps {
sh ('if [ "$GIT_NAME" != "default" ]; then git config user.name "${GIT_NAME}"; fi;')
withCredentials([usernamePassword(credentialsId: env.GIT_NAME , usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh ('if [ "$GIT_NAME" != "default" -a "$TAG_EMISSARY" != "" ]; then git add .; fi;')
sh ('if [ "$GIT_NAME" != "default" -a "$TAG_EMISSARY" != "" ]; then git commit -m "Commit made from Jenkins for tag ${TAG_EMISSARY}"; fi;')
sh ('if [ "$GIT_NAME" != "default" -a "$TAG_EMISSARY" != "" ]; then git tag -a ${TAG_EMISSARY} -m "Jenkins tag of ${TAG_EMISSARY}"; fi;')
sh ('if [ "$GIT_NAME" != "default" -a "$TAG_EMISSARY" != "" ]; then git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/NationalSecurityAgency/emissary.git --tags; fi;')
}
}
}
stage('Start Burrito Build'){
steps {
sh ('if [ "$TAG_EMISSARY" == "" ]; then export TAG_EMISSARY="$(./emissary version | grep Version: | awk {\'print $3 " " \'})"; fi;')
build(
job: 'Burrito_Pipeline',
parameters: [
string(name: 'TAG_EMISSARY', value: String.valueOf(TAG_EMISSARY)),
string(name: 'TAG_BURRITO', value: String.valueOf(TAG_BURRITO)),
string(name: 'GIT_NAME', value: String.valueOf(GIT_NAME))
]
)
}
}
}
}