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
3c28da67
Commit
3c28da67
authored
Aug 20, 2018
by
bruckwubete
Browse files
Options
Downloads
Patches
Plain Diff
Squashed to 1
parent
0d252add
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
+60
-0
60 additions, 0 deletions
Jenkinsfile
with
60 additions
and
0 deletions
Jenkinsfile
0 → 100644
+
60
−
0
View file @
3c28da67
def
project
=
'ci-cd-for-bn'
def
appName
=
'greenlight'
def
greenlightVersion
=
'v2'
def
label
=
"jenkins-execution-worker-${UUID.randomUUID().toString()}"
if
(
env
.
TAG_NAME
&&
env
.
TAG_NAME
.
contains
(
"release"
))
{
kubeCloud
=
"production"
kubecSecretsId
=
'gl-launcher-prod-secrets'
}
else
{
kubeCloud
=
"staging"
kubecSecretsId
=
'gl-launcher-staging-secrets'
}
podTemplate
(
label:
label
,
cloud:
"${kubeCloud}"
,
containers:
[
containerTemplate
(
name:
'gcloud'
,
image:
"gcr.io/ci-cd-for-bn/gcloud-docker"
,
command:
'cat'
,
ttyEnabled:
true
),
containerTemplate
(
name:
'kubectl'
,
image:
'gcr.io/cloud-builders/kubectl'
,
command:
'cat'
,
ttyEnabled:
true
)
],
volumes:
[
hostPathVolume
(
mountPath:
'/usr/bin/docker'
,
hostPath:
'/usr/bin/docker'
),
hostPathVolume
(
mountPath:
'/var/run/docker.sock'
,
hostPath:
'/var/run/docker.sock'
)
]){
node
(
label
)
{
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
imageTag
=
"gcr.io/${project}/${appName}:${gitBranch}.${env.BUILD_NUMBER}.${gitCommit}"
stage
(
'Build and Publish'
)
{
container
(
'gcloud'
)
{
withCredentials
([
file
(
credentialsId:
'cloud-datastore-user-account-creds'
,
variable:
'FILE'
)])
{
sh
"gcloud auth activate-service-account --key-file=$FILE"
if
(
kubeCloud
==
"staging"
)
{
sh
"gcloud docker -- build -t ${imageTag} . && gcloud docker -- push ${imageTag}"
}
else
{
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
"docker login -u $DOCKER_USER -p $DOCKER_PASSWORD"
sh
"docker push '$DOCKER_USER/${appName}:${greenlightVersion}' && docker push '$DOCKER_USER/${appName}:${gitTag}'"
}
}
}
}
}
stage
(
'Deploy'
)
{
container
(
'kubectl'
)
{
withCredentials
([
file
(
credentialsId:
kubecSecretsId
,
variable:
'FILE'
)])
{
sh
'''
kubectl get pods && kubectl apply -f $FILE
'''
}
sh
"kubectl set image deployments/gl-deployment gl=${imageTag}"
}
}
}
}
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