Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Greenlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arbeitsgruppe Hardwarenahe IT-Systeme
Greenlight
Commits
e4779487
Commit
e4779487
authored
Aug 24, 2018
by
Bruck Wubete
Committed by
Jesus Federico
Aug 24, 2018
Browse files
Options
Downloads
Patches
Plain Diff
Update Jenkins File with github webhooks and slack notifications (#251)
* Update Jenkinsfile
parent
f6742fd4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Jenkinsfile
+59
-38
59 additions, 38 deletions
Jenkinsfile
with
59 additions
and
38 deletions
Jenkinsfile
+
59
−
38
View file @
e4779487
...
...
@@ -2,13 +2,25 @@ def project = 'ci-cd-for-bn'
def
appName
=
'greenlight'
def
greenlightVersion
=
'v2'
def
label
=
"jenkins-execution-worker-${UUID.randomUUID().toString()}"
def
releaseBuild
=
env
.
TAG_NAME
&&
env
.
TAG_NAME
.
contains
(
"release"
)
if
(
env
.
TAG_NAME
&&
env
.
TAG_NAME
.
contains
(
"release"
))
{
String
convert
(
long
millsToConvert
){
long
seconds
,
minutes
,
hours
;
seconds
=
millsToConvert
/
1000
;
minutes
=
seconds
/
60
;
seconds
=
seconds
%
60
;
hours
=
minutes
/
60
;
minutes
=
minutes
%
60
;
return
String
.
format
(
"%02d:%02d:%02d"
,
hours
,
minutes
,
seconds
);
}
if
(
releaseBuild
)
{
kubeCloud
=
"production"
kubecSecretsId
=
'g
l-launcher
-prod-secrets'
kubecSecretsId
=
'g
reenlight
-prod-secrets'
}
else
{
kubeCloud
=
"staging"
kubecSecretsId
=
'g
l-launcher
-staging-secrets'
kubecSecretsId
=
'g
reenlight
-staging-secrets'
}
properties
([
...
...
@@ -27,33 +39,36 @@ volumes: [
hostPathVolume
(
mountPath:
'/var/run/docker.sock'
,
hostPath:
'/var/run/docker.sock'
)
]){
node
(
label
)
{
try
{
slackSend
(
color:
'#FFFF00'
,
message:
"STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
)
def
myRepo
=
checkout
scm
def
gitCommit
=
myRepo
.
GIT_COMMIT
def
gitBranch
=
myRepo
.
GIT_BRANCH
def
gitTag
=
env
.
TAG_NAME
def
shortGitCommit
=
"${gitCommit[0..10]}"
def
previousGitCommit
=
sh
(
script:
"git rev-parse ${gitCommit}~"
,
returnStdout:
true
)
def
previousGitCommit
=
myRepo
.
GIT_PREVIOUS_COMMIT
def
imageTag
=
"gcr.io/${project}/${appName}:${gitBranch}.${env.BUILD_NUMBER}.${gitCommit}"
def
stageBuild
=
(
kubeCloud
==
"staging"
&&
gitBranch
==
"master"
)
stage
(
'Test'
)
{
container
(
'ruby'
)
{
sh
"bundle install
--without development production
&& bundle exec rubocop && bundle exec rspec"
sh
"bundle install && bundle exec rubocop && bundle exec rspec
"
}
}
stage
(
'Build and Publish'
)
{
container
(
'gcloud'
)
{
withCredentials
([
file
(
credentialsId:
'cloud-datastore-user-account-creds'
,
variable:
'FILE'
)])
{
withCredentials
([
file
(
credentialsId:
'cloud-datastore-user-account-creds'
,
variable:
'FILE'
)
,
string
(
credentialsId:
'DOCKER_USER'
,
variable:
'DOCKER_USER'
),
string
(
credentialsId:
'DOCKER_PASSWORD'
,
variable:
'DOCKER_PASSWORD'
)
])
{
sh
"gcloud auth activate-service-account --key-file=$FILE"
if
(
kubeCloud
==
"staging"
)
{
sh
"gcloud docker -- build -t ${imageTag} . && gcloud docker -- push ${imageTag}"
}
else
{
if
(
stageBuild
)
{
sh
"gcloud docker -- build -t ${imageTag} -t 'bigbluebutton/${appName}:master' . && gcloud docker -- push ${imageTag}"
sh
"docker login -u $DOCKER_USER -p $DOCKER_PASSWORD"
sh
"docker push 'bigbluebutton/${appName}:master'"
}
else
if
(
releaseBuild
)
{
imageTag
=
"gcr.io/${project}/${appName}:${gitTag}"
withCredentials
([
string
(
credentialsId:
'DOCKER_USER'
,
variable:
'DOCKER_USER'
),
string
(
credentialsId:
'DOCKER_PASSWORD'
,
variable:
'DOCKER_PASSWORD'
)])
{
sh
"gcloud docker -- build -t ${imageTag} -t '$DOCKER_USER/${appName}:${greenlightVersion}' -t '$DOCKER_USER/${appName}:${gitTag}' . && gcloud docker -- push ${imageTag}"
sh
"gcloud docker -- build -t ${imageTag} -t 'bigbluebutton/${appName}:${greenlightVersion}' -t 'bigbluebutton/${appName}:${gitTag}' . && gcloud docker -- push ${imageTag}"
sh
"docker login -u $DOCKER_USER -p $DOCKER_PASSWORD"
sh
"docker push '$DOCKER_USER/${appName}:${greenlightVersion}' && docker push '$DOCKER_USER/${appName}:${gitTag}'"
}
sh
"docker push 'bigbluebutton/${appName}:${greenlightVersion}' && docker push 'bigbluebutton/${appName}:${gitTag}'"
}
}
}
...
...
@@ -61,13 +76,19 @@ volumes: [
stage
(
'Deploy'
)
{
container
(
'kubectl'
)
{
if
(
stageBuild
||
releaseBuild
)
{
withCredentials
([
file
(
credentialsId:
kubecSecretsId
,
variable:
'FILE'
)])
{
sh
'''
kubectl apply -f $FILE
'''
}
}
sh
"kubectl set image deployments/gl-deployment gl=${imageTag}"
}
}
slackSend
(
color:
'#00FF00'
,
message:
"SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' in ${convert(currentBuild.duration)} (${env.BUILD_URL})"
)
}
catch
(
e
)
{
slackSend
(
color:
'#FF0000'
,
message:
"FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' message: ${e} (${env.BUILD_URL})"
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment