Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
EOLE
Zéphir
Services
Server Manager
Commits
685b9f64
Commit
685b9f64
authored
Mar 19, 2019
by
Matthieu Lamalle
Browse files
Merge branch 'feature/image-versioning' into 'develop'
Docker images versioning in Jenkins pipeline See merge request
!9
parents
00976788
21530b66
Pipeline
#320
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Jenkinsfile
View file @
685b9f64
pipeline
{
// Import de la librairie Zéphir
// Voir le projet https://gitlab.mim.ovh/EOLE/Zephir/jenkins
@Library
(
'zephir'
)
_
agent
{
dockerfile
{
filename
'Dockerfile'
dir
'ci'
args
'--privileged -v /var/run/docker.sock:/var/run/docker.sock'
}
}
triggers
{
gitlab
(
triggerOnPush:
true
,
triggerOnMergeRequest:
true
,
branchFilterType:
'All'
,
cancelPendingBuildsOnUpdate:
false
)
}
options
{
gitLabConnection
(
'Gitlab MIM'
)
gitlabBuilds
(
builds:
[])
}
parameters
{
string
(
defaultValue:
"develop"
,
description:
'Branche "staging"'
,
name:
'stagingBranch'
)
string
(
defaultValue:
"master"
,
description:
'Branche "stable"'
,
name:
'stableBranch'
)
}
environment
{
IMAGE_NAME
=
"zephir-server-manager"
IMAGE_COMMIT_TAG
=
env
.
GIT_COMMIT
.
substring
(
0
,
8
)
}
stages
{
stage
(
'Build image'
)
{
steps
{
gitlabStage
(
STAGE_NAME
)
{
withDockerHubCredentials
{
sh
"""
# Construction de l'image
docker build -t '${DOCKER_USERNAME}/${IMAGE_NAME}' .
# Ajout du tag de commit
docker tag '${DOCKER_USERNAME}/${IMAGE_NAME}:latest' '${DOCKER_USERNAME}/${IMAGE_NAME}:${IMAGE_COMMIT_TAG}'
"""
}
}
}
}
stage
(
'Publish staging image'
)
{
when
{
branch
params
.
stagingBranch
}
steps
{
gitlabStage
(
STAGE_NAME
)
{
addTagAndPublishDockerImage
(
env
.
IMAGE_COMMIT_TAG
,
"staging-latest"
)
}
}
}
stage
(
'Publish stable image'
)
{
when
{
branch
params
.
stableBranch
}
steps
{
gitlabStage
(
STAGE_NAME
)
{
addTagAndPublishDockerImage
(
env
.
IMAGE_COMMIT_TAG
,
"stable-latest"
)
}
}
}
}
}
def
gitlabStage
(
String
stageName
,
Closure
fn
)
{
gitlabBuilds
(
builds:
[
stageName
])
{
gitlabCommitStatus
(
stageName
)
{
fn
()
}
}
}
def
withDockerHubCredentials
(
Closure
fn
)
{
withCredentials
([
usernamePassword
(
credentialsId:
'dockerhub'
,
usernameVariable:
'DOCKER_USERNAME'
,
passwordVariable:
'DOCKER_PASSWORD'
)]
){
fn
()
}
}
def
addTagAndPublishDockerImage
(
String
originalTag
,
String
newTag
)
{
withDockerHubCredentials
{
sh
"""
# Ajout du nouveau tag
docker tag '${DOCKER_USERNAME}/${IMAGE_NAME}:${originalTag}' '${DOCKER_USERNAME}/${IMAGE_NAME}:${newTag}'
# Publication de l'image sur le DockerHub
echo "${DOCKER_PASSWORD}" | docker login --username '${DOCKER_USERNAME}' --password-stdin
docker push '${DOCKER_USERNAME}/${IMAGE_NAME}:${newTag}'
docker push '${DOCKER_USERNAME}/${IMAGE_NAME}:${originalTag}'
docker logout
"""
}
}
\ No newline at end of file
// Exécution du pipeline de construction des images
serviceImagePipeline
(
"zephir-server-manager"
)
\ No newline at end of file
ci/Dockerfile
View file @
685b9f64
FROM
docker:stable
RUN
apk add
--no-cache
git
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment