Verified Commit 8a345357 authored by Lukas Wiest's avatar Lukas Wiest 🚂
Browse files

refactor(ci): redo pipeline

reworked pipeline to suit all branches

This pulls, builds and publishes now for every branch on the repo
Tag used is the branch name

if the commit the pipeline runs matches the format [0-9]+.[0-9]+.[0-9]+
the release stage is run additionally, which pushs the built image
additionally with the tags 'latest' and the tag.

On Jenkins the old Pipeline configurations are disabled and replaced by
a multibranch pipeline configuration
parent b1f233c6
def version = ""
pipeline {
environment {
registry = "hftstuttgart/modocot-backend"
registryCredential = 'Dockerhub'
dockerImage = ''
}
agent any
tools {
jdk 'Java11'
maven 'Maven_Home'
}
stages {
stage('Checkout') {
stage('prepare') {
steps {
echo 'Checkout Repository..'
git branch: 'master',
url: 'https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/MoDoCoT-Backend.git'
checkout ([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
userRemoteConfigs: scm.userRemoteConfigs
])
script {
version = sh(script: 'git describe --tags --always', returnStdout: true).trim()
echo sh(script: 'env|sort', returnStdout: true)
}
}
}
stage('Build') {
stage('compile') {
steps {
echo 'Maven Build..'
sh 'mvn clean package -DskipTests=false'
sh 'mvn clean package'
}
}
stage('Docker Build..') {
steps{
stage('build Docker image') {
steps {
script {
dockerImage = docker.build registry + ":latest"
dockerImage = docker.build registry
}
}
}
stage('Push to Dockerhub..') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
stage('push development image') {
steps {
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push("${env.GIT_BRANCH}")
}
}
}
}
stage('ShellScript') {
stage('release') {
when {
expression { version ==~ /[0-9]+.[0-9]+.[0-9]+/ }
}
steps {
echo 'Exectue Shellscript..'
sh 'chmod 744 restart_modocot_backend.sh && ./restart_modocot_backend.sh'
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push("latest")
dockerImage.push("${version}")
}
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment