forked from relaypro-open/dog_agent_ex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
180 lines (154 loc) · 8.17 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env groovy
pipeline {
agent none
environment {
tag = VersionNumber(versionNumberString: '${BUILD_TIMESTAMP}');
// job environment variables
BUILD_ENV = "${build_stream}"
// this is a result of a backwards-incompatible change from JENKINS-24380
BUILD_ID = "${VersionNumber(projectStartDate: '1970-01-01', versionNumberString: '${BUILD_DATE_FORMATTED, \"yyyy-MM-dd_H-m-s\"}')}"
}
parameters {
booleanParam(name: 'deploy',
defaultValue: false,
description: 'Whether or not to deploy this new build to the environment selected below.')
string(name: 'branch',
defaultValue: 'main',
description: 'The source branch to compile.')
choice(name: 'env',
choices: ['mob_qa','mob_pro','beta_qa','stage.qa','api.qa','api.pro'],
description: 'If deploying, which ansible environment to deploy to. Determines deployment target')
choice(name: 'dog_env',
choices: ['qa','pro'],
description: 'If deploying, which dog environment to deploy to. Determines which dog_trainer this build will connect to')
string(name: 'target',
defaultValue: '',
description: 'The target host/group.')
string(name: 'flags',
defaultValue: '--tags upgrade',
description: 'ansible flags')
choice(name: 'erlang_version',
choices: ['24.3.4.2'],
description: 'The erlang_version dog_agent_ex will be built with')
}
stages {
stage('Matrix Build') {
matrix {
agent {
docker {
image "${DOCKER_IMAGE}"
args '--user="root"'
}
}
axes {
axis {
name 'DOCKER_IMAGE'
values 'relaypro/elixir-14-4-erlang-24-focal:master-latest', 'relaypro/elixir-14-4-erlang-24-xenial:master-latest'
}
}
stages {
stage ('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'admin', url: 'https://github.com/relaypro-open/dog_agent_ex.git']]])
}
}
stage('Build') {
steps{
sh """#!/bin/bash -x
echo "PWD: ${PWD}"
cd $WORKSPACE
rm -rf _build
# elixir expects utf8.
export ELIXIR_VERSION="v1.14.4"
export LANG=C.UTF-8
set -xe \
&& ELIXIR_DOWNLOAD_URL="https://github.com/elixir-lang/elixir/archive/\${ELIXIR_VERSION}.tar.gz" \
&& ELIXIR_DOWNLOAD_SHA256="07d66cf147acadc21bd1679f486efd6f8d64a73856ecc83c71b5e903081b45d2" \
&& curl -fSL -o elixir-src.tar.gz \$ELIXIR_DOWNLOAD_URL \
&& echo "\$ELIXIR_DOWNLOAD_SHA256 elixir-src.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/local/src/elixir \
&& tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
&& rm elixir-src.tar.gz \
&& cd /usr/local/src/elixir \
&& make install clean \
&& find /usr/local/src/elixir/ -type f -not -regex "/usr/local/src/elixir/lib/*/lib.*" -exec rm -rf {} + \
&& find /usr/local/src/elixir/ -type d -depth -empty -delete
echo "PWD: ${PWD}"
cd $WORKSPACE
echo "env: \$env"
echo "dog_env: \$dog_env"
if [[ \$env == *qa ]]; then
build_env="qa"
elif [[ \$env == *pro ]]; then
build_env="pro"
elif [[ \$env == *dev ]]; then
build_env="dev"
fi
if [[ \$DOCKER_IMAGE == 'relaypro/elixir-14-4-erlang-24-xenial:master-latest' ]]; then
build_suffix='ubuntu'
elif [[ \$DOCKER_IMAGE == 'relaypro/elixir-14-4-erlang-24-focal:master-latest' ]]; then
build_suffix='ubuntu-20-04'
fi
#ls /opt/kerl/lib
#. /opt/kerl/lib/\$erla//ng_version/activate
which erl
echo "build_env: \$build_env"
apt-get update && apt-get install -y libcap-dev locales iptables ipset lsb-release jq curl make
mix local.hex --force && mix local.rebar --force
mkdir /etc/dog_ex
echo "PWD: ${PWD}"
cp config/runtime.${dog_env}.exs config/runtime.exs
mix deps.get \
&& mix deps.clean --all --build \
&& mix compile \
&& MIX_ENV=${dog_env} mix release
find .
mv -f _build/qa/dog-0.1.0.tar.gz \$dog_env-\$BUILD_ID.\$build_suffix.tar.gz
chown -R jenkins:jenkins $WORKSPACE
"""
}
post {
success {
archiveArtifacts allowEmptyArchive: false, artifacts: '*.tar.gz', caseSensitive: true, defaultExcludes: true, fingerprint: false
}
}
}
stage('Upload artifact to S3') {
steps {
withAWS(credentials: 'aws-iam-user/product-jenkins-artifact-uploads') {
s3Upload bucket:'product-builds', path: 'dog_ex/', includePathPattern: '*.tar.gz'
}
}
}
stage('Deploy') {
when {
expression { params.deploy == true }
}
steps {
build job: '/playbyplay/pbp-common-deploy', parameters: [
string(name: 'deployEnv', value: "${params.env}"),
string(name: 'app', value: 'dog'),
string(name: 'target', value: "${params.hosts}"),
string(name: 'ansibleFlags', value: '')
]
}
}
}
}
}
}
post {
changed {
emailext(
to: '[email protected]',
body: '${DEFAULT_CONTENT}',
mimeType: 'text/html',
subject: '${DEFAULT_SUBJECT}',
replyTo: '$DEFAULT_REPLYTO'
)
}
cleanup{
deleteDir()
}
}
}