-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathJenkinsfile.build
124 lines (121 loc) · 5.54 KB
/
Jenkinsfile.build
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pipeline {
agent {
node {
label 'team:iow'
}
}
parameters {
choice(choices: ['Test', 'QA', 'Beta', 'Production'], description: 's3 bucket that the build will target', name: 'BUILD_DEST')
choice(choices: ['Snapshot', 'Release'], description: 'type of release', name: 'RELEASE_TYPE')
choice(choices: ['minor', 'major', 'patch'], description: 'release version', name: 'RELEASE_VERSION')
string(defaultValue: "", description: 'Specific Commit to build', name: 'COMMIT')
string(defaultValue: "", description: 'Specific Tag to Build', name: 'TAG')
string(defaultValue: "master", description: 'Source Branch', name: 'BRANCH')
}
triggers {
pollSCM('H/5 * * * *')
}
stages {
stage('clean workspace') {
steps{
cleanWs()
}
}
stage('checkout') {
steps {
script {
buildSource = "refs/heads/${BRANCH}"
if ("${TAG}" != "") {
buildSource = "refs/tags/${TAG}"
}
else if ("${COMMIT}" != "") {
buildSource = "${COMMIT}"
}
}
checkout ([
$class: 'GitSCM',
branches: [[name: buildSource]],
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: [
[
$class: 'WipeWorkspace'
],
[
$class: 'LocalBranch',
localBranch: "**"
]
],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs
])
}
}
stage('build') {
steps {
script {
versionChange = ""
if("${params.RELEASE_TYPE}" == "Release") {
versionChange = "${params.RELEASE_VERSION}"
}
}
sh """
echo "${versionChange}" > versionType.txt
echo "${params.BUILD_DEST}" > destination.txt
cat versionType.txt
cat destination.txt
docker stop nwisweb_data_connector_docker || true && docker rm nwisweb_data_connector_docker || true
docker build . --tag="nwisweb_tableau_dockerinstance"
docker run --name nwisweb_data_connector_docker nwisweb_tableau_dockerinstance
pathtemplate=":usr/local/bin/nwisweb-tableau-data-connector/dist"
dockerinstanceid=\$( docker ps -aqf "name=nwisweb_data_connector_docker" )
docker cp "\${dockerinstanceid}\${pathtemplate}" $WORKSPACE
docker cp "\${dockerinstanceid}:usr/local/bin/nwisweb-tableau-data-connector/package.json" $WORKSPACE
docker cp "\${dockerinstanceid}:usr/local/bin/nwisweb-tableau-data-connector/code.json" $WORKSPACE
docker cp "\${dockerinstanceid}:usr/local/bin/nwisweb-tableau-data-connector/currVerNum.txt" $WORKSPACE
docker rm "\${dockerinstanceid}"
"""
withCredentials([usernamePassword(credentialsId: "NWISWEB-TABLEAU-READ-WRITE-TOKEN", usernameVariable: "GIT_USERNAME", passwordVariable: "GIT_PASSWORD")]) {
script {
if("${params.RELEASE_TYPE}" == "Release") {
sh """
/usr/bin/git config credential.helper '/bin/echo -e "username=${GIT_USERNAME}\npassword=${GIT_PASSWORD}" | tee /dev/null'
export GIT_USERNAME
export GIT_PASSWORD
echo Tagging build as `cat currVerNum.txt`
echo Incrementing version number to `cat newVerNum.txt`
git tag v`cat currVerNum.txt`
git push origin --tag
git add package.json code.json
git commit -m "automatic version number increment"
git pull origin ${params.BRANCH}
git push -u origin HEAD:${params.BRANCH}
"""
}
}
}
}
}
stage('send to S3') {
steps {
script {
if("${params.BUILD_DEST}" == "Beta") {
targetDomain = "s3://nwisweb-tableau-wdc-beta-website"
}
else if("${params.BUILD_DEST}" == "Production") {
targetDomain = "s3://nwisweb-tableau-wdc-prod-website"
}
else if("${params.BUILD_DEST}" == "QA") {
targetDomain = "s3://nwisweb-tableau-wdc-qa-website"
}
else if("${params.BUILD_DEST}" == "Test") {
targetDomain = "s3://nwisweb-tableau-wdc-test-website"
}
}
sh """
aws s3 rm "${targetDomain}" --recursive
aws s3 cp $WORKSPACE/dist "${targetDomain}"/tableau-connector --recursive
"""
}
}
}
}