Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
common-lib
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
OZG-Cloud
lib
common-lib
Commits
f10b30a8
Commit
f10b30a8
authored
3 years ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-1518 OZG-1741 add Jenkinsfile
parent
6df88223
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
+155
-0
155 additions, 0 deletions
Jenkinsfile
with
155 additions
and
0 deletions
Jenkinsfile
0 → 100644
+
155
−
0
View file @
f10b30a8
def
FAILED_STAGE
pipeline
{
agent
{
node
{
label
'jenkins-worker'
}
}
environment
{
BLUE_OCEAN_URL
=
"https://jenkins.ozg-sh.de/blue/organizations/jenkins/kop-common/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline"
RELEASE_REGEX
=
/\d+.\d+.\d+/
SNAPSHOT_REGEX
=
/\d+.\d+.\d+-SNAPSHOT/
}
options
{
timeout
(
time:
1
,
unit:
'HOURS'
)
disableConcurrentBuilds
()
buildDiscarder
(
logRotator
(
numToKeepStr:
'5'
))
}
stages
{
stage
(
'Check Version'
)
{
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
def
rootPom
=
readMavenPom
file:
'pom.xml'
def
rootVersion
=
rootPom
.
version
def
dependenciesPom
=
readMavenPom
file:
'kop-common-dependencies/pom.xml'
def
dependenciesVersion
=
dependenciesPom
.
parent
.
version
def
parentPom
=
readMavenPom
file:
'kop-common-parent/pom.xml'
def
parentVersion
=
parentPom
.
parent
.
version
if
(
env
.
BRANCH_NAME
==
'release'
){
if
(
!(
rootVersion
==~
RELEASE_REGEX
)
||
!(
dependenciesVersion
==~
RELEASE_REGEX
)
||
!(
parentVersion
==~
RELEASE_REGEX
))
{
error
(
"Keine Release Version für Branch ${env.BRANCH_NAME}."
)
}
}
else
{
if
(
!(
rootVersion
==~
SNAPSHOT_REGEX
)
||
!(
dependenciesVersion
==~
SNAPSHOT_REGEX
)
||
!(
parentVersion
==~
SNAPSHOT_REGEX
))
{
error
(
"Keine Snapshot Version für Branch ${env.BRANCH_NAME}."
)
}
}
if
(
!(
rootVersion
==
dependenciesVersion
&&
rootVersion
==
parentVersion
)){
error
(
"Versionen sind nicht identisch"
)
}
}
}
}
stage
(
'Build Kop-Common'
)
{
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
}
container
(
"maven-17"
){
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
sh
'mvn --version'
sh
'mvn -s $MAVEN_SETTINGS clean install spring-boot:build-image -Dmaven.wagon.http.retryHandler.count=3'
}
script
{
try
{
if
(
env
.
BRANCH_NAME
==
'master'
)
{
withSonarQubeEnv
(
'sonarqube-ozg-sh'
){
sh
'mvn sonar:sonar'
}
}
}
catch
(
Exception
e
)
{
unstable
(
"SonarQube failed"
)
}
}
}
}
post
{
always
{
junit
testResults:
'**/target/surefire-reports/*.xml'
,
skipPublishingChecks:
true
}
}
}
stage
(
'Deploy Kop-Common to Nexus'
){
when
{
anyOf
{
branch
'master'
branch
'release'
}
}
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
}
container
(
'maven-17'
)
{
configFileProvider
([
configFile
(
fileId:
'maven-settings'
,
variable:
'MAVEN_SETTINGS'
)])
{
sh
'mvn -s $MAVEN_SETTINGS -DskipTests deploy'
}
}
}
}
stage
(
'Push Docker image'
)
{
steps
{
script
{
FAILED_STAGE
=
env
.
STAGE_NAME
def
pom
=
readMavenPom
file:
'pom.xml'
def
version
=
pom
.
version
container
(
"docker"
)
{
withCredentials
([
usernamePassword
(
credentialsId:
'jenkins-docker-login'
,
usernameVariable:
'USER'
,
passwordVariable:
'PASSWORD'
)])
{
sh
'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}'
//kop-common-dependencies
sh
"docker tag docker.ozg-sh.de/kop-common-dependencies:build-latest docker.ozg-sh.de/kop-common-dependencies:${env.BRANCH_NAME}-${version}"
sh
"docker push docker.ozg-sh.de/kop-common-dependencies:${env.BRANCH_NAME}-${version}"
if
(
env
.
BRANCH_NAME
==
'master'
)
{
sh
'docker tag docker.ozg-sh.de/kop-common-dependencies:build-latest docker.ozg-sh.de/kop-common-dependencies:snapshot-latest'
sh
'docker push docker.ozg-sh.de/kop-common-dependencies:snapshot-latest'
}
if
(
env
.
BRANCH_NAME
==
'release'
)
{
sh
'docker tag docker.ozg-sh.de/kop-common-dependencies:build-latest docker.ozg-sh.de/kop-common-dependencies:latest'
sh
'docker push docker.ozg-sh.de/kop-common-dependencies:latest'
}
//kop-common-parent
sh
"docker tag docker.ozg-sh.de/kop-common-parent:build-latest docker.ozg-sh.de/kop-common-parent:${env.BRANCH_NAME}-${version}"
sh
"docker push docker.ozg-sh.de/kop-common-parent:${env.BRANCH_NAME}-${version}"
if
(
env
.
BRANCH_NAME
==
'master'
)
{
sh
'docker tag docker.ozg-sh.de/kop-common-parent:build-latest docker.ozg-sh.de/kop-common-parent:snapshot-latest'
sh
'docker push docker.ozg-sh.de/kop-common-parent:snapshot-latest'
}
if
(
env
.
BRANCH_NAME
==
'release'
)
{
sh
'docker tag docker.ozg-sh.de/kop-common-parent:build-latest docker.ozg-sh.de/kop-common-parent:latest'
sh
'docker push docker.ozg-sh.de/kop-common-parent:latest'
}
}
}
}
}
}
}
post
{
failure
{
script
{
if
(
env
.
BRANCH_NAME
==
'master'
)
{
slackSend
(
color:
"danger"
,
message:
"Kop-Common: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>"
)
}
}
}
}
}
\ No newline at end of file
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