Skip to content

Commit d13c7ad

Browse files
committed
feat: jenkins env vars + bug
1 parent 1e0a14d commit d13c7ad

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

deploy/Jenkinsfile

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
podTemplate(label: 'build-pod-sourcerer-app',
1+
// Copyright 2017 Sourcerer, Inc. All Rights Reserved.
2+
// Author: Maxim Rusak ([email protected])
3+
4+
def label = "sourcerer-app-${UUID.randomUUID().toString()}"
5+
6+
def namespace = 'sandbox'
7+
if (env.BRANCH_NAME == 'master') {
8+
namespace = 'production'
9+
} else if (env.BRANCH_NAME == 'develop') {
10+
namespace = 'staging'
11+
}
12+
13+
podTemplate(label: label,
214
containers: [
315
containerTemplate(name: 'jnlp', image: 'gcr.io/sourcerer-1377/jenkins-slave:v4', args: '${computer.jnlpmac} ${computer.name}'),
416
containerTemplate(name: 'gradle', image: 'gcr.io/sourcerer-1377/gradle:4.2.0', ttyEnabled: true, command: 'tail -f /dev/null')
517
],
618
envVars: [
7-
envVar(key: 'CONTAINER_TAG', value: "${env.BRANCH_NAME}.${env.BUILD_NUMBER}")
19+
envVar(key: 'NAMESPACE', value: namespace),
20+
envVar(key: 'CONTAINER_TAG', value: "${namespace}.${env.BUILD_NUMBER}.${System.currentTimeMillis()}")
821
],
922
volumes: [
1023
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
1124
hostPathVolume(hostPath: '/usr/bin/docker', mountPath: '/usr/bin/docker')
1225
]
1326
) {
14-
node('build-pod-sourcerer-app') {
15-
def namespace = 'sandbox'
16-
def plog = 'debug'
17-
18-
if (env.BRANCH_NAME == 'master') {
19-
namespace = 'production'
20-
plog = 'info'
21-
} else if (env.BRANCH_NAME == 'develop') {
22-
namespace = 'staging'
23-
plog = 'info'
24-
}
25-
27+
node(label) {
2628
stage('checkout') {
2729
checkout scm
2830
}
2931

3032
stage('build jar and test') {
3133
container('gradle') {
32-
sh("LOG=${plog} NAMESPACE=${namespace} ./do.sh build_jar_inside")
34+
sh("./do.sh build_jar_inside")
3335
}
3436
}
3537

@@ -45,7 +47,7 @@ podTemplate(label: 'build-pod-sourcerer-app',
4547

4648
stage('deploy') {
4749
println "Deploying to ${namespace} kubernetes namespace"
48-
sh("NAMESPACE=${namespace} ./do.sh deploy")
50+
sh("./do.sh deploy")
4951
}
5052
}
5153
}

do.sh

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
#!/bin/bash
22

3-
#-------------------#
4-
#----- Helpers -----#
5-
#-------------------#
3+
# Copyright 2017 Sourcerer, Inc. All Rights Reserved.
4+
# Author: Maxim Rusak ([email protected])
65

76
set -x
87

9-
usage() {
10-
echo "$0 [COMMAND] [ARGUMENTS]"
11-
echo " Commands:"
12-
echo " - build_jar: build jar"
13-
echo " - build_prod_inside: build nginx container"
14-
echo " - run_jar: run jar"
15-
echo " - run_prod: start nginx container"
16-
}
17-
188
fn_exists() {
19-
type $1 2>/dev/null | grep -q 'is a function'
9+
type $1 2>/dev/null | grep -q 'is a function'
2010
}
2111

2212
COMMAND=$1
2313
shift
2414
ARGUMENTS=${@}
2515

26-
TAG="${CONTAINER_TAG:-latest}"
16+
CONTAINER_TAG="${CONTAINER_TAG:-latest}"
2717
NAMESPACE="${NAMESPACE:-sandbox}"
2818
LOG="${LOG:-debug}"
2919
VOLUME="${BUILD_VOLUME:-$PWD}"
3020
PROJECT=sourcerer-app
3121
PORT=3182
32-
REPO_NAME=gcr.io/sourcerer-1377/$PROJECT:$TAG
22+
REPO_NAME=gcr.io/sourcerer-1377/$PROJECT:$CONTAINER_TAG
3323
GRADLE_VERSION=4.2.0
3424

3525
#--------------------#
@@ -40,12 +30,16 @@ GRADLE_VERSION=4.2.0
4030
build_jar_inside() {
4131
if [ "$NAMESPACE" == "sandbox" ]; then
4232
API="https://sandbox.sourcerer/api/commit"
33+
LOG="debug"
4334
elif [ "$NAMESPACE" == "staging" ]; then
4435
API="https://staging.sourcerer/api/commit"
36+
LOG="info"
4537
elif [ "$NAMESPACE" == "local" ]; then
4638
API="http://localhost:3181"
39+
LOG="debug"
4740
else
4841
API="https://sourcerer.io/api/commit"
42+
LOG="info"
4943
fi
5044
gradle -Penv=$NAMESPACE -Plog=$LOG -Papi=$API build
5145
}
@@ -88,7 +82,7 @@ push() {
8882

8983
fn_exists $COMMAND
9084
if [ $? -eq 0 ]; then
91-
$COMMAND $ARGUMENTS
85+
$COMMAND $ARGUMENTS
9286
else
93-
usage
87+
echo "Command not found"
9488
fi

0 commit comments

Comments
 (0)